Merge "SONAR TD - Group actions redundancy"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / RpcContextImplTest.java
index 854d4d3269ac9fdb7317802680025cc123f28189..d38ff06800cc8da44022af9744d30ba99e6eb508 100644 (file)
@@ -7,11 +7,13 @@
  */
 package org.opendaylight.openflowplugin.impl.rpc;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.junit.Assert.assertEquals;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -20,13 +22,15 @@ import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 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.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.XidSequencer;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -35,7 +39,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.N
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
-import java.util.concurrent.Semaphore;
 
 @RunWith(MockitoJUnitRunner.class)
 public class RpcContextImplTest {
@@ -55,11 +58,19 @@ public class RpcContextImplTest {
     @Mock
     private DeviceContext deviceContext;
     @Mock
-    private BindingAwareBroker.RoutedRpcRegistration routedRpcReg;
+    private BindingAwareBroker.RoutedRpcRegistration<TestRpcService> routedRpcReg;
+
+    private Class<TestRpcService> serviceClass;
     @Mock
     private NotificationPublishService notificationPublishService;
     @Mock
     private TestRpcService serviceInstance;
+    @Mock
+    private DeviceInfo deviceInfo;
+    @Mock
+    private ExtensionConverterProvider extensionConverterProvider;
+    @Mock
+    private ConvertorExecutor convertorExecutor;
 
     private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
 
@@ -69,10 +80,19 @@ public class RpcContextImplTest {
         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
 
         when(deviceContext.getDeviceState()).thenReturn(deviceState);
-        when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
+        when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
         when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
 
-        rpcContext = new RpcContextImpl(rpcProviderRegistry,deviceContext, messageSpy, MAX_REQUESTS,nodeInstanceIdentifier);
+        rpcContext = new RpcContextImpl(
+                deviceInfo,
+                rpcProviderRegistry,
+                messageSpy,
+                MAX_REQUESTS,
+                nodeInstanceIdentifier,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService);
 
         when(rpcProviderRegistry.addRoutedRpcImplementation(TestRpcService.class, serviceInstance)).thenReturn(routedRpcReg);
 
@@ -80,8 +100,16 @@ public class RpcContextImplTest {
 
     @Test
     public void testStoreOrFail() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
-                messageSpy, 100, nodeInstanceIdentifier)) {
+        try (final RpcContext rpcContext = new RpcContextImpl(
+                deviceInfo,
+                rpcProviderRegistry,
+                messageSpy,
+                100,
+                nodeInstanceIdentifier,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService)){
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNotNull(requestContext);
         }
@@ -89,8 +117,16 @@ public class RpcContextImplTest {
 
     @Test
     public void testStoreOrFailThatFails() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
-                messageSpy, 0, nodeInstanceIdentifier)) {
+        try (final RpcContext rpcContext = new RpcContextImpl(
+                deviceInfo,
+                rpcProviderRegistry,
+                messageSpy,
+                0,
+                nodeInstanceIdentifier,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService)){
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNull(requestContext);
         }
@@ -98,8 +134,16 @@ public class RpcContextImplTest {
 
     @Test
     public void testStoreAndCloseOrFail() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, deviceContext, messageSpy,
-                100, nodeInstanceIdentifier)) {
+        try (final RpcContext rpcContext = new RpcContextImpl(
+                deviceInfo,
+                rpcProviderRegistry,
+                messageSpy,
+                100,
+                nodeInstanceIdentifier,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService)){
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNotNull(requestContext);
             requestContext.close();
@@ -125,6 +169,8 @@ public class RpcContextImplTest {
 
     @Test
     public void testClose() {
+        serviceClass = TestRpcService.class;
+        when(routedRpcReg.getServiceType()).thenReturn(serviceClass);
         rpcContext.registerRpcServiceImplementation(TestRpcService.class, serviceInstance);
         rpcContext.close();
         assertEquals(rpcContext.isEmptyRpcRegistrations(), true);
@@ -136,7 +182,7 @@ public class RpcContextImplTest {
      */
     @Test
     public void testCreateRequestContext1() throws InterruptedException {
-        when(deviceContext.reserveXidForDeviceMessage()).thenReturn(null);
+        when(deviceInfo.reserveXidForDeviceMessage()).thenReturn(null);
         assertEquals(rpcContext.createRequestContext(),null);
     }