Enable checkstyle enforcement in openflowplugin-parent
[openflowplugin.git] / applications / topology-lldp-discovery / src / test / java / org / opendaylight / openflowplugin / applications / topology / lldp / LLDPLinkAgerTest.java
index 8b107b82a08ff4f553e43653aac3f658f5cce55a..2645cefde98b84971c76a66d07a414433c17e4e6 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.verify;
 
+import com.google.common.base.Optional;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -20,12 +21,21 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.mdsal.eos.binding.api.Entity;
+import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
+import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.config.rev160511.NonZeroUint32Type;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.config.rev160511.TopologyLldpDiscoveryConfig;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.config.rev160511.TopologyLldpDiscoveryConfigBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,23 +47,32 @@ public class LLDPLinkAgerTest {
 
     private static final Logger LOG = LoggerFactory.getLogger(LLDPLinkAgerTest.class);
 
-    private LLDPLinkAger lldpLinkAger;
-    private final long LLDP_INTERVAL = 5L;
-    private final long LINK_EXPIRATION_TIME = 10L;
+    private static final long LLDP_INTERVAL = 5L;
+    private static final long LINK_EXPIRATION_TIME = 10L;
+
     /**
-     * We need to wait while other tasks are finished before we can check anything
-     * in LLDPAgingTask
+     * We need to wait while other tasks are finished before we can check anything in LLDPAgingTask.
      */
-    private final int SLEEP = 100;
+    private static final int SLEEP = 100;
+
+    private LLDPLinkAger lldpLinkAger;
 
     @Mock
     private LinkDiscovered link;
     @Mock
     private NotificationProviderService notificationService;
+    @Mock
+    private EntityOwnershipService eos;
+    @Mock
+    private LinkRemoved linkRemoved;
 
     @Before
     public void setUp() throws Exception {
-        lldpLinkAger = new LLDPLinkAger(getConfig(), notificationService, getConfigurationService());
+        lldpLinkAger = new LLDPLinkAger(getConfig(), notificationService, getConfigurationService(), eos);
+        Mockito.when(link.getDestination()).thenReturn(new NodeConnectorRef(
+                InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1")))));
+        Mockito.when(eos.getOwnershipState(Mockito.any(Entity.class))).thenReturn(
+                Optional.of(EntityOwnershipState.IS_OWNER));
     }
 
     @Test
@@ -70,7 +89,7 @@ public class LLDPLinkAgerTest {
     }
 
     /**
-     * Inner class LLDPAgingTask removes all expired records from linkToDate if any (in constructor of LLDPLinkAger)
+     * Inner class LLDPAgingTask removes all expired records from linkToDate if any (in constructor of LLDPLinkAger).
      */
     @Test
     public void testLLDPAgingTask() throws InterruptedException {
@@ -101,4 +120,4 @@ public class LLDPLinkAgerTest {
 
         return configurationService;
     }
-}
\ No newline at end of file
+}