X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Frole%2FRoleManagerImplTest.java;h=fe20b2e68e6f6681e2ef8bc7a7ee3da6b079a82d;hb=6e2627630ebabb37526133a13deeb62adcc85d35;hp=3febe5466ccd088dd1f7727ba3abffa370f0536e;hpb=52f1d136aff5568e9d9607e6a61e4ec128c962aa;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java index 3febe5466c..fe20b2e68e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java @@ -35,6 +35,7 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile 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.DeviceManager; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler; @@ -97,6 +98,13 @@ public class RoleManagerImplTest { @Mock DeviceState deviceState; + @Mock + DeviceInfo deviceInfo; + + @Mock + DeviceInfo deviceInfo2; + + @Mock GetFeaturesOutput featuresOutput; @@ -104,40 +112,46 @@ public class RoleManagerImplTest { private RoleManagerImpl roleManagerSpy; private RoleContext roleContextSpy; private final NodeId nodeId = NodeId.getDefaultInstance("openflow:1"); + private final NodeId nodeId2 = NodeId.getDefaultInstance("openflow:2"); + - private final EntityOwnershipChange masterEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), false, true, true); - private final EntityOwnershipChange masterTxEntity = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), false, true, true); - private final EntityOwnershipChange slaveEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true); - private final EntityOwnershipChange slaveTxEntityLast = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), true, false, false); - private final EntityOwnershipChange masterEntityNotOwner = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true); + private final EntityOwnershipChange masterEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), false, true, true, false); + private final EntityOwnershipChange masterTxEntity = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), false, true, true, false); + private final EntityOwnershipChange slaveEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true, false); + private final EntityOwnershipChange slaveTxEntityLast = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), true, false, false, false); + private final EntityOwnershipChange masterEntityNotOwner = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true, false); private InOrder inOrder; @Before public void setUp() throws Exception { CheckedFuture future = Futures.immediateCheckedFuture(null); - Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput); Mockito.when(entityOwnershipService.registerListener(Mockito.anyString(), Mockito.any(EntityOwnershipListener.class))).thenReturn(entityOwnershipListenerRegistration); Mockito.when(entityOwnershipService.registerCandidate(Mockito.any(Entity.class))).thenReturn(entityOwnershipCandidateRegistration); Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); + Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply); Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId); Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING); Mockito.when(featuresReply.getDatapathId()).thenReturn(new BigInteger("1")); Mockito.when(featuresReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); - Mockito.doNothing().when(deviceInitializationPhaseHandler).onDeviceContextLevelUp(Mockito.any()); - Mockito.doNothing().when(deviceTerminationPhaseHandler).onDeviceContextLevelDown(Mockito.any()); + Mockito.doNothing().when(deviceInitializationPhaseHandler).onDeviceContextLevelUp(Mockito.any()); + Mockito.doNothing().when(deviceTerminationPhaseHandler).onDeviceContextLevelDown(Mockito.any()); Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); Mockito.when(writeTransaction.submit()).thenReturn(future); - Mockito.when(deviceManager.getDeviceContextFromNodeId(Mockito.any())).thenReturn(deviceContext); + Mockito.when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext); + Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId); + Mockito.when(deviceInfo2.getNodeId()).thenReturn(nodeId2); + Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN); roleManager = new RoleManagerImpl(entityOwnershipService, dataBroker, conductor); roleManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler); roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler); - Mockito.when(conductor.getDeviceContext(Mockito.any())).thenReturn(deviceContext); + Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext); roleManagerSpy = Mockito.spy(roleManager); - roleManagerSpy.onDeviceContextLevelUp(nodeId); + roleManagerSpy.onDeviceContextLevelUp(deviceInfo); roleContextSpy = Mockito.spy(roleManager.getRoleContext(nodeId)); + Mockito.when(roleContextSpy.getDeviceInfo().getNodeId()).thenReturn(nodeId); inOrder = Mockito.inOrder(entityOwnershipListenerRegistration, roleManagerSpy, roleContextSpy); } @@ -147,8 +161,8 @@ public class RoleManagerImplTest { @Test(expected = VerifyException.class) public void testOnDeviceContextLevelUp() throws Exception { - roleManagerSpy.onDeviceContextLevelUp(nodeId); - inOrder.verify(roleManagerSpy).onDeviceContextLevelUp(nodeId); + roleManagerSpy.onDeviceContextLevelUp(deviceInfo); + inOrder.verify(roleManagerSpy).onDeviceContextLevelUp(deviceInfo); inOrder.verifyNoMoreInteractions(); } @@ -173,8 +187,8 @@ public class RoleManagerImplTest { @Test public void testOnDeviceContextLevelDown() throws Exception { - roleManagerSpy.onDeviceContextLevelDown(deviceContext); - inOrder.verify(roleManagerSpy).onDeviceContextLevelDown(deviceContext); + roleManagerSpy.onDeviceContextLevelDown(deviceInfo); + inOrder.verify(roleManagerSpy).onDeviceContextLevelDown(deviceInfo); inOrder.verifyNoMoreInteractions(); } @@ -234,8 +248,7 @@ public class RoleManagerImplTest { Mockito.when(roleContextSpy.isTxCandidateRegistered()).thenReturn(false); roleManagerSpy.changeOwnershipForTxEntity(slaveTxEntityLast, roleContextSpy); verify(roleContextSpy).close(); - verify(roleContextSpy).getNodeId(); - verify(conductor).closeConnection(nodeId); + verify(conductor).closeConnection(deviceInfo); } @Test @@ -243,50 +256,48 @@ public class RoleManagerImplTest { Mockito.when(roleContextSpy.isTxCandidateRegistered()).thenReturn(true); roleManagerSpy.changeOwnershipForTxEntity(masterEntityNotOwner, roleContextSpy); verify(roleContextSpy).close(); - verify(conductor).closeConnection(nodeId); + verify(conductor).closeConnection(deviceInfo); } @Test public void testAddListener() throws Exception { roleManager.addRoleChangeListener((new RoleChangeListener() { @Override - public void roleInitializationDone(final NodeId nodeId, final boolean success) { - Assert.assertTrue(nodeId.equals(nodeId)); + public void roleInitializationDone(final DeviceInfo deviceInfo_, final boolean success) { + Assert.assertTrue(deviceInfo.equals(deviceInfo_)); Assert.assertTrue(success); } @Override - public void roleChangeOnDevice(final NodeId nodeId_, final boolean success, final OfpRole newRole, final boolean initializationPhase) { - Assert.assertTrue(nodeId.equals(nodeId_)); + public void roleChangeOnDevice(final DeviceInfo deviceInfo_, final boolean success, final OfpRole newRole, final boolean initializationPhase) { + Assert.assertTrue(deviceInfo.equals(deviceInfo_)); Assert.assertTrue(success); Assert.assertFalse(initializationPhase); Assert.assertTrue(newRole.equals(OfpRole.BECOMEMASTER)); } })); - roleManager.notifyListenersRoleInitializationDone(nodeId, true); - roleManager.notifyListenersRoleChangeOnDevice(nodeId, true, OfpRole.BECOMEMASTER, false); + roleManager.notifyListenersRoleInitializationDone(deviceInfo, true); + roleManager.notifyListenersRoleChangeOnDevice(deviceInfo, true, OfpRole.BECOMEMASTER, false); } @Test public void testMakeDeviceRoleChange() throws Exception{ roleManagerSpy.makeDeviceRoleChange(OfpRole.BECOMEMASTER, roleContextSpy, true); verify(roleManagerSpy, atLeastOnce()).sendRoleChangeToDevice(Mockito.any(), Mockito.any()); - verify(roleManagerSpy, atLeastOnce()).notifyListenersRoleChangeOnDevice(Mockito.any(), eq(true), Mockito.any(), eq(true)); + verify(roleManagerSpy, atLeastOnce()).notifyListenersRoleChangeOnDevice(Mockito.any(), eq(true), Mockito.any(), eq(true)); } @Test public void testServicesChangeDone() throws Exception { - final NodeId nodeId2 = NodeId.getDefaultInstance("openflow:2"); roleManagerSpy.setRoleContext(nodeId2, roleContextSpy); - roleManagerSpy.servicesChangeDone(nodeId2, true); + roleManagerSpy.servicesChangeDone(deviceInfo2, true); verify(roleContextSpy).unregisterCandidate(Mockito.any()); } @Test public void testServicesChangeDoneContextIsNull() throws Exception { - final NodeId nodeId2 = NodeId.getDefaultInstance("openflow:2"); roleManagerSpy.setRoleContext(nodeId, roleContextSpy); - roleManagerSpy.servicesChangeDone(nodeId2, true); + roleManagerSpy.servicesChangeDone(deviceInfo2, true); verify(roleContextSpy, never()).unregisterCandidate(Mockito.any()); } } \ No newline at end of file