Convert DataChangeListeners to DataTreeChangeListeners
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / endpoint / EndpointManagerTest.java
index fe232f183e2eca259c06bd16ec29615534cdc672..6669d4f5b2ebd2d08124e6389c588169b6aaf03c 100644 (file)
@@ -8,6 +8,11 @@
 
 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -16,38 +21,34 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.lang.reflect.Method;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.UUID;
 import java.util.concurrent.ScheduledExecutorService;
-
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
 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.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;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.groupbasedpolicy.dto.EgKey;
 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.yang.types.rev100924.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
@@ -64,27 +65,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.l3endpoint.rev151217.NatAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayL3Context;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.ForwardingContext;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.forwarding.context.L2BridgeDomain;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.RpcService;
-
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
 
 public class EndpointManagerTest {
 
     private EndpointManager manager;
     private DataBroker dataProvider;
-    private RpcProviderRegistry rpcRegistry;
+    private PacketProcessingService packetService;
+    private SalFlowService flowService;
     private NotificationService notificationService;
     private ScheduledExecutorService executor;
     private SwitchManager switchManager;
-    private ListenerRegistration<DataChangeListener> listenerReg;
     private EndpointListener endpointListener;
     private Endpoint endpoint1;
     private Endpoint endpoint2;
@@ -99,11 +93,14 @@ public class EndpointManagerTest {
     private EndpointL3 newL3Ep;
     private Optional<Endpoints> optionalRead;
 
+    // TODO get rid of unnecessary mocks (endpoint1, endpoint2, their parameters)
+
     @SuppressWarnings("unchecked")
     @Before
     public void initialisation() throws Exception {
         dataProvider = mock(DataBroker.class);
-        rpcRegistry = mock(RpcProviderRegistry.class);
+        packetService = mock(PacketProcessingService.class);
+        flowService = mock(SalFlowService.class);
         notificationService = mock(NotificationService.class);
         executor = mock(ScheduledExecutorService.class);
         switchManager = mock(SwitchManager.class);
@@ -111,14 +108,12 @@ public class EndpointManagerTest {
         when(dataProvider.newWriteOnlyTransaction()).thenReturn(writeTransaction);
         CheckedFuture<Void, TransactionCommitFailedException> checkedFutureWrite = mock(CheckedFuture.class);
         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(rpcRegistry.addRpcImplementation(any(Class.class), any(RpcService.class))).thenReturn(rpcRegistration);
-
-        manager = spy(new EndpointManager(dataProvider, rpcRegistry, notificationService, executor, switchManager));
+        BindingAwareBroker.RpcRegistration<EndpointService> rpcRegistration =
+                mock(BindingAwareBroker.RpcRegistration.class);
+        when(dataProvider.registerDataTreeChangeListener(any(DataTreeIdentifier.class),
+                any(ClusteredDataTreeChangeListener.class))).thenReturn(mock(ListenerRegistration.class));
+
+        manager = spy(new EndpointManager(dataProvider, packetService, flowService, notificationService, executor, switchManager));
         endpointListener = mock(EndpointListener.class);
         manager.registerListener(endpointListener);
 
@@ -127,7 +122,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);
@@ -147,13 +142,6 @@ public class EndpointManagerTest {
         when(nodeId1.getValue()).thenReturn("nodeValue1");
         when(nodeId2.getValue()).thenReturn("nodeValue2");
 
-        // onDataChanged
-        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change = mock(AsyncDataChangeEvent.class);
-        InstanceIdentifier<DataObject> endpointId = mock(InstanceIdentifier.class);
-        Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
-        removedPaths.add(endpointId);
-        when(change.getRemovedPaths()).thenReturn(removedPaths);
-
         // updateEndpointL3
         oldL3Ep = mock(EndpointL3.class);
         newL3Ep = mock(EndpointL3.class);
@@ -162,8 +150,8 @@ public class EndpointManagerTest {
         ReadOnlyTransaction readTransaction = mock(ReadOnlyTransaction.class);
         when(dataProvider.newReadOnlyTransaction()).thenReturn(readTransaction);
         CheckedFuture<Optional<Endpoints>, ReadFailedException> checkedFutureRead = mock(CheckedFuture.class);
-        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(
-                checkedFutureRead);
+        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+            .thenReturn(checkedFutureRead);
         optionalRead = mock(Optional.class);
         when(checkedFutureRead.checkedGet()).thenReturn(optionalRead);
         when(optionalRead.isPresent()).thenReturn(false);
@@ -176,39 +164,39 @@ public class EndpointManagerTest {
 
     @Test
     public void getGroupsForNodeTest() {
-        Assert.assertTrue(manager.getGroupsForNode(nodeId1).isEmpty());
+        assertTrue(manager.getGroupsForNode(nodeId1).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getGroupsForNode(nodeId1).isEmpty());
+        assertFalse(manager.getGroupsForNode(nodeId1).isEmpty());
     }
 
     @Test
     public void getNodesForGroupTest() {
         EgKey egKey = mock(EgKey.class);
         Set<NodeId> nodesForGroup = manager.getNodesForGroup(egKey);
-        Assert.assertNotNull(nodesForGroup);
-        Assert.assertTrue(nodesForGroup.isEmpty());
+        assertNotNull(nodesForGroup);
+        assertTrue(nodesForGroup.isEmpty());
     }
 
     @Test
     public void getEndpointsForNodeTestNodeIdEgKey() {
         EgKey egKey = new EgKey(tenantId, endpointGroupId);
-        Assert.assertTrue(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
+        assertTrue(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
+        assertFalse(manager.getEndpointsForNode(nodeId1, egKey).isEmpty());
     }
 
     @Test
     public void getEndpointsForNodeTestNodeId() {
-        Assert.assertTrue(manager.getEndpointsForNode(nodeId1).isEmpty());
+        assertTrue(manager.getEndpointsForNode(nodeId1).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getEndpointsForNode(nodeId1).isEmpty());
+        assertFalse(manager.getEndpointsForNode(nodeId1).isEmpty());
     }
 
     @Test
     public void getEndpoint() {
         EpKey epKey = new EpKey(endpoint1.getL2Context(), endpoint1.getMacAddress());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertEquals(endpoint1, manager.getEndpoint(epKey));
+        assertEquals(endpoint1, manager.getEndpoint(epKey));
     }
 
     @SuppressWarnings("unchecked")
@@ -217,8 +205,8 @@ public class EndpointManagerTest {
         ReadOnlyTransaction readTransaction = mock(ReadOnlyTransaction.class);
         when(dataProvider.newReadOnlyTransaction()).thenReturn(readTransaction);
         CheckedFuture<Optional<Endpoints>, ReadFailedException> resultFuture = mock(CheckedFuture.class);
-        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(
-                resultFuture);
+        when(readTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+            .thenReturn(resultFuture);
         Optional<Endpoints> optional = mock(Optional.class);
         when(resultFuture.checkedGet()).thenReturn(optional);
         when(optional.isPresent()).thenReturn(true);
@@ -229,7 +217,7 @@ public class EndpointManagerTest {
         when(endpointL3Prefix.getTenant()).thenReturn(tenantId);
 
         Collection<EndpointL3Prefix> result = manager.getEndpointsL3PrefixForTenant(tenantId);
-        Assert.assertTrue(result.contains(endpointL3Prefix));
+        assertTrue(result.contains(endpointL3Prefix));
     }
 
     @SuppressWarnings("unchecked")
@@ -238,24 +226,25 @@ public class EndpointManagerTest {
         ReadOnlyTransaction transaction = mock(ReadOnlyTransaction.class);
         when(dataProvider.newReadOnlyTransaction()).thenReturn(transaction);
         CheckedFuture<Optional<Endpoints>, ReadFailedException> checkedFuture = mock(CheckedFuture.class);
-        when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture);
+        when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
+            .thenReturn(checkedFuture);
         Optional<Endpoints> optional = mock(Optional.class);
         when(checkedFuture.checkedGet()).thenReturn(optional);
         when(optional.isPresent()).thenReturn(false);
-        Assert.assertNull(manager.getEndpointsFromDataStore());
+        assertNull(manager.getEndpointsFromDataStore());
 
         when(optional.isPresent()).thenReturn(true);
         Endpoints endpoints = mock(Endpoints.class);
         when(optional.get()).thenReturn(endpoints);
-        Assert.assertEquals(endpoints, manager.getEndpointsFromDataStore());
+        assertEquals(endpoints, manager.getEndpointsFromDataStore());
 
-        manager = new EndpointManager(null, rpcRegistry, notificationService, executor, switchManager);
-        Assert.assertNull(manager.getEndpointsFromDataStore());
+        manager = new EndpointManager(null, packetService, flowService, notificationService, executor, switchManager);
+        assertNull(manager.getEndpointsFromDataStore());
     }
 
     @Test
     public void getL3EndpointsTestEndpointsNull() throws Exception {
-        Assert.assertNull(manager.getL3Endpoints());
+        assertNull(manager.getL3Endpoints());
     }
 
     @Test
@@ -265,7 +254,7 @@ public class EndpointManagerTest {
         when(optionalRead.get()).thenReturn(endpoints);
         when(endpoints.getEndpointL3()).thenReturn(null);
 
-        Assert.assertNull(manager.getL3Endpoints());
+        assertNull(manager.getL3Endpoints());
     }
 
     @Test
@@ -276,7 +265,7 @@ public class EndpointManagerTest {
         List<EndpointL3> endpointL3List = Collections.singletonList(mock(EndpointL3.class));
         when(endpoints.getEndpointL3()).thenReturn(endpointL3List);
 
-        Assert.assertEquals(endpointL3List, manager.getL3Endpoints());
+        assertEquals(endpointL3List, manager.getL3Endpoints());
     }
 
     @Test
@@ -296,13 +285,13 @@ public class EndpointManagerTest {
         when(endpointL3.getMacAddress()).thenReturn(mock(MacAddress.class));
 
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.containsValue(endpointL3));
+        assertTrue(result.containsValue(endpointL3));
     }
 
     @Test
     public void getL3EpWithNatByL2KeyTestL3EpsNull() {
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.isEmpty());
+        assertTrue(result.isEmpty());
     }
 
     @Test
@@ -321,7 +310,7 @@ public class EndpointManagerTest {
         when(endpointL3.getMacAddress()).thenReturn(null);
 
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.isEmpty());
+        assertTrue(result.isEmpty());
     }
 
     @Test
@@ -340,26 +329,26 @@ public class EndpointManagerTest {
         when(endpointL3.getMacAddress()).thenReturn(mock(MacAddress.class));
 
         Map<EndpointKey, EndpointL3> result = manager.getL3EpWithNatByL2Key();
-        Assert.assertTrue(result.isEmpty());
+        assertTrue(result.isEmpty());
     }
 
     @Test
     public void getEndpointsForGroupTest() {
         EgKey newEgKey = new EgKey(tenantId, endpointGroupId);
-        Assert.assertTrue(manager.getEndpointsForGroup(newEgKey).isEmpty());
+        assertTrue(manager.getEndpointsForGroup(newEgKey).isEmpty());
         manager.processEndpoint(null, endpoint1);
-        Assert.assertFalse(manager.getEndpointsForGroup(newEgKey).isEmpty());
+        assertFalse(manager.getEndpointsForGroup(newEgKey).isEmpty());
     }
 
     @Test
     public void getConditionsForEndpoint() {
         Endpoint endpoint = mock(Endpoint.class);
         when(endpoint.getCondition()).thenReturn(null);
-        Assert.assertTrue(manager.getConditionsForEndpoint(endpoint).isEmpty());
+        assertTrue(manager.getConditionsForEndpoint(endpoint).isEmpty());
 
         List<ConditionName> conditionNameList = Collections.singletonList(mock(ConditionName.class));
         when(endpoint.getCondition()).thenReturn(conditionNameList);
-        Assert.assertEquals(conditionNameList, manager.getConditionsForEndpoint(endpoint));
+        assertEquals(conditionNameList, manager.getConditionsForEndpoint(endpoint));
     }
 
     @Test
@@ -379,9 +368,9 @@ 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));
+        verify(endpointListener, never()).endpointUpdated(any(EpKey.class));
     }
 
     @Test
@@ -400,9 +389,9 @@ 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));
+        verify(endpointListener, never()).endpointUpdated(any(EpKey.class));
     }
 
     @Test
@@ -419,7 +408,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,17 +419,42 @@ 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));
+        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));
     }
 
+    @Test
+    public void updateEndpointL3TestUpdate() throws Exception {
+        when(oldL3Ep.getIpAddress()).thenReturn(new IpAddress(new Ipv4Address("1.1.1.1")));
+
+        when(newL3Ep.getTenant()).thenReturn(mock(TenantId.class));
+        when(newL3Ep.getEndpointGroup()).thenReturn(mock(EndpointGroupId.class));
+        when(newL3Ep.getL3Context()).thenReturn(mock(L3ContextId.class));
+        when(newL3Ep.getIpAddress()).thenReturn(mock(IpAddress.class));
+
+        OfOverlayL3Context ofOverlayL3Context = mock(OfOverlayL3Context.class);
+        when(newL3Ep.getAugmentation(OfOverlayL3Context.class)).thenReturn(ofOverlayL3Context);
+
+        when(newL3Ep.getNetworkContainment()).thenReturn(null);
+
+        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, oldL3Ep);
+        manager.processL3Endpoint(oldL3Ep, newL3Ep);
+
+        verify(endpointListener).endpointUpdated(any(EpKey.class));
+    }
+
     @Test
     public void updateEndpointTestNewEndpointRemove() {
         Collection<Endpoint> collection;
@@ -448,13 +462,13 @@ public class EndpointManagerTest {
         verify(endpointListener).endpointUpdated(any(EpKey.class));
         verify(endpointListener).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
 
         manager.processEndpoint(endpoint2, null);
         verify(endpointListener, times(2)).endpointUpdated(any(EpKey.class));
         verify(endpointListener, times(2)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
     }
 
     @Test
@@ -510,7 +524,7 @@ public class EndpointManagerTest {
         // create: node1, update: node1 -> node2
         verify(endpointListener, times(3)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     /**
@@ -528,9 +542,9 @@ public class EndpointManagerTest {
         verify(endpointListener, times(2)).endpointUpdated(any(EpKey.class));
         verify(endpointListener, times(1)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, otherEndpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     /**
@@ -548,9 +562,9 @@ public class EndpointManagerTest {
         // create: node1, update: node1 -> node2
         verify(endpointListener, times(3)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, otherEndpointGroupId));
-        Assert.assertFalse(collection.isEmpty());
+        assertFalse(collection.isEmpty());
     }
 
     /**
@@ -567,7 +581,7 @@ public class EndpointManagerTest {
         verify(endpointListener, times(2)).endpointUpdated(any(EpKey.class));
         verify(endpointListener, times(2)).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        Assert.assertTrue(collection.isEmpty());
+        assertTrue(collection.isEmpty());
     }
 
     /**
@@ -584,105 +598,44 @@ public class EndpointManagerTest {
         verify(endpointListener).endpointUpdated(any(EpKey.class));
         verify(endpointListener).nodeEndpointUpdated(any(NodeId.class), any(EpKey.class));
         collection = manager.getEndpointsForGroup(new EgKey(tenantId, endpointGroupId));
-        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();
+        assertFalse(collection.isEmpty());
     }
 
     @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();
     }
 
-     //**************
-     //Helper Functions
-     //**************
+    // **************
+    // Helper Functions
+    // **************
 
     @Test
     public void getEgKeyTest() {
-        Assert.assertNotNull(manager.getEgKey(endpoint1));
-        Assert.assertNull(manager.getEgKey(null));
+        assertNotNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(null));
 
         when(endpoint1.getTenant()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getTenant()).thenReturn(tenantId);
         when(endpoint1.getEndpointGroup()).thenReturn(null);
-        Assert.assertNotNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId);
         when(endpoint1.getEndpointGroups()).thenReturn(null);
-        Assert.assertNotNull(manager.getEgKey(endpoint1));
+        assertNotNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getEndpointGroup()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getEndpointGroup()).thenReturn(endpointGroupId);
         when(endpoint1.getL2Context()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
 
         when(endpoint1.getL2Context()).thenReturn(l2BridgeDomainId);
         when(endpoint1.getMacAddress()).thenReturn(null);
-        Assert.assertNull(manager.getEgKey(endpoint1));
+        assertNull(manager.getEgKey(endpoint1));
     }
 
     @Test
@@ -692,18 +645,18 @@ public class EndpointManagerTest {
 
         when(endpoint.getEndpointGroups()).thenReturn(null);
         egKeys = manager.getEgKeysForEndpoint(endpoint);
-        Assert.assertTrue(egKeys.isEmpty());
+        assertTrue(egKeys.isEmpty());
 
         EndpointGroupId endpointGroupId = mock(EndpointGroupId.class);
         when(endpoint.getEndpointGroup()).thenReturn(endpointGroupId);
         egKeys = manager.getEgKeysForEndpoint(endpoint);
-        Assert.assertEquals(1, egKeys.size());
+        assertEquals(1, egKeys.size());
 
         EndpointGroupId epgId = mock(EndpointGroupId.class);
         List<EndpointGroupId> endpointGroups = Collections.singletonList(epgId);
         when(endpoint.getEndpointGroups()).thenReturn(endpointGroups);
         egKeys = manager.getEgKeysForEndpoint(endpoint);
-        Assert.assertEquals(2, egKeys.size());
+        assertEquals(2, egKeys.size());
     }
 
     @Test
@@ -711,21 +664,42 @@ public class EndpointManagerTest {
         Endpoint endpoint = mock(Endpoint.class);
         when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(null);
         // TODO
-//        Assert.assertFalse(manager.isExternal(endpoint));
-//        Assert.assertTrue(manager.isInternal(endpoint));
-//
-//        OfOverlayContext ofc = mock(OfOverlayContext.class);
-//        when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(ofc);
-//        when(ofc.getLocationType()).thenReturn(null);
-//        Assert.assertFalse(manager.isExternal(endpoint));
-//        Assert.assertTrue(manager.isInternal(endpoint));
-//
-//        when(ofc.getLocationType()).thenReturn(LocationType.Internal);
-//        Assert.assertFalse(manager.isExternal(endpoint));
-//        Assert.assertTrue(manager.isInternal(endpoint));
-//
-//        when(ofc.getLocationType()).thenReturn(LocationType.External);
-//        Assert.assertTrue(manager.isExternal(endpoint));
-//        Assert.assertFalse(manager.isInternal(endpoint));
+        // assertFalse(manager.isExternal(endpoint));
+        // assertTrue(manager.isInternal(endpoint));
+        //
+        // OfOverlayContext ofc = mock(OfOverlayContext.class);
+        // when(endpoint.getAugmentation(OfOverlayContext.class)).thenReturn(ofc);
+        // when(ofc.getLocationType()).thenReturn(null);
+        // assertFalse(manager.isExternal(endpoint));
+        // assertTrue(manager.isInternal(endpoint));
+        //
+        // when(ofc.getLocationType()).thenReturn(LocationType.Internal);
+        // assertFalse(manager.isExternal(endpoint));
+        // assertTrue(manager.isInternal(endpoint));
+        //
+        // when(ofc.getLocationType()).thenReturn(LocationType.External);
+        // assertTrue(manager.isExternal(endpoint));
+        // assertFalse(manager.isInternal(endpoint));
+    }
+
+    @Test
+    public void testGetL2EndpointFromL3() {
+        when(newL3Ep.getL2Context()).thenReturn(mock(L2BridgeDomainId.class));
+        when(newL3Ep.getMacAddress()).thenReturn(mock(MacAddress.class));
+
+        Endpoint ep = manager.getL2EndpointFromL3(newL3Ep);
+
+        assertNull(ep);
     }
+
+    @Test
+    public void testGetL2EndpointFromL3_noL2Context_noMacAddr() {
+        when(newL3Ep.getL2Context()).thenReturn(null);
+        when(newL3Ep.getMacAddress()).thenReturn(null);
+
+        Endpoint ep = manager.getL2EndpointFromL3(newL3Ep);
+
+        assertNull(ep);
+    }
+
 }