Migrate MockitoJUnitRunner
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / configuration / ConfigurationServiceFactoryImplTest.java
index e5010013aead1de46e8febbe91bac6d2c7560676..703f5773ff04597745ea85c5b56ebd90298c4ebe 100644 (file)
@@ -10,34 +10,31 @@ package org.opendaylight.openflowplugin.impl.configuration;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import com.google.common.collect.ImmutableMap;
-import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.openflowplugin.api.OFConstants;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationListener;
 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ConfigurationServiceFactoryImplTest {
-    private static final int CONFIG_PROP_COUNT = 23;
+    private static final int CONFIG_PROP_COUNT = 24;
     private static final boolean IS_STATISTICS_POLLING_ON = true;
     private static final int BARRIER_COUNT_LIMIT = 2000;
     private static final long BARRIER_INTERVAL_TIMEOUT_LIMIT = 3000;
@@ -50,35 +47,24 @@ public class ConfigurationServiceFactoryImplTest {
     private static final boolean IS_STATISTICS_RPC_ENABLED = false;
     private static final boolean USE_SINGLE_LAYER_SERIALIZATION = true;
     private static final int RPC_REQUESTS_QUOTA = 2500;
-    private static final long GLOBAL_NOTIFICATION_QUOTA = 9000;
-    private static final int THREAD_POOL_MIN_THREADS = 3;
+    private static final Uint32 GLOBAL_NOTIFICATION_QUOTA = Uint32.valueOf(9000);
+    private static final Uint16 THREAD_POOL_MIN_THREADS = Uint16.valueOf(3);
     private static final int THREAD_POOL_MIN_THREADS_UPDATE = 4;
     private static final int THREAD_POOL_MAX_THREADS = 1000;
-    private static final long THREAD_POOL_TIMEOUT = 60;
-    private static final int DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = 0;
+    private static final Uint32 THREAD_POOL_TIMEOUT = Uint32.valueOf(60);
+    private static final Uint16 DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = Uint16.ZERO;
+    private static final Uint16 DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS = Uint16.valueOf(60);
 
     @Mock
     private OpenflowProviderConfig config;
 
-    @Mock
-    private BundleContext bundleContext;
-
     @Mock
     private ConfigurationListener configurationListener;
 
-    @Mock
-    private ConfigurationAdmin configurationAdmin;
-
-    @Mock
-    private ServiceReference<ConfigurationAdmin> serviceReference;
-
-    @Mock
-    private Configuration configuration;
-
     private ConfigurationService configurationService;
 
     @Before
-    public void setUp() throws Exception {
+    public void setUp() {
         when(config.isIsStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
         when(config.isIsFlowStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
         when(config.isIsTableStatisticsPollingOn()).thenReturn(IS_STATISTICS_POLLING_ON);
@@ -103,21 +89,18 @@ public class ConfigurationServiceFactoryImplTest {
         when(config.getThreadPoolMaxThreads()).thenReturn(new NonZeroUint16Type(THREAD_POOL_MAX_THREADS));
         when(config.getThreadPoolTimeout()).thenReturn(THREAD_POOL_TIMEOUT);
         when(config.getDeviceConnectionRateLimitPerMin()).thenReturn(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN);
+        when(config.getDeviceConnectionHoldTimeInSeconds()).thenReturn(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS);
 
-        final Dictionary<String, Object> properties = new Hashtable<>();
-        properties.put(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString(), IS_STATISTICS_POLLING_ON);
+        final Map<String, String> properties = new Hashtable<>();
+        properties.put(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString(),
+                Boolean.toString(IS_STATISTICS_POLLING_ON));
 
-        when(configuration.getProperties()).thenReturn(properties);
-        when(configurationAdmin.getConfiguration(OFConstants.CONFIG_FILE_ID)).thenReturn(configuration);
-        when(bundleContext.getService(serviceReference)).thenReturn(configurationAdmin);
-        when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(serviceReference);
-
-        configurationService = new ConfigurationServiceFactoryImpl()
-                .newInstance(config, bundleContext);
+        configurationService = new ConfigurationServiceFactoryImpl().newInstance(config);
+        configurationService.update(properties);
     }
 
     @Test
-    public void update() throws Exception {
+    public void update() {
         final int tpMinThreads = configurationService
                 .getProperty(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString(), Integer::valueOf);
 
@@ -135,7 +118,7 @@ public class ConfigurationServiceFactoryImplTest {
     }
 
     @Test
-    public void getProperty() throws Exception {
+    public void getProperty() {
         final int tpMaxThreads = configurationService
                 .getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf);
 
@@ -143,7 +126,7 @@ public class ConfigurationServiceFactoryImplTest {
     }
 
     @Test
-    public void registerListener() throws Exception {
+    public void registerListener() {
         configurationService.registerListener(configurationListener);
         verify(configurationListener, times(CONFIG_PROP_COUNT)).onPropertyChanged(any(), any());
     }
@@ -153,5 +136,4 @@ public class ConfigurationServiceFactoryImplTest {
         configurationService.close();
         configurationService.getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf);
     }
-
-}
\ No newline at end of file
+}