Merge "GetFlowNodeCache cli"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / RpcContextImplTest.java
index 5fdaa36c2cbeb4a73215e3a48e8856d84f81a547..8a537c1a341fe30e3aff9db4cf0c492f55e521f7 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -10,31 +10,34 @@ 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.ArgumentMatchers.anySet;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import com.google.common.collect.ImmutableSet;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 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.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupCacheManager;
 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;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
@@ -45,21 +48,19 @@ public class RpcContextImplTest {
     private static final int MAX_REQUESTS = 5;
     private RpcContextImpl rpcContext;
 
-
     @Mock
-    private BindingAwareBroker.ProviderContext rpcProviderRegistry;
+    private FlowGroupCacheManager flowGroupCacheManager;
     @Mock
-    private DeviceState deviceState;
+    private RpcProviderService rpcProviderRegistry;
     @Mock
-    private XidSequencer xidSequencer;
+    private DeviceState deviceState;
     @Mock
     private MessageSpy messageSpy;
     @Mock
     private DeviceContext deviceContext;
     @Mock
-    private BindingAwareBroker.RoutedRpcRegistration<TestRpcService> routedRpcReg;
+    private ObjectRegistration<TestRpcService> routedRpcReg;
 
-    private Class<TestRpcService> serviceClass;
     @Mock
     private NotificationPublishService notificationPublishService;
     @Mock
@@ -78,7 +79,6 @@ 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);
@@ -90,49 +90,49 @@ public class RpcContextImplTest {
                 deviceContext,
                 extensionConverterProvider,
                 convertorExecutor,
-                notificationPublishService, true);
-
-        when(rpcProviderRegistry.addRoutedRpcImplementation(TestRpcService.class, serviceInstance)).thenReturn(routedRpcReg);
+                notificationPublishService, true, flowGroupCacheManager);
 
+        when(rpcProviderRegistry.registerRpcImplementation(eq(TestRpcService.class), eq(serviceInstance), anySet()))
+                .thenReturn(routedRpcReg);
     }
 
     @Test
-    public void testStoreOrFail() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(
+    public void testStoreOrFail() {
+        try (RpcContext rpcContext = new RpcContextImpl(
                 rpcProviderRegistry,
                 100,
                 deviceContext,
                 extensionConverterProvider,
                 convertorExecutor,
-                notificationPublishService, true)){
+                notificationPublishService, true, flowGroupCacheManager)) {
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNotNull(requestContext);
         }
     }
 
     @Test
-    public void testStoreOrFailThatFails() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(
+    public void testStoreOrFailThatFails() {
+        try (RpcContext rpcContext = new RpcContextImpl(
                 rpcProviderRegistry,
                 0,
                 deviceContext,
                 extensionConverterProvider,
                 convertorExecutor,
-                notificationPublishService, true)){
+                notificationPublishService, true, flowGroupCacheManager)) {
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNull(requestContext);
         }
     }
 
     @Test
-    public void testStoreAndCloseOrFail() throws Exception {
-        try (final RpcContext rpcContext = new RpcContextImpl(
+    public void testStoreAndCloseOrFail() {
+        try (RpcContext rpcContext = new RpcContextImpl(
                 rpcProviderRegistry,
                 100,
                 deviceContext,
                 extensionConverterProvider,
                 convertorExecutor,
-                notificationPublishService, true)){
+                notificationPublishService, true, flowGroupCacheManager)) {
             final RequestContext<?> requestContext = rpcContext.createRequestContext();
             assertNotNull(requestContext);
             requestContext.close();
@@ -142,12 +142,11 @@ public class RpcContextImplTest {
 
     public void testRegisterRpcServiceImplementation() {
         rpcContext.registerRpcServiceImplementation(TestRpcService.class, serviceInstance);
-        verify(rpcProviderRegistry, Mockito.times(1)).addRoutedRpcImplementation(TestRpcService.class,serviceInstance);
-        verify(routedRpcReg,Mockito.times(1)).registerPath(NodeContext.class,nodeInstanceIdentifier);
+        verify(rpcProviderRegistry, Mockito.times(1)).registerRpcImplementation(TestRpcService.class, serviceInstance,
+            ImmutableSet.of(nodeInstanceIdentifier));
         assertEquals(rpcContext.isEmptyRpcRegistrations(), false);
     }
 
-
     @Test
     public void testLookupRpcService() {
         when(routedRpcReg.getInstance()).thenReturn(serviceInstance);
@@ -158,30 +157,27 @@ public class RpcContextImplTest {
 
     @Test
     public void testClose() {
-        serviceClass = TestRpcService.class;
-        when(routedRpcReg.getServiceType()).thenReturn(serviceClass);
+        when(routedRpcReg.getInstance()).thenReturn(serviceInstance);
         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 {
+    public void testCreateRequestContext1() {
         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 {
+    public void testCreateRequestContext2() {
         RequestContext temp = rpcContext.createRequestContext();
         temp.close();
         verify(messageSpy).spyMessage(RpcContextImpl.class, MessageSpy.StatisticsGroup.REQUEST_STACK_FREED);
@@ -195,6 +191,8 @@ public class RpcContextImplTest {
         assertEquals(rpcContext.isEmptyRpcRegistrations(), true);
     }
 
-    //Stub for RpcService class
-    public class TestRpcService implements RpcService {}
+    //Stub for RpcService class.
+    public class TestRpcService implements RpcService {
+
+    }
 }