Merge "Move empty match constant into OFConstants"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / rpc / RpcManagerImplTest.java
index 3a6ed63c5731d3b86ee95f4cd6c873ba38900a6a..415d443580ff2ec95fafa459a1c29e9437be2890 100644 (file)
@@ -7,7 +7,13 @@
  */
 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;
 import org.junit.Test;
@@ -22,6 +28,7 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderCo
 import org.opendaylight.openflowplugin.api.OFConstants;
 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;
@@ -35,17 +42,9 @@ 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.role.service.rev150727.OfpRole;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
-import java.util.concurrent.ConcurrentMap;
-
-import static org.mockito.Mockito.atLeastOnce;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
 
 @RunWith(MockitoJUnitRunner.class)
 public class RpcManagerImplTest {
@@ -78,7 +77,9 @@ public class RpcManagerImplTest {
     @Mock
     private RpcContext removedContexts;
     @Mock
-    private ConcurrentMap<NodeId, RpcContext> contexts;
+    private ConcurrentMap<DeviceInfo, RpcContext> contexts;
+    @Mock
+    private DeviceInfo deviceInfo;
 
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
@@ -102,64 +103,58 @@ public class RpcManagerImplTest {
         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
         Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
         Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
-        Mockito.when(deviceContext.getDeviceState().getRole()).thenReturn(OfpRole.BECOMEMASTER);
         Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
-        Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
-        Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput);
+        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);
         Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
-        Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
+        Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
         Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
-        Mockito.when(deviceState.getNodeId()).thenReturn(nodeKey.getId());
+        Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId());
         Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
                 Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
                 .thenReturn(routedRpcRegistration);
-        Mockito.when(conductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(deviceContext);
-        Mockito.when(contexts.remove(nodeId)).thenReturn(removedContexts);
+        Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
+        Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts);
     }
 
     @Test
     public void onDeviceContextLevelUp() throws Exception {
-        rpcManager.onDeviceContextLevelUp(nodeId);
-        verify(conductor).getDeviceContext(Mockito.<NodeId>any());
+        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        verify(conductor).getDeviceContext(deviceInfo);
     }
 
     @Test
     public void onDeviceContextLevelUpTwice() throws Exception {
-        rpcManager.onDeviceContextLevelUp(nodeId);
+        rpcManager.onDeviceContextLevelUp(deviceInfo);
         expectedException.expect(VerifyException.class);
-        rpcManager.onDeviceContextLevelUp(nodeId);
+        rpcManager.onDeviceContextLevelUp(deviceInfo);
     }
 
     @Test
     public void testOnDeviceContextLevelUpMaster() throws Exception {
-        Mockito.when(deviceState.getRole()).thenReturn(OfpRole.BECOMEMASTER);
-        rpcManager.onDeviceContextLevelUp(nodeId);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(nodeId);
+        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo);
     }
 
     @Test
     public void testOnDeviceContextLevelUpSlave() throws Exception {
-        Mockito.when(deviceState.getRole()).thenReturn(OfpRole.BECOMESLAVE);
-        rpcManager.onDeviceContextLevelUp(nodeId);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(nodeId);
+        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo);
     }
 
     @Test
     public void testOnDeviceContextLevelUpOther() throws Exception {
-        Mockito.when(deviceState.getRole()).thenReturn(OfpRole.NOCHANGE);
-        rpcManager.onDeviceContextLevelUp(nodeId);
-        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(nodeId);
+        rpcManager.onDeviceContextLevelUp(deviceInfo);
+        verify(deviceINitializationPhaseHandler).onDeviceContextLevelUp(deviceInfo);
     }
 
     @Test
     public void testOnDeviceContextLevelDown() throws Exception {
-        Mockito.when(deviceState.getRole()).thenReturn(OfpRole.NOCHANGE);
-        rpcManager.onDeviceContextLevelDown(deviceContext);
-        verify(deviceTerminationPhaseHandler).onDeviceContextLevelDown(deviceContext);
+        rpcManager.onDeviceContextLevelDown(deviceInfo);
+        verify(deviceTerminationPhaseHandler).onDeviceContextLevelDown(deviceInfo);
     }
 
     /**
@@ -167,10 +162,10 @@ public class RpcManagerImplTest {
      */
     @Test
     public void onDeviceContextLevelDown1() {
-        rpcManager.addRecordToContexts(nodeId,removedContexts);
-        rpcManager.onDeviceContextLevelDown(deviceContext);
+        rpcManager.addRecordToContexts(deviceInfo,removedContexts);
+        rpcManager.onDeviceContextLevelDown(deviceInfo);
         verify(removedContexts,times(1)).close();
-        verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceContext);
+        verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceInfo);
     }
 
 
@@ -179,15 +174,15 @@ public class RpcManagerImplTest {
      */
     @Test
     public void onDeviceContextLevelDown2() {
-        rpcManager.onDeviceContextLevelDown(deviceContext);
+        rpcManager.onDeviceContextLevelDown(deviceInfo);
         verify(removedContexts,never()).close();
-        verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceContext);
+        verify(deviceTerminationPhaseHandler,times(1)).onDeviceContextLevelDown(deviceInfo);
 
     }
 
     @Test
     public void close() {
-        rpcManager.addRecordToContexts(nodeId,removedContexts);
+        rpcManager.addRecordToContexts(deviceInfo,removedContexts);
         rpcManager.close();
         verify(removedContexts,atLeastOnce()).close();
     }