Bug 4988: OF statistics & REST client
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / endpoint / EndpointManagerTest.java
index fe232f183e2eca259c06bd16ec29615534cdc672..cc267d2c9b8959accc7583364d86a51aed0cede6 100644 (file)
@@ -31,6 +31,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -47,6 +49,7 @@ import org.opendaylight.groupbasedpolicy.dto.EpKey;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.EndpointListener;
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.node.SwitchManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
@@ -113,9 +116,11 @@ public class EndpointManagerTest {
         when(writeTransaction.submit()).thenReturn(checkedFutureWrite);
         BindingAwareBroker.RpcRegistration<EndpointService> rpcRegistration = mock(BindingAwareBroker.RpcRegistration.class);
         listenerReg = mock(ListenerRegistration.class);
-        when(
-                dataProvider.registerDataChangeListener(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
-                        any(DataChangeListener.class), any(DataChangeScope.class))).thenReturn(listenerReg);
+        when(dataProvider.registerDataChangeListener(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
+                any(DataChangeListener.class), any(DataChangeScope.class))).thenReturn(listenerReg);
+        when(dataProvider.registerDataTreeChangeListener(any(DataTreeIdentifier.class),
+                any(DataTreeChangeListener.class))).thenReturn(listenerReg);
+
         when(rpcRegistry.addRpcImplementation(any(Class.class), any(RpcService.class))).thenReturn(rpcRegistration);
 
         manager = spy(new EndpointManager(dataProvider, rpcRegistry, notificationService, executor, switchManager));
@@ -127,7 +132,7 @@ public class EndpointManagerTest {
         tenantId = mock(TenantId.class);
         endpointGroupId = mock(EndpointGroupId.class);
         l2BridgeDomainId = mock(L2BridgeDomainId.class);
-        MacAddress macAddress = mock(MacAddress.class);
+        MacAddress macAddress = new MacAddress("12:34:56:78:9a:bc");
         when(endpoint1.getTenant()).thenReturn(tenantId);
         when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId);
         when(endpoint1.getL2Context()).thenReturn(l2BridgeDomainId);
@@ -379,7 +384,7 @@ public class EndpointManagerTest {
         when(newL3Ep.getKey()).thenReturn(endpointL3Key);
         IpAddress ipAddress = mock(IpAddress.class);
         when(endpointL3Key.getIpAddress()).thenReturn(ipAddress);
-
+        when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
         verify(endpointListener,never()).endpointUpdated(any(EpKey.class));
     }
@@ -400,7 +405,7 @@ public class EndpointManagerTest {
         when(newL3Ep.getKey()).thenReturn(endpointL3Key);
         IpAddress ipAddress = mock(IpAddress.class);
         when(endpointL3Key.getIpAddress()).thenReturn(ipAddress);
-
+        when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
         verify(endpointListener,never()).endpointUpdated(any(EpKey.class));
     }
@@ -419,7 +424,7 @@ public class EndpointManagerTest {
 
         when(newL3Ep.getL2Context()).thenReturn(mock(L2BridgeDomainId.class));
         when(newL3Ep.getMacAddress()).thenReturn(mock(MacAddress.class));
-
+        when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
         verify(endpointListener).endpointUpdated(any(EpKey.class));
     }
@@ -430,13 +435,14 @@ public class EndpointManagerTest {
         when(newL3Ep.getEndpointGroup()).thenReturn(mock(EndpointGroupId.class));
         when(newL3Ep.getL3Context()).thenReturn(mock(L3ContextId.class));
         when(newL3Ep.getIpAddress()).thenReturn(null);
-
+        when(newL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(null, newL3Ep);
         verify(endpointListener,never()).endpointUpdated(any(EpKey.class));
     }
 
     @Test
     public void updateEndpointL3TestDelete() throws Exception {
+        when(oldL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
         manager.processL3Endpoint(oldL3Ep, null);
         verify(endpointListener).endpointUpdated(any(EpKey.class));
     }
@@ -587,70 +593,10 @@ public class EndpointManagerTest {
         Assert.assertFalse(collection.isEmpty());
     }
 
-    @SuppressWarnings({"unchecked"})
-    @Test
-    public void addEndpointFromL3EndpointTest() throws Exception {
-        EndpointL3 l3Ep = mock(EndpointL3.class);
-        ReadWriteTransaction rwTx = mock(ReadWriteTransaction.class);
-        OfOverlayL3Context ofL3Ctx = mock(OfOverlayL3Context.class);
-        when(l3Ep.getAugmentation(OfOverlayL3Context.class)).thenReturn(ofL3Ctx);
-
-        CheckedFuture<Optional<Tenant>, ReadFailedException> checkedFuture = mock(CheckedFuture.class);
-        when(rwTx.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
-        Optional<Tenant> optional = mock(Optional.class);
-        when(checkedFuture.checkedGet()).thenReturn(optional);
-        Tenant tenant = mock(Tenant.class);
-        ForwardingContext fwCtx = mock(ForwardingContext.class);
-        when(tenant.getForwardingContext()).thenReturn(fwCtx);
-        when(optional.isPresent()).thenReturn(true);
-        when(optional.get()).thenReturn(tenant);
-
-        L2BridgeDomain l2BridgeDomain = mock(L2BridgeDomain.class);
-        when(fwCtx.getL2BridgeDomain()).thenReturn(Collections.singletonList(l2BridgeDomain));
-        L2BridgeDomainId l2BridgeDomainId = mock(L2BridgeDomainId.class);
-        when(l2BridgeDomain.getId()).thenReturn(l2BridgeDomainId);
-        String l2bdValue = UUID.randomUUID().toString();
-        when(l2BridgeDomainId.getValue()).thenReturn(l2bdValue);
-
-        NetworkDomainId networkDomainId = mock(NetworkDomainId.class);
-        when(l3Ep.getNetworkContainment()).thenReturn(networkDomainId);
-        when(networkDomainId.getValue()).thenReturn(l2bdValue);
-
-        Method method = EndpointManager.class.getDeclaredMethod("addEndpointFromL3Endpoint", EndpointL3.class,
-                ReadWriteTransaction.class);
-        method.setAccessible(true);
-        method.invoke(manager, l3Ep, rwTx);
-        verify(rwTx).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Endpoint.class));
-    }
-
-    @SuppressWarnings({"unchecked"})
-    @Test
-    public void addEndpointFromL3EndpointTestTenantPresentFalse() throws Exception {
-        EndpointL3 l3Ep = mock(EndpointL3.class);
-        ReadWriteTransaction rwTx = mock(ReadWriteTransaction.class);
-        OfOverlayL3Context ofL3Ctx = mock(OfOverlayL3Context.class);
-        when(l3Ep.getAugmentation(OfOverlayL3Context.class)).thenReturn(ofL3Ctx);
-
-        CheckedFuture<Optional<Tenant>, ReadFailedException> checkedFuture = mock(CheckedFuture.class);
-        when(rwTx.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
-        Optional<Tenant> optional = mock(Optional.class);
-        when(checkedFuture.checkedGet()).thenReturn(optional);
-        when(optional.isPresent()).thenReturn(false);
-
-        Method method = EndpointManager.class.getDeclaredMethod("addEndpointFromL3Endpoint", EndpointL3.class,
-                ReadWriteTransaction.class);
-        method.setAccessible(true);
-        method.invoke(manager, l3Ep, rwTx);
-        verify(rwTx).cancel();
-    }
-
     @Test
     public void closeTest() throws Exception {
         manager.close();
-        verify(listenerReg).close();
-        manager = new EndpointManager(null, rpcRegistry, notificationService, executor, switchManager);
-        manager.close();
-        verify(listenerReg, times(1)).close();
+        verify(listenerReg, times(3)).close();
     }
 
      //**************