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;
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;
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);
}
/**
- * 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();
}
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());
}
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());
}