import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.HashedWheelTimer;
import io.netty.util.TimerTask;
+
+import java.math.BigInteger;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
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.lifecycle.ServiceChangeListener;
+import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
+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.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
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 java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-
@RunWith(MockitoJUnitRunner.class)
public class LifecycleConductorImplTest {
@Mock
private ServiceChangeListener serviceChangeListener;
@Mock
- private ConcurrentHashMap<NodeId, ServiceChangeListener> serviceChangeListeners;
+ private ConcurrentHashMap<DeviceInfo, ServiceChangeListener> serviceChangeListeners;
@Mock
private DeviceContext deviceContext;
@Mock
private ListenableFuture<Void> listenableFuture;
@Mock
private StatisticsManager statisticsManager;
+ @Mock
+ private RpcManager rpcManager;
+ @Mock
+ private RpcContext rpcContext;
+ @Mock
+ private DeviceInfo deviceInfo;
private NodeId nodeId = new NodeId("openflow-junit:1");
private OfpRole ofpRole = OfpRole.NOCHANGE;
@Before
public void setUp() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency);
- lifecycleConductor.setSafelyDeviceManager(deviceManager);
- lifecycleConductor.setSafelyStatisticsManager(statisticsManager);
+ lifecycleConductor.setSafelyManager(deviceManager);
+ lifecycleConductor.setSafelyManager(statisticsManager);
+ lifecycleConductor.setSafelyManager(rpcManager);
when(connectionContext.getFeatures()).thenReturn(featuresReply);
+ when(deviceInfo.getNodeId()).thenReturn(nodeId);
+ when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
+ when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+ when(rpcManager.gainContext(Mockito.<DeviceInfo>any())).thenReturn(rpcContext);
}
@Test
public void addOneTimeListenerWhenServicesChangesDoneTest() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
assertEquals(false,lifecycleConductor.isServiceChangeListenersEmpty());
}
*/
@Test
public void notifyServiceChangeListenersTest1() {
- lifecycleConductor.notifyServiceChangeListeners(nodeId,true);
+ lifecycleConductor.notifyServiceChangeListeners(deviceInfo,true);
when(serviceChangeListeners.size()).thenReturn(0);
- verify(serviceChangeListeners,times(0)).remove(nodeId);
+ verify(serviceChangeListeners,times(0)).remove(deviceInfo);
}
/**
*/
@Test
public void notifyServiceChangeListenersTest2() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
assertEquals(false,lifecycleConductor.isServiceChangeListenersEmpty());
- lifecycleConductor.notifyServiceChangeListeners(nodeId,true);
+ lifecycleConductor.notifyServiceChangeListeners(deviceInfo,true);
assertEquals(true,lifecycleConductor.isServiceChangeListenersEmpty());
}
*/
@Test
public void roleInitializationDoneTest1() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
- lifecycleConductor.roleInitializationDone(nodeId,false);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
+ lifecycleConductor.roleInitializationDone(deviceInfo,false);
verify(deviceContext,times(1)).shutdownConnection();
}
*/
@Test
public void roleInitializationDoneTest2() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
- lifecycleConductor.roleInitializationDone(nodeId,true);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
+ lifecycleConductor.roleInitializationDone(deviceInfo,true);
verify(deviceContext,times(0)).shutdownConnection();
}
*/
@Test
public void roleChangeOnDeviceTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,ofpRole,false);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,ofpRole,false);
verify(deviceContext,times(0)).shutdownConnection();
- lifecycleConductor.roleChangeOnDevice(nodeId,false,ofpRole,false);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,false,ofpRole,false);
verify(deviceContext,times(0)).shutdownConnection();
}
*/
@Test
public void roleChangeOnDeviceTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.roleChangeOnDevice(nodeId,false,ofpRole,false);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,false,ofpRole,false);
verify(deviceContext,times(1)).shutdownConnection();
}
*/
@Test
public void roleChangeOnDeviceTest3() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,ofpRole,true);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,ofpRole,true);
verify(deviceContext,times(0)).shutdownConnection();
}
@Test
public void roleChangeOnDeviceTest4() {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- when(deviceContext.onClusterRoleChange(null, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,OfpRole.BECOMEMASTER,false);
- verify(statisticsManager).startScheduling(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ when(deviceContext.onClusterRoleChange(OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMEMASTER,false);
+ verify(statisticsManager).startScheduling(Mockito.<DeviceInfo>any());
}
/**
@Test
public void roleChangeOnDeviceTest5() {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- when(deviceContext.onClusterRoleChange(null, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,OfpRole.BECOMESLAVE,false);
- verify(statisticsManager).stopScheduling(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ when(deviceContext.onClusterRoleChange(OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMESLAVE,false);
+ verify(statisticsManager).stopScheduling(Mockito.<DeviceInfo>any());
}
/**
*/
@Test
public void gainVersionSafelyTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- assertNull(lifecycleConductor.gainVersionSafely(nodeId));
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ assertNull(lifecycleConductor.gainVersionSafely(deviceInfo));
}
/**
*/
@Test
public void gainVersionSafelyTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.gainVersionSafely(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.gainVersionSafely(deviceInfo);
verify(deviceContext,times(1)).getPrimaryConnectionContext();
}
*/
@Test
public void gainConnectionStateSafelyTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- assertNull(lifecycleConductor.gainConnectionStateSafely(nodeId));
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ assertNull(lifecycleConductor.gainConnectionStateSafely(deviceInfo));
}
/**
*/
@Test
public void gainConnectionStateSafelyTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.gainConnectionStateSafely(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.gainConnectionStateSafely(deviceInfo);
verify(deviceContext,times(1)).getPrimaryConnectionContext();
}
*/
@Test
public void reserveXidForDeviceMessageTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- assertNull(lifecycleConductor.reserveXidForDeviceMessage(nodeId));
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ assertNull(lifecycleConductor.reserveXidForDeviceMessage(deviceInfo));
}
/**
*/
@Test
public void reserveXidForDeviceMessageTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.reserveXidForDeviceMessage(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.reserveXidForDeviceMessage(deviceInfo);
verify(deviceContext,times(1)).reserveXidForDeviceMessage();
}
*/
@Test
public void deviceStartInitializationDoneTest() {
- lifecycleConductor.deviceStartInitializationDone(nodeId, false);
+ lifecycleConductor.deviceStartInitializationDone(deviceInfo, false);
verify(deviceContext,times(1)).shutdownConnection();
}
*/
@Test
public void deviceInitializationDoneTest() {
- lifecycleConductor.deviceInitializationDone(nodeId, false);
+ lifecycleConductor.deviceInitializationDone(deviceInfo, false);
verify(deviceContext,times(1)).shutdownConnection();
}
}