Tests coverage increasing for iovisor.endpoint 61/39161/1
authorKonstantin Blagov <kblagov@cisco.com>
Thu, 19 May 2016 11:35:27 +0000 (13:35 +0200)
committerKonstantin Blagov <kblagov@cisco.com>
Fri, 20 May 2016 07:40:14 +0000 (07:40 +0000)
Change-Id: Ibf87f90000a5e26f2ae5dbe61634b6c0cfac9c0a
Signed-off-by: Konstantin Blagov <kblagov@cisco.com>
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/EndpointListenerCovrgTest.java [new file with mode: 0755]
renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/IovisorEndpointAugCovrgTest.java [new file with mode: 0755]

diff --git a/renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/EndpointListenerCovrgTest.java b/renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/EndpointListenerCovrgTest.java
new file mode 100755 (executable)
index 0000000..5438de1
--- /dev/null
@@ -0,0 +1,76 @@
+package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.spy;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.util.Set;\r
+\r
+import com.google.common.collect.ImmutableSet;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;\r
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;\r
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.groupbasedpolicy.util.IidFactory;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
+\r
+public class EndpointListenerCovrgTest {\r
+\r
+    private EndpointListener listener;\r
+    private DataObjectModification<EndpointL3> rootNode;\r
+    private Set<DataTreeModification<EndpointL3>> changes;\r
+\r
+    private InstanceIdentifier<EndpointL3> rootIdentifier;\r
+\r
+    @SuppressWarnings("unchecked")\r
+    @Before\r
+    public void init() {\r
+        DataBroker dataProvider = mock(DataBroker.class);\r
+\r
+        EndpointManager endpointManager = mock(EndpointManager.class);\r
+        listener = spy(new EndpointListener(dataProvider, endpointManager));\r
+\r
+        EndpointL3 endpointL3 = mock(EndpointL3.class);\r
+\r
+        rootNode = mock(DataObjectModification.class);\r
+        rootIdentifier = IidFactory.l3EndpointsIidWildcard();\r
+        DataTreeIdentifier<EndpointL3> rootPath =\r
+                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, rootIdentifier);\r
+\r
+        DataTreeModification<EndpointL3> change = mock(DataTreeModification.class);\r
+\r
+        when(change.getRootNode()).thenReturn(rootNode);\r
+        when(change.getRootPath()).thenReturn(rootPath);\r
+\r
+        changes = ImmutableSet.of(change);\r
+\r
+        when(rootNode.getDataBefore()).thenReturn(endpointL3);\r
+        when(rootNode.getDataAfter()).thenReturn(endpointL3);\r
+    }\r
+\r
+    @Test\r
+    public void testOnWrite() {\r
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);\r
+\r
+        listener.onDataTreeChanged(changes);\r
+    }\r
+\r
+    @Test(expected = UnsupportedOperationException.class)\r
+    public void testOnDelete() {\r
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);\r
+\r
+        listener.onDataTreeChanged(changes);\r
+    }\r
+\r
+    @Test\r
+    public void testOnSubtreeModified() {\r
+        when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);\r
+\r
+        listener.onDataTreeChanged(changes);\r
+    }\r
+\r
+}\r
diff --git a/renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/IovisorEndpointAugCovrgTest.java b/renderers/iovisor/src/test/java/org/opendaylight/groupbasedpolicy/renderer/iovisor/endpoint/IovisorEndpointAugCovrgTest.java
new file mode 100755 (executable)
index 0000000..7cc7169
--- /dev/null
@@ -0,0 +1,62 @@
+package org.opendaylight.groupbasedpolicy.renderer.iovisor.endpoint;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.groupbasedpolicy.api.EpRendererAugmentationRegistry;\r
+import org.opendaylight.groupbasedpolicy.renderer.iovisor.test.GbpIovisorDataBrokerTest;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.RegisterEndpointInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.iovisor.rev151030.IovisorModuleAugmentationInput;\r
+\r
+public class IovisorEndpointAugCovrgTest extends GbpIovisorDataBrokerTest {\r
+\r
+    private EpRendererAugmentationRegistry epRAR;\r
+    private IovisorEndpointAug aug;\r
+\r
+    @Before\r
+    public void init() {\r
+        epRAR = mock(EpRendererAugmentationRegistry.class);\r
+\r
+        aug = new IovisorEndpointAug(epRAR);\r
+    }\r
+\r
+    @Test\r
+    public void testClose() throws Exception {\r
+        IovisorEndpointAug other = new IovisorEndpointAug(epRAR);\r
+        other.close();\r
+\r
+        verify(epRAR).unregister(any(IovisorEndpointAug.class));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointAugmentation() {\r
+        assertNull(aug.buildEndpointAugmentation(null));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointL3Augmentation() {\r
+        RegisterEndpointInput input = mock(RegisterEndpointInput.class);\r
+        IovisorModuleAugmentationInput iomAugInput = mock(IovisorModuleAugmentationInput.class);\r
+        when(input.getAugmentation(IovisorModuleAugmentationInput.class)).thenReturn(iomAugInput);\r
+        assertNotNull(aug.buildEndpointL3Augmentation(input));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildEndpointL3Augmentation_Null() {\r
+        RegisterEndpointInput input = mock(RegisterEndpointInput.class);\r
+        when(input.getAugmentation(IovisorModuleAugmentationInput.class)).thenReturn(null);\r
+        assertNull(aug.buildEndpointL3Augmentation(input));\r
+    }\r
+\r
+    @Test\r
+    public void testBuildL3PrefixEndpointAugmentation() {\r
+        assertNull(aug.buildL3PrefixEndpointAugmentation(null));\r
+    }\r
+\r
+}\r