Merge "Spec: OFPGC_ADD_OR_MOD support in openflowplugin"
[openflowplugin.git] / applications / topology-lldp-discovery / src / test / java / org / opendaylight / openflowplugin / applications / topology / lldp / LLDPLinkAgerTest.java
index 056fde6e684fb2410e3db12117f439c50d4497cd..8b107b82a08ff4f553e43653aac3f658f5cce55a 100644 (file)
@@ -12,18 +12,20 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.verify;
 
-import java.util.Date;
-import java.util.Map;
-import java.util.Timer;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+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.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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,26 +41,19 @@ public class LLDPLinkAgerTest {
     private final long LLDP_INTERVAL = 5L;
     private final long LINK_EXPIRATION_TIME = 10L;
     /**
-     * We need to w8 while other tasks are finished before we can check anything
+     * We need to wait while other tasks are finished before we can check anything
      * in LLDPAgingTask
      */
     private final int SLEEP = 100;
 
-
     @Mock
     private LinkDiscovered link;
     @Mock
-    private Map<LinkDiscovered, Date> linkToDate;
-    @Mock
-    private Timer timer;
-    @Mock
     private NotificationProviderService notificationService;
-    @Mock
-    private LinkRemoved linkRemoved;
 
     @Before
     public void setUp() throws Exception {
-        lldpLinkAger = new LLDPLinkAger(LLDP_INTERVAL, LINK_EXPIRATION_TIME, notificationService);
+        lldpLinkAger = new LLDPLinkAger(getConfig(), notificationService, getConfigurationService());
     }
 
     @Test
@@ -69,7 +64,7 @@ public class LLDPLinkAgerTest {
     }
 
     @Test
-    public void testClose() {
+    public void testClose() throws Exception {
         lldpLinkAger.close();
         assertTrue(lldpLinkAger.isLinkToDateEmpty());
     }
@@ -83,4 +78,27 @@ public class LLDPLinkAgerTest {
         Thread.sleep(SLEEP);
         verify(notificationService).publish(Matchers.any(LinkRemoved.class));
     }
+
+    private TopologyLldpDiscoveryConfig getConfig() {
+        TopologyLldpDiscoveryConfigBuilder cfgBuilder = new TopologyLldpDiscoveryConfigBuilder();
+        cfgBuilder.setTopologyLldpInterval(new NonZeroUint32Type(LLDP_INTERVAL));
+        cfgBuilder.setTopologyLldpExpirationInterval(new NonZeroUint32Type(LINK_EXPIRATION_TIME));
+        return cfgBuilder.build();
+    }
+
+    private ConfigurationService getConfigurationService() {
+        final ConfigurationService configurationService = Mockito.mock(ConfigurationService.class);
+        final TopologyLldpDiscoveryConfig config = getConfig();
+
+        Mockito.when(configurationService.registerListener(Mockito.any())).thenReturn(() -> {
+        });
+
+        Mockito.when(configurationService.getProperty(Mockito.eq("topology-lldp-interval"), Mockito.any()))
+                .thenReturn(config.getTopologyLldpInterval());
+
+        Mockito.when(configurationService.getProperty(Mockito.eq("topology-lldp-expiration-interval"), Mockito.any()))
+                .thenReturn(config.getTopologyLldpExpirationInterval());
+
+        return configurationService;
+    }
 }
\ No newline at end of file