import java.nio.ByteBuffer;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.singleton.api.ClusterSingletonServiceProvider;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.Ipv4AddressBinary;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.opendaylight.yangtools.yang.common.Uint16;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(NioDatagramChannel.class)
public class LispSouthboundPluginTest {
private static NioDatagramChannel channel;
private static final IpAddressBinary IPV6_BINARY = new IpAddressBinary(new Ipv6AddressBinary(IPV6_BYTES));
private static final TransportAddress TRANSPORT_ADDRESS_IPV4 = new TransportAddressBuilder()
.setIpAddress(IPV4_BINARY)
- .setPort(new PortNumber(PORT)).build();
+ .setPort(new PortNumber(Uint16.valueOf(PORT))).build();
private static final TransportAddress TRANSPORT_ADDRESS_IPV6 = new TransportAddressBuilder()
.setIpAddress(IPV6_BINARY)
- .setPort(new PortNumber(PORT)).build();
+ .setPort(new PortNumber(Uint16.valueOf(PORT))).build();
@Before
public void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
lispSouthboundPlugin = new LispSouthboundPlugin(
Mockito.mock(DataBroker.class),
Mockito.mock(NotificationPublishService.class),
- Mockito.mock(ClusterSingletonServiceProvider.class));
- lispSouthboundPlugin.setBindingAddress(ADDRESS_1);
- lispSouthboundPlugin.setMapRegisterCacheEnabled(false);
+ Mockito.mock(ClusterSingletonServiceProvider.class),
+ ADDRESS_1, false, 0);
- channel = PowerMockito.mock(NioDatagramChannel.class);
- xtrChannel = PowerMockito.mock(NioDatagramChannel.class);
+ channel = Mockito.mock(NioDatagramChannel.class);
+ xtrChannel = Mockito.mock(NioDatagramChannel.class);
injectChannel();
injectXtrChannel();
}
injectField("bootstrap", BOOTSTRAP_MOCK);
lispSouthboundPlugin.setLispAddress(ADDRESS_1);
- Mockito.verifyZeroInteractions(BOOTSTRAP_MOCK);
- Mockito.verifyZeroInteractions(channel);
+ Mockito.verifyNoInteractions(BOOTSTRAP_MOCK);
+ Mockito.verifyNoInteractions(channel);
}
/**
public void shouldListenOnXtrPortTest_false() throws NoSuchFieldException, IllegalAccessException {
lispSouthboundPlugin.shouldListenOnXtrPort(false);
- Mockito.verifyZeroInteractions(xtrChannel);
+ Mockito.verifyNoInteractions(xtrChannel);
}
/**
* Tests {@link LispSouthboundPlugin#close} method.
*/
@Test
- @SuppressWarnings("unchecked")
public void closeTest() throws Exception {
EventLoopGroup elgMock = Mockito.mock(EventLoopGroup.class);
LispSouthboundPluginTest.injectField("eventLoopGroup", elgMock);
+ DataStoreBackEnd dsbeMock = Mockito.mock(DataStoreBackEnd.class);
+ LispSouthboundPluginTest.injectField("dsbe", dsbeMock);
LispSouthboundHandler handlerMock = Mockito.mock(LispSouthboundHandler.class);
LispSouthboundPluginTest.injectField("lispSouthboundHandler", handlerMock);
Mockito.verify(elgMock).shutdownGracefully();
Mockito.verify(handlerMock).close();
assertNull(getField("lispSouthboundHandler"));
- assertNull(getField("lispXtrSouthboundHandler"));
- Channel[] channel = getField("channel");
- assertNull(channel[0]);
+ Channel[] channels = getField("channel");
+ assertNull(channels[0]);
}
private static void injectChannel() throws NoSuchFieldException, IllegalAccessException {
xtrChannelField.set(lispSouthboundPlugin, xtrChannel);
}
- private static ByteBuffer parseHexString(String packet) {
+ private static ByteBuffer parseHexString(final String packet) {
final String[] tokens = packet.split("\\s+");
final ByteBuffer buffer = ByteBuffer.allocate(tokens.length);
for (String token : tokens) {
return buffer;
}
- private static <T> void injectField(String fieldName, T obj) throws NoSuchFieldException, IllegalAccessException {
+ private static <T> void injectField(final String fieldName, final T obj)
+ throws NoSuchFieldException, IllegalAccessException {
Field field = LispSouthboundPlugin.class.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(lispSouthboundPlugin, obj);
}
@SuppressWarnings("unchecked")
- private static <T> T getField(String fieldName) throws NoSuchFieldException, IllegalAccessException {
+ private static <T> T getField(final String fieldName) throws NoSuchFieldException, IllegalAccessException {
Field field = LispSouthboundPlugin.class.getDeclaredField(fieldName);
field.setAccessible(true);