Bug 5596 Cleaning part 1
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / LifecycleConductorImplTest.java
index c089672c304148cc060c3a9aa82730faa7f124c8..723cb79723a2cb5ee74f1ba8a83f4ce2bbb66456 100644 (file)
@@ -27,6 +27,7 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.openflowplugin.api.openflow.OFPContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
@@ -38,6 +39,8 @@ import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
 import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
 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;
@@ -87,30 +90,28 @@ public class LifecycleConductorImplTest {
 
     private NodeId nodeId = new NodeId("openflow-junit:1");
     private OfpRole ofpRole = OfpRole.NOCHANGE;
-    private long delay = 42;
+    private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
 
     @Before
     public void setUp() {
-        final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
+        nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
+        final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
 
-        lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency);
+        lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency, convertorManager);
         lifecycleConductor.setSafelyManager(deviceManager);
         lifecycleConductor.setSafelyManager(statisticsManager);
         lifecycleConductor.setSafelyManager(rpcManager);
 
-        when(deviceManager.gainContext(Mockito.<DeviceInfo>any())).thenReturn(deviceContext);
+        when(deviceManager.gainContext(Mockito.any())).thenReturn(deviceContext);
         when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
         when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
-        when(rpcManager.gainContext(Mockito.<DeviceInfo>any())).thenReturn(rpcContext);
+        when(rpcManager.gainContext(Mockito.any())).thenReturn(rpcContext);
         when(deviceInfo.getNodeId()).thenReturn(nodeId);
         when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
         when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
         when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
-        when(rpcManager.gainContext(Mockito.<DeviceInfo>any())).thenReturn(rpcContext);
     }
 
-
-
     @Test
     public void addOneTimeListenerWhenServicesChangesDoneTest() {
         lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
@@ -161,35 +162,14 @@ public class LifecycleConductorImplTest {
     }
 
     /**
-     * When getDeviceContext returns null nothing should happen
+     * When getDeviceContext returns null raise exception
      */
-    @Test
+    @Test(expected = NullPointerException.class)
     public void roleChangeOnDeviceTest1() {
         when(deviceManager.gainContext(deviceInfo)).thenReturn(null);
-        lifecycleConductor.roleChangeOnDevice(deviceInfo,true,ofpRole,false);
+        lifecycleConductor.roleChangeOnDevice(deviceInfo,ofpRole);
         verify(deviceContext,times(0)).shutdownConnection();
-        lifecycleConductor.roleChangeOnDevice(deviceInfo,false,ofpRole,false);
-        verify(deviceContext,times(0)).shutdownConnection();
-    }
-
-    /**
-     * When success flag is set to FALSE connection should be closed
-     */
-    @Test
-    public void roleChangeOnDeviceTest2() {
-        when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
-        lifecycleConductor.roleChangeOnDevice(deviceInfo,false,ofpRole,false);
-        verify(deviceContext,times(1)).shutdownConnection();
-    }
-
-    /**
-     * When success flag is set to TRUE and initializationPahse flag is set to TRUE starting
-     * device should be skipped
-     */
-    @Test
-    public void roleChangeOnDeviceTest3() {
-        when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
-        lifecycleConductor.roleChangeOnDevice(deviceInfo,true,ofpRole,true);
+        lifecycleConductor.roleChangeOnDevice(deviceInfo,ofpRole);
         verify(deviceContext,times(0)).shutdownConnection();
     }
 
@@ -201,10 +181,9 @@ public class LifecycleConductorImplTest {
         final DataBroker dataBroker = mock(DataBroker.class);
 
         when(deviceContext.getDeviceState()).thenReturn(deviceState);
-        when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
+        when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker, nodeInstanceIdentifier));
         when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
-        when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
-        lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMEMASTER,false);
+        lifecycleConductor.roleChangeOnDevice(deviceInfo,OfpRole.BECOMEMASTER);
         verify(statisticsManager).startScheduling(Mockito.<DeviceInfo>any());
     }
 
@@ -216,11 +195,10 @@ public class LifecycleConductorImplTest {
         final DataBroker dataBroker = mock(DataBroker.class);
 
         when(deviceContext.getDeviceState()).thenReturn(deviceState);
-        when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker));
+        when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker, nodeInstanceIdentifier));
         when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
-        when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
 
-        lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMESLAVE,false);
+        lifecycleConductor.roleChangeOnDevice(deviceInfo,OfpRole.BECOMESLAVE);
         verify(statisticsManager).stopScheduling(Mockito.<DeviceInfo>any());
     }