Bump upstreams
[lispflowmapping.git] / mappingservice / southbound / src / test / java / org / opendaylight / lispflowmapping / southbound / LispSouthboundPluginTest.java
index e77df27fe6b4c0f06a9a448ce66f4056f96caf52..3b0a7ab329c2dd42c3e0dbc45ec0fe91a3c4fb42 100644 (file)
@@ -24,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.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;
@@ -39,12 +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.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,22 +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),
-                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();
     }
@@ -148,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);
     }
 
     /**
@@ -169,7 +164,7 @@ public class LispSouthboundPluginTest {
     public void shouldListenOnXtrPortTest_false() throws NoSuchFieldException, IllegalAccessException {
         lispSouthboundPlugin.shouldListenOnXtrPort(false);
 
-        Mockito.verifyZeroInteractions(xtrChannel);
+        Mockito.verifyNoInteractions(xtrChannel);
     }
 
     /**
@@ -188,10 +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);
+        DataStoreBackEnd dsbeMock = Mockito.mock(DataStoreBackEnd.class);
+        LispSouthboundPluginTest.injectField("dsbe", dsbeMock);
 
         LispSouthboundHandler handlerMock = Mockito.mock(LispSouthboundHandler.class);
         LispSouthboundPluginTest.injectField("lispSouthboundHandler", handlerMock);
@@ -203,9 +199,8 @@ public class LispSouthboundPluginTest {
         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 {
@@ -220,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) {
@@ -230,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);