Bump upstreams
[lispflowmapping.git] / mappingservice / southbound / src / test / java / org / opendaylight / lispflowmapping / southbound / LispSouthboundPluginTest.java
index 546bde404baebadfa4164153cdfda77f536cbc50..3b0a7ab329c2dd42c3e0dbc45ec0fe91a3c4fb42 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
 import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.DatagramPacket;
@@ -23,14 +24,14 @@ import java.net.UnknownHostException;
 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.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
+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;
@@ -38,13 +39,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev16
 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.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLispSbService;
-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;
@@ -64,20 +60,21 @@ public class LispSouthboundPluginTest {
     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));
-        lispSouthboundPlugin.setBindingAddress(ADDRESS_1);
-        lispSouthboundPlugin.setMapRegisterCacheEnabled(false);
-        channel = PowerMockito.mock(NioDatagramChannel.class);
-        xtrChannel = PowerMockito.mock(NioDatagramChannel.class);
+                Mockito.mock(NotificationPublishService.class),
+                Mockito.mock(ClusterSingletonServiceProvider.class),
+                ADDRESS_1, false, 0);
+
+        channel = Mockito.mock(NioDatagramChannel.class);
+        xtrChannel = Mockito.mock(NioDatagramChannel.class);
         injectChannel();
         injectXtrChannel();
     }
@@ -146,8 +143,8 @@ public class LispSouthboundPluginTest {
         injectField("bootstrap", BOOTSTRAP_MOCK);
         lispSouthboundPlugin.setLispAddress(ADDRESS_1);
 
-        Mockito.verifyZeroInteractions(BOOTSTRAP_MOCK);
-        Mockito.verifyZeroInteractions(channel);
+        Mockito.verifyNoInteractions(BOOTSTRAP_MOCK);
+        Mockito.verifyNoInteractions(channel);
     }
 
     /**
@@ -167,7 +164,7 @@ public class LispSouthboundPluginTest {
     public void shouldListenOnXtrPortTest_false() throws NoSuchFieldException, IllegalAccessException {
         lispSouthboundPlugin.shouldListenOnXtrPort(false);
 
-        Mockito.verifyZeroInteractions(xtrChannel);
+        Mockito.verifyNoInteractions(xtrChannel);
     }
 
     /**
@@ -186,14 +183,11 @@ public class LispSouthboundPluginTest {
      * Tests {@link LispSouthboundPlugin#close} method.
      */
     @Test
-    @SuppressWarnings("unchecked")
     public void closeTest() throws Exception {
         EventLoopGroup elgMock = Mockito.mock(EventLoopGroup.class);
         LispSouthboundPluginTest.injectField("eventLoopGroup", elgMock);
-
-        BindingAwareBroker.RpcRegistration<OdlLispSbService> registrationMock =
-                Mockito.mock(BindingAwareBroker.RpcRegistration.class);
-        LispSouthboundPluginTest.injectField("sbRpcRegistration", registrationMock);
+        DataStoreBackEnd dsbeMock = Mockito.mock(DataStoreBackEnd.class);
+        LispSouthboundPluginTest.injectField("dsbe", dsbeMock);
 
         LispSouthboundHandler handlerMock = Mockito.mock(LispSouthboundHandler.class);
         LispSouthboundPluginTest.injectField("lispSouthboundHandler", handlerMock);
@@ -203,17 +197,16 @@ public class LispSouthboundPluginTest {
 
         Mockito.verify(channel).close();
         Mockito.verify(elgMock).shutdownGracefully();
-        Mockito.verify(registrationMock).close();
         Mockito.verify(handlerMock).close();
         assertNull(getField("lispSouthboundHandler"));
-        assertNull(getField("lispXtrSouthboundHandler"));
-        assertNull(getField("channel"));
+        Channel[] channels = getField("channel");
+        assertNull(channels[0]);
     }
 
     private static void injectChannel() throws NoSuchFieldException, IllegalAccessException {
         final Field channelField = LispSouthboundPlugin.class.getDeclaredField("channel");
         channelField.setAccessible(true);
-        channelField.set(lispSouthboundPlugin, channel);
+        channelField.set(lispSouthboundPlugin, new Channel[] { channel });
     }
 
     private static void injectXtrChannel() throws NoSuchFieldException, IllegalAccessException {
@@ -222,7 +215,7 @@ public class LispSouthboundPluginTest {
         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) {
@@ -232,14 +225,15 @@ public class LispSouthboundPluginTest {
         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);