OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / RpcContextImplTest.java
index 08f97f5c619db89afb3ebca3ae17350dc5feddb5..9ca563094f6910460071d3b0c2524152ef12bc48 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -20,13 +21,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;
@@ -44,23 +47,26 @@ public class RpcContextImplTest {
 
 
     @Mock
-    private BindingAwareBroker.ProviderContext rpcProviderRegistry;
+    private RpcProviderRegistry rpcProviderRegistry;
     @Mock
     private DeviceState deviceState;
     @Mock
-    private DeviceInfo deviceInfo;
-    @Mock
-    private XidSequencer xidSequencer;
-    @Mock
     private MessageSpy messageSpy;
     @Mock
     private DeviceContext deviceContext;
     @Mock
-    private BindingAwareBroker.RoutedRpcRegistration routedRpcReg;
+    private BindingAwareBroker.RoutedRpcRegistration<TestRpcService> routedRpcReg;
+
     @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,20 +75,32 @@ public class RpcContextImplTest {
         final NodeId nodeId = new NodeId("openflow:1");
         nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
 
-        when(deviceContext.getDeviceState()).thenReturn(deviceState);
         when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
         when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
+        when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+        when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
 
-        rpcContext = new RpcContextImpl(rpcProviderRegistry,deviceContext, messageSpy, MAX_REQUESTS,nodeInstanceIdentifier);
-
-        when(rpcProviderRegistry.addRoutedRpcImplementation(TestRpcService.class, serviceInstance)).thenReturn(routedRpcReg);
+        rpcContext = new RpcContextImpl(
+                rpcProviderRegistry,
+                MAX_REQUESTS,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService, true);
 
+        when(rpcProviderRegistry.addRoutedRpcImplementation(TestRpcService.class, serviceInstance))
+                .thenReturn(routedRpcReg);
     }
 
     @Test
     public void testStoreOrFail() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
-                messageSpy, 100, nodeInstanceIdentifier)) {
+        try (RpcContext rpcContext = new RpcContextImpl(
+                rpcProviderRegistry,
+                100,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService, true)) {
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNotNull(requestContext);
         }
@@ -90,8 +108,13 @@ public class RpcContextImplTest {
 
     @Test
     public void testStoreOrFailThatFails() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
-                messageSpy, 0, nodeInstanceIdentifier)) {
+        try (RpcContext rpcContext = new RpcContextImpl(
+                rpcProviderRegistry,
+                0,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService, true)) {
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNull(requestContext);
         }
@@ -99,12 +122,17 @@ public class RpcContextImplTest {
 
     @Test
     public void testStoreAndCloseOrFail() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, deviceContext, messageSpy,
-                100, nodeInstanceIdentifier)) {
+        try (RpcContext rpcContext = new RpcContextImpl(
+                rpcProviderRegistry,
+                100,
+                deviceContext,
+                extensionConverterProvider,
+                convertorExecutor,
+                notificationPublishService, true)) {
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNotNull(requestContext);
             requestContext.close();
-            verify(messageSpy).spyMessage(RpcContextImpl.class, MessageSpy.STATISTIC_GROUP.REQUEST_STACK_FREED);
+            verify(messageSpy).spyMessage(RpcContextImpl.class, MessageSpy.StatisticsGroup.REQUEST_STACK_FREED);
         }
     }
 
@@ -115,7 +143,6 @@ public class RpcContextImplTest {
         assertEquals(rpcContext.isEmptyRpcRegistrations(), false);
     }
 
-
     @Test
     public void testLookupRpcService() {
         when(routedRpcReg.getInstance()).thenReturn(serviceInstance);
@@ -126,31 +153,31 @@ public class RpcContextImplTest {
 
     @Test
     public void testClose() {
+        Class<TestRpcService> serviceClass = TestRpcService.class;
+        when(routedRpcReg.getServiceType()).thenReturn(serviceClass);
         rpcContext.registerRpcServiceImplementation(TestRpcService.class, serviceInstance);
         rpcContext.close();
         assertEquals(rpcContext.isEmptyRpcRegistrations(), true);
     }
 
     /**
-     * When deviceContext.reserveXidForDeviceMessage returns null, null should be returned
-     * @throws InterruptedException
+     * When deviceContext.reserveXidForDeviceMessage returns null, null should be returned.
      */
     @Test
     public void testCreateRequestContext1() throws InterruptedException {
-        when(deviceContext.reserveXidForDeviceMessage()).thenReturn(null);
+        when(deviceInfo.reserveXidForDeviceMessage()).thenReturn(null);
         assertEquals(rpcContext.createRequestContext(),null);
     }
 
     /**
-     * When deviceContext.reserveXidForDeviceMessage returns value, AbstractRequestContext should be returned
-     * @throws InterruptedException
+     * When deviceContext.reserveXidForDeviceMessage returns value, AbstractRequestContext should be returned.
      */
 
     @Test
     public void testCreateRequestContext2() throws InterruptedException {
         RequestContext temp = rpcContext.createRequestContext();
         temp.close();
-        verify(messageSpy).spyMessage(RpcContextImpl.class,MessageSpy.STATISTIC_GROUP.REQUEST_STACK_FREED);
+        verify(messageSpy).spyMessage(RpcContextImpl.class, MessageSpy.StatisticsGroup.REQUEST_STACK_FREED);
     }
 
     @Test
@@ -161,6 +188,6 @@ public class RpcContextImplTest {
         assertEquals(rpcContext.isEmptyRpcRegistrations(), true);
     }
 
-    //Stub for RpcService class
+    //Stub for RpcService class.
     public class TestRpcService implements RpcService {}
 }