X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2FLifecycleConductorImplTest.java;h=723cb79723a2cb5ee74f1ba8a83f4ce2bbb66456;hb=d8cc382a8dbdcb7c89b68457b3ae0b6d576ee28f;hp=39d4e4c917c279e9819fa23bac850d7777636226;hpb=4c10625cca87be09b9c6aa8056a0e4d6ba0f914d;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java index 39d4e4c917..723cb79723 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java @@ -9,6 +9,7 @@ package org.opendaylight.openflowplugin.impl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -25,6 +26,8 @@ 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.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; @@ -35,9 +38,17 @@ import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; 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; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @RunWith(MockitoJUnitRunner.class) public class LifecycleConductorImplTest { @@ -79,28 +90,28 @@ public class LifecycleConductorImplTest { private NodeId nodeId = new NodeId("openflow-junit:1"); private OfpRole ofpRole = OfpRole.NOCHANGE; - private long delay = 42; + private KeyedInstanceIdentifier nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId)); @Before public void setUp() { + 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.any())).thenReturn(deviceContext); + when(deviceManager.gainContext(Mockito.any())).thenReturn(deviceContext); when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); - when(rpcManager.gainContext(Mockito.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.any())).thenReturn(rpcContext); } - - @Test public void addOneTimeListenerWhenServicesChangesDoneTest() { lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo); @@ -151,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(); } @@ -188,10 +178,12 @@ public class LifecycleConductorImplTest { */ @Test public void roleChangeOnDeviceTest4() { + final DataBroker dataBroker = mock(DataBroker.class); + when(deviceContext.getDeviceState()).thenReturn(deviceState); + 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.any()); } @@ -200,10 +192,13 @@ public class LifecycleConductorImplTest { */ @Test public void roleChangeOnDeviceTest5() { + final DataBroker dataBroker = mock(DataBroker.class); + when(deviceContext.getDeviceState()).thenReturn(deviceState); + 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.any()); }