Encapsulate OpenFlowPlugin configuration
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / RpcManagerImplTest.java
index f3c6dabb6bd429ae0467c1a152b0f1d713fd4f9c..3f68647244ecd0df20588d7b748e9e761adc338b 100644 (file)
@@ -8,11 +8,8 @@
 package org.opendaylight.openflowplugin.impl.rpc;
 
 import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import com.google.common.base.VerifyException;
 import java.util.concurrent.ConcurrentMap;
 import org.junit.Before;
 import org.junit.Rule;
@@ -31,9 +28,6 @@ import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
@@ -45,6 +39,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
+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.OpenflowProviderConfigBuilder;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
@@ -60,16 +56,10 @@ public class RpcManagerImplTest {
     @Mock
     private DeviceContext deviceContext;
     @Mock
-    private DeviceInitializationPhaseHandler deviceINitializationPhaseHandler;
-    @Mock
-    private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
-    @Mock
     private BindingAwareBroker.RoutedRpcRegistration<RpcService> routedRpcRegistration;
     @Mock
     private DeviceState deviceState;
     @Mock
-    private MessageSpy mockMsgSpy;
-    @Mock
     private ConnectionContext connectionContext;
     @Mock
     private ItemLifeCycleRegistry itemLifeCycleRegistry;
@@ -82,8 +72,6 @@ public class RpcManagerImplTest {
     @Mock
     private DeviceInfo deviceInfo;
     @Mock
-    private LifecycleService lifecycleService;
-    @Mock
     private ExtensionConverterProvider extensionConverterProvider;
     @Mock
     private ConvertorExecutor convertorExecutor;
@@ -100,8 +88,9 @@ public class RpcManagerImplTest {
     @Before
     public void setUp() {
         final NodeKey nodeKey = new NodeKey(nodeId);
-        rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, extensionConverterProvider, convertorExecutor, notificationPublishService);
-        rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
+        rpcManager = new RpcManagerImpl(new OpenflowProviderConfigBuilder()
+                .setRpcRequestsQuota(new NonZeroUint16Type(QUOTA_VALUE))
+                .build(), rpcProviderRegistry, extensionConverterProvider, convertorExecutor, notificationPublishService);
 
         GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder()
                 .setVersion(OFConstants.OFP_VERSION_1_3)
@@ -114,7 +103,6 @@ public class RpcManagerImplTest {
         Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
         Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
         Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
-        rpcManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
         Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
         Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
@@ -123,64 +111,9 @@ public class RpcManagerImplTest {
         Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
         Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId());
         Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
-                Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
+                Matchers.any(), Matchers.any(RpcService.class)))
                 .thenReturn(routedRpcRegistration);
         Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts);
-        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext);
-    }
-
-    @Test
-    public void onDeviceContextLevelUpTwice() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        expectedException.expect(VerifyException.class);
-        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-    }
-
-    @Test
-    public void testOnDeviceContextLevelUpMaster() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
-    }
-
-    @Test
-    public void testOnDeviceContextLevelUpSlave() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
-    }
-
-    @Test
-    public void testOnDeviceContextLevelUpOther() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
-    }
-
-    @Test
-    public void testOnDeviceContextLevelDown() throws Exception {
-        rpcManager.onDeviceContextLevelDown(deviceInfo);
-        verify(deviceTerminationPhaseHandler).onDeviceContextLevelDown(deviceInfo);
-    }
-
-    /**
-     * On non null context close and onDeviceContextLevelDown should be called
-     */
-    @Test
-    public void onDeviceContextLevelDown1() {
-        rpcManager.addRecordToContexts(deviceInfo,removedContexts);
-        rpcManager.onDeviceContextLevelDown(deviceInfo);
-        verify(removedContexts,times(1)).close();
-        verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceInfo);
-    }
-
-
-    /**
-     * On null context only onDeviceContextLevelDown should be called
-     */
-    @Test
-    public void onDeviceContextLevelDown2() {
-        rpcManager.onDeviceContextLevelDown(deviceInfo);
-        verify(removedContexts,never()).close();
-        verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceInfo);
-
     }
 
     @Test