import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.api.openflow.connection.DeviceConnectionStatusProvider;
import org.opendaylight.openflowplugin.impl.connection.ConnectionContextImpl;
import org.opendaylight.openflowplugin.impl.util.ThreadPoolLoggingExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Testing basic bahavior of {@link SystemNotificationsListenerImpl}.
private ConnectionAdapter connectionAdapter;
@Mock
private FeaturesReply features;
+ @Mock
+ private DeviceConnectionStatusProvider deviceConnectionStatusProvider;
+ @Mock
+ private NotificationPublishService notificationPublishService;
private ConnectionContext connectionContext;
private ConnectionContextImpl connectionContextGolem;
@Before
public void setUp() {
- connectionContextGolem = new ConnectionContextImpl(connectionAdapter);
+ connectionContextGolem = new ConnectionContextImpl(connectionAdapter, deviceConnectionStatusProvider);
connectionContextGolem.changeStateToWorking();
connectionContextGolem.setNodeId(NODE_ID);
+ connectionContextGolem.setFeatures(features);
connectionContext = Mockito.spy(connectionContextGolem);
Mockito.when(connectionAdapter.getRemoteAddress()).thenReturn(
InetSocketAddress.createUnresolved("unit-odl.example.org", 4242));
- Mockito.when(features.getAuxiliaryId()).thenReturn((short) 0);
-
- Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
- Mockito.when(connectionContext.getFeatures()).thenReturn(features);
-
- systemNotificationsListener =
- new SystemNotificationsListenerImpl(connectionContext, ECHO_REPLY_TIMEOUT, threadPool);
+ Mockito.when(features.getAuxiliaryId()).thenReturn(Uint8.ZERO);
+ systemNotificationsListener = new SystemNotificationsListenerImpl(connectionContext, ECHO_REPLY_TIMEOUT,
+ threadPool, notificationPublishService);
}
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
Mockito.verifyNoMoreInteractions(connectionContext);
}
* Successful scenario - connection is on and closes without errors.
*/
@Test
- public void testOnDisconnectEvent1() throws Exception {
+ public void testOnDisconnectEvent1() {
DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
systemNotificationsListener.onDisconnectEvent(disconnectNotification);
* Broken scenario - connection is on but fails to close.
*/
@Test
- public void testOnDisconnectEvent2() throws Exception {
+ public void testOnDisconnectEvent2() {
DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
systemNotificationsListener.onDisconnectEvent(disconnectNotification);
* Successful scenario - connection is already down.
*/
@Test
- public void testOnDisconnectEvent3() throws Exception {
+ public void testOnDisconnectEvent3() {
connectionContextGolem.changeStateToTimeouting();
DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
* Broken scenario - connection is on but throws error on close.
*/
@Test
- public void testOnDisconnectEvent4() throws Exception {
+ public void testOnDisconnectEvent4() {
Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.RIP);
DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
@Test
public void testOnSwitchIdleEvent1() throws Exception {
final ListenableFuture<RpcResult<EchoOutput>> echoReply =
- Futures.immediateFuture(RpcResultBuilder.success(new EchoOutputBuilder().setXid(0L).build()).build());
+ RpcResultBuilder.success(new EchoOutputBuilder().setXid(Uint32.ZERO).build()).buildFuture();
Mockito.when(connectionAdapter.echo(any(EchoInput.class))).thenReturn(echoReply);
private void verifyCommonInvocations() {
verifyCommonInvocationsSubSet();
+ Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT).atLeastOnce()).getFeatures();
Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT).atLeastOnce()).getConnectionAdapter();
}
private void verifyCommonInvocationsSubSet() {
Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT).atLeastOnce()).getConnectionState();
- Mockito.verify(connectionContext, Mockito.timeout(SAFE_TIMEOUT).atLeastOnce()).getFeatures();
}
}