import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.binding.dom.adapter.AdapterContext;
import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTestCustomizer;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class BmpMonitorImplTest extends AbstractConcurrentDataBrokerTest {
// the local port and address where the monitor (ODL) will listen for incoming BMP request
private static final int MONITOR_LOCAL_PORT = 12345;
public void setUp() throws Exception {
super.setup();
- MockitoAnnotations.initMocks(this);
-
doAnswer(invocationOnMock -> {
BmpMonitorImplTest.this.singletonService = (ClusterSingletonService) invocationOnMock.getArguments()[0];
- this.singletonService.instantiateServiceInstance();
+ singletonService.instantiateServiceInstance();
return BmpMonitorImplTest.this.singletonServiceRegistration;
- }).when(this.clusterSSProv).registerClusterSingletonService(any(ClusterSingletonService.class));
+ }).when(clusterSSProv).registerClusterSingletonService(any(ClusterSingletonService.class));
doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService.closeServiceInstance())
- .when(this.singletonServiceRegistration).close();
+ .when(singletonServiceRegistration).close();
doAnswer(invocationOnMock -> {
- this.singletonService2 = (ClusterSingletonService) invocationOnMock.getArguments()[0];
- this.singletonService2.instantiateServiceInstance();
+ singletonService2 = (ClusterSingletonService) invocationOnMock.getArguments()[0];
+ singletonService2.instantiateServiceInstance();
return BmpMonitorImplTest.this.singletonServiceRegistration2;
- }).when(this.clusterSSProv2).registerClusterSingletonService(any(ClusterSingletonService.class));
+ }).when(clusterSSProv2).registerClusterSingletonService(any(ClusterSingletonService.class));
doAnswer(invocationOnMock -> BmpMonitorImplTest.this.singletonService2.closeServiceInstance())
- .when(this.singletonServiceRegistration2).close();
+ .when(singletonServiceRegistration2).close();
- this.ribActivator.startRIBExtensionProvider(this.ribExtension, this.mappingService.currentSerializer());
+ ribActivator.startRIBExtensionProvider(ribExtension, mappingService.currentSerializer());
final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
- this.bgpActivator.start(context);
+ bgpActivator.start(context);
final SimpleBmpExtensionProviderContext ctx = new SimpleBmpExtensionProviderContext();
- this.bmpActivator = new BmpActivator(context);
- this.bmpActivator.start(ctx);
- this.msgRegistry = ctx.getBmpMessageRegistry();
+ bmpActivator = new BmpActivator(context);
+ bmpActivator.start(ctx);
+ msgRegistry = ctx.getBmpMessageRegistry();
- this.dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx,
+ dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx,
new DefaultBmpSessionFactory());
final InetSocketAddress inetAddress = new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS),
wTx.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of(BmpMonitor.QNAME), parentNode);
wTx.commit().get();
- this.bmpApp = new BmpMonitoringStationImpl(getDomBroker(), this.dispatcher, this.ribExtension,
- this.mappingService.currentSerializer(), this.clusterSSProv, MONITOR_ID, inetAddress, null);
+ bmpApp = new BmpMonitoringStationImpl(getDomBroker(), dispatcher, ribExtension,
+ mappingService.currentSerializer(), clusterSSProv, MONITOR_ID, inetAddress, null);
readDataOperational(getDataBroker(), BMP_II, monitor -> {
assertEquals(1, monitor.nonnullMonitor().size());
final Monitor bmpMonitor = monitor.nonnullMonitor().values().iterator().next();
@Override
protected final AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
final AbstractDataBrokerTestCustomizer customizer = super.createDataBrokerTestCustomizer();
- this.mappingService = customizer.getAdapterContext();
+ mappingService = customizer.getAdapterContext();
return customizer;
}
@After
public void tearDown() throws Exception {
- this.dispatcher.close();
- this.bmpApp.close();
+ dispatcher.close();
+ bmpApp.close();
checkNotPresentOperational(getDataBroker(), BMP_II);
}
// initiate another BMP request from router 1, create a redundant connection
// we expect the connection to be closed
- final Channel channel3 = connectTestClient(REMOTE_ROUTER_ADDRESS_1, this.msgRegistry);
+ final Channel channel3 = connectTestClient(REMOTE_ROUTER_ADDRESS_1, msgRegistry);
// channel 1 should still be open, while channel3 should be closed
private Channel testMonitoringStation(final String remoteRouterIpAddr) throws InterruptedException,
ExecutionException {
- final Channel channel = connectTestClient(remoteRouterIpAddr, this.msgRegistry);
+ final Channel channel = connectTestClient(remoteRouterIpAddr, msgRegistry);
final RouterId routerId = getRouterId(remoteRouterIpAddr);
readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
@Test
public void deploySecondInstance() throws Exception {
- final BmpMonitoringStation monitoringStation2 = new BmpMonitoringStationImpl(getDomBroker(), this.dispatcher,
- this.ribExtension, this.mappingService.currentSerializer(), this.clusterSSProv2, new MonitorId("monitor2"),
+ final BmpMonitoringStation monitoringStation2 = new BmpMonitoringStationImpl(getDomBroker(), dispatcher,
+ ribExtension, mappingService.currentSerializer(), clusterSSProv2, new MonitorId("monitor2"),
new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS_2), MONITOR_LOCAL_PORT), null);
readDataOperational(getDataBroker(), BMP_II, monitor -> {
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
import org.opendaylight.protocol.bmp.spi.registry.SimpleBmpExtensionProviderContext;
import org.opendaylight.protocol.concepts.KeyMapping;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class BmpDispatcherImplTest {
-
private static final int PORT = 45678;
private static final InetSocketAddress CLIENT_REMOTE = new InetSocketAddress("127.0.0.10", PORT);
private static final InetSocketAddress SERVER = new InetSocketAddress("0.0.0.0", PORT);
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- doNothing().when(this.mockedSession).handlerRemoved(any(ChannelHandlerContext.class));
- doNothing().when(this.mockedSession).handlerAdded(any(ChannelHandlerContext.class));
- doNothing().when(this.mockedSession).channelRegistered(any(ChannelHandlerContext.class));
- doNothing().when(this.mockedSession).channelActive(any(ChannelHandlerContext.class));
- doNothing().when(this.mockedSession).channelInactive(any(ChannelHandlerContext.class));
- doNothing().when(this.mockedSession).channelUnregistered(any(ChannelHandlerContext.class));
- doNothing().when(this.mockedSession).channelReadComplete(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).handlerRemoved(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).handlerAdded(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).channelRegistered(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).channelActive(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).channelInactive(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).channelUnregistered(any(ChannelHandlerContext.class));
+ doNothing().when(mockedSession).channelReadComplete(any(ChannelHandlerContext.class));
- this.bgpActivator = new BGPActivator();
+ bgpActivator = new BGPActivator();
final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext();
- this.bgpActivator.start(context);
+ bgpActivator.start(context);
final SimpleBmpExtensionProviderContext ctx = new SimpleBmpExtensionProviderContext();
- this.bmpActivator = new BmpActivator(context);
- this.bmpActivator.start(ctx);
+ bmpActivator = new BmpActivator(context);
+ bmpActivator.start(ctx);
- this.dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
- ctx, (channel, sessionListenerFactory) -> BmpDispatcherImplTest.this.mockedSession);
+ dispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), ctx,
+ (channel, sessionListenerFactory) -> BmpDispatcherImplTest.this.mockedSession);
}
@After
public void tearDown() throws Exception {
- this.dispatcher.close();
+ dispatcher.close();
}
@Test
public void testCreateServer() throws Exception {
- final ChannelFuture futureServer = this.dispatcher.createServer(SERVER,
- this.mockedListenerFactory, KeyMapping.getKeyMapping());
+ final ChannelFuture futureServer = dispatcher.createServer(SERVER, mockedListenerFactory,
+ KeyMapping.getKeyMapping());
waitFutureSuccess(futureServer);
final Channel serverChannel = futureServer.channel();
checkEquals(() -> assertTrue(serverChannel.isActive()));
- final ChannelFuture futureClient = this.dispatcher.createClient(CLIENT_REMOTE,
- this.mockedListenerFactory, KeyMapping.getKeyMapping());
+ final ChannelFuture futureClient = dispatcher.createClient(CLIENT_REMOTE, mockedListenerFactory,
+ KeyMapping.getKeyMapping());
waitFutureSuccess(futureClient);
final Channel clientChannel = futureClient.channel();
checkEquals(() -> assertTrue(clientChannel.isActive()));
- verify(this.mockedSession, timeout(500).times(2)).handlerAdded(any(ChannelHandlerContext.class));
- verify(this.mockedSession, timeout(500).times(2)).channelRegistered(any(ChannelHandlerContext.class));
- verify(this.mockedSession, timeout(500).times(2)).channelActive(any(ChannelHandlerContext.class));
+ verify(mockedSession, timeout(500).times(2)).handlerAdded(any(ChannelHandlerContext.class));
+ verify(mockedSession, timeout(500).times(2)).channelRegistered(any(ChannelHandlerContext.class));
+ verify(mockedSession, timeout(500).times(2)).channelActive(any(ChannelHandlerContext.class));
waitFutureSuccess(clientChannel.close());
waitFutureSuccess(serverChannel.close());
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.protocol.bmp.impl.session;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.doReturn;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.protocol.bmp.api.BmpSession;
import org.opendaylight.protocol.bmp.parser.message.TestUtil;
import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.InitiationMessage;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class BmpSessionImplTest {
private BmpSession session;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- doReturn(null).when(this.mockedHandlerContext).channel();
- doReturn(null).when(this.mockedHandlerContext).fireChannelInactive();
- this.listener = new BmpTestSessionListener();
- this.session = new BmpSessionImpl(this.listener);
- this.channel = new EmbeddedChannel(this.session);
- assertTrue(this.listener.isUp());
+ listener = new BmpTestSessionListener();
+ session = new BmpSessionImpl(listener);
+ channel = new EmbeddedChannel(session);
+ assertTrue(listener.isUp());
}
@Test
public void testOnInitiate() {
- this.channel.writeInbound(createInitMsg());
- assertEquals(this.listener.getListMsg().size(), 1);
- this.channel.writeInbound(createInitMsg());
- assertEquals(this.listener.getListMsg().size(), 2);
+ channel.writeInbound(createInitMsg());
+ assertEquals(listener.getListMsg().size(), 1);
+ channel.writeInbound(createInitMsg());
+ assertEquals(listener.getListMsg().size(), 2);
}
@Test
public void testOnTerminationAfterInitiated() {
- this.channel.writeInbound(createInitMsg());
- assertEquals(this.listener.getListMsg().size(), 1);
- this.channel.writeInbound(TestUtil.createTerminationMsg());
- assertEquals(this.listener.getListMsg().size(), 1);
- assertFalse(this.listener.isUp());
+ channel.writeInbound(createInitMsg());
+ assertEquals(listener.getListMsg().size(), 1);
+ channel.writeInbound(TestUtil.createTerminationMsg());
+ assertEquals(listener.getListMsg().size(), 1);
+ assertFalse(listener.isUp());
}
@Test
public void testOnTermination() {
- this.channel.writeInbound(TestUtil.createTerminationMsg());
- assertEquals(this.listener.getListMsg().size(), 0);
- assertFalse(this.listener.isUp());
+ channel.writeInbound(TestUtil.createTerminationMsg());
+ assertEquals(listener.getListMsg().size(), 0);
+ assertFalse(listener.isUp());
}
@Test
public void testOnUnexpectedMessage() {
- this.channel.writeInbound(TestUtil.createPeerDownFSM());
- assertEquals(this.listener.getListMsg().size(), 0);
- assertFalse(this.listener.isUp());
+ channel.writeInbound(TestUtil.createPeerDownFSM());
+ assertEquals(listener.getListMsg().size(), 0);
+ assertFalse(listener.isUp());
}
@Test
public void testExceptionCaught() throws Exception {
- this.session.exceptionCaught(this.mockedHandlerContext, new BmpDeserializationException(""));
- assertEquals(this.listener.getListMsg().size(), 0);
- assertFalse(this.listener.isUp());
+ session.exceptionCaught(mockedHandlerContext, new BmpDeserializationException(""));
+ assertEquals(listener.getListMsg().size(), 0);
+ assertFalse(listener.isUp());
}
-
}