Bump upstream versions
[netconf.git] / netconf / netconf-impl / src / test / java / org / opendaylight / netconf / impl / NetconfServerSessionTest.java
index 6e3dc9e153d64c7079ab336aa4c6d2911223a766..9609dde637035e50bac99e12767bcffaaf4ee4dd 100644 (file)
@@ -5,11 +5,12 @@
  * 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.netconf.impl;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.verify;
 
@@ -17,11 +18,11 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.embedded.EmbeddedChannel;
-import org.junit.Assert;
 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.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.netconf.api.xml.XmlUtil;
@@ -38,14 +39,15 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.mon
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
 import org.w3c.dom.Document;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class NetconfServerSessionTest {
-
     private static final String HOST = "127.0.0.1";
     private static final String PORT = "17830";
     private static final String SSH_TRANSPORT = "ssh";
     private static final String TCP_TRANSPORT = "tcp";
     private static final String SESSION_ID = "1";
     private static final String USER = "admin";
+
     private NetconfServerSession session;
     private EmbeddedChannel channel;
     private NetconfMessage msg;
@@ -54,7 +56,6 @@ public class NetconfServerSessionTest {
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
         final NetconfHelloMessageAdditionalHeader header =
                 new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, SSH_TRANSPORT, SESSION_ID);
         channel = new EmbeddedChannel();
@@ -76,7 +77,7 @@ public class NetconfServerSessionTest {
         session.sendMessage(msg);
         channel.runPendingTasks();
         final Object o = channel.readOutbound();
-        Assert.assertEquals(msg, o);
+        assertEquals(msg, o);
         verify(listener).onSessionTerminated(eq(session), any());
     }
 
@@ -85,7 +86,7 @@ public class NetconfServerSessionTest {
         session.sendMessage(msg);
         channel.runPendingTasks();
         final Object o = channel.readOutbound();
-        Assert.assertEquals(msg, o);
+        assertEquals(msg, o);
     }
 
     @Test
@@ -96,37 +97,37 @@ public class NetconfServerSessionTest {
         session.sendMessage(notif);
         channel.runPendingTasks();
         final Object o = channel.readOutbound();
-        Assert.assertEquals(notif, o);
+        assertEquals(notif, o);
         verify(listener).onNotification(session, notif);
     }
 
     @Test
     public void testOnIncommingRpcSuccess() throws Exception {
         session.sessionUp();
-        final Session managementSession = this.session.toManagementSession();
-        this.session.onIncommingRpcSuccess();
-        final Session afterRpcSuccess = this.session.toManagementSession();
-        Assert.assertEquals(managementSession.getInRpcs().getValue() + 1,
+        final Session managementSession = session.toManagementSession();
+        session.onIncommingRpcSuccess();
+        final Session afterRpcSuccess = session.toManagementSession();
+        assertEquals(managementSession.getInRpcs().getValue().toJava() + 1,
                 afterRpcSuccess.getInRpcs().getValue().longValue());
     }
 
     @Test
     public void testOnIncommingRpcFail() throws Exception {
         session.sessionUp();
-        final Session managementSession = this.session.toManagementSession();
-        this.session.onIncommingRpcFail();
-        final Session afterRpcSuccess = this.session.toManagementSession();
-        Assert.assertEquals(managementSession.getInBadRpcs().getValue() + 1,
+        final Session managementSession = session.toManagementSession();
+        session.onIncommingRpcFail();
+        final Session afterRpcSuccess = session.toManagementSession();
+        assertEquals(managementSession.getInBadRpcs().getValue().toJava() + 1,
                 afterRpcSuccess.getInBadRpcs().getValue().longValue());
     }
 
     @Test
     public void testOnOutgoingRpcError() throws Exception {
         session.sessionUp();
-        final Session managementSession = this.session.toManagementSession();
-        this.session.onOutgoingRpcError();
-        final Session afterRpcSuccess = this.session.toManagementSession();
-        Assert.assertEquals(managementSession.getOutRpcErrors().getValue() + 1,
+        final Session managementSession = session.toManagementSession();
+        session.onOutgoingRpcError();
+        final Session afterRpcSuccess = session.toManagementSession();
+        assertEquals(managementSession.getOutRpcErrors().getValue().toJava() + 1,
                 afterRpcSuccess.getOutRpcErrors().getValue().longValue());
     }
 
@@ -138,10 +139,10 @@ public class NetconfServerSessionTest {
         final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         final Session managementSession = tcpSession.toManagementSession();
-        Assert.assertEquals(HOST, managementSession.getSourceHost().getIpAddress().getIpv4Address().getValue());
-        Assert.assertEquals(managementSession.getUsername(), USER);
-        Assert.assertEquals(managementSession.getSessionId().toString(), SESSION_ID);
-        Assert.assertEquals(managementSession.getTransport(), NetconfTcp.class);
+        assertEquals(HOST, managementSession.getSourceHost().getIpAddress().getIpv4Address().getValue());
+        assertEquals(USER, managementSession.getUsername());
+        assertEquals(SESSION_ID, managementSession.getSessionId().toString());
+        assertEquals(NetconfTcp.VALUE, managementSession.getTransport());
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -163,15 +164,15 @@ public class NetconfServerSessionTest {
         final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         final Session managementSession = tcpSession.toManagementSession();
-        Assert.assertEquals("::1", managementSession.getSourceHost().getIpAddress().getIpv6Address().getValue());
-        Assert.assertEquals(managementSession.getUsername(), USER);
-        Assert.assertEquals(managementSession.getSessionId().toString(), SESSION_ID);
-        Assert.assertEquals(managementSession.getTransport(), NetconfSsh.class);
+        assertEquals("::1", managementSession.getSourceHost().getIpAddress().getIpv6Address().getValue());
+        assertEquals(USER, managementSession.getUsername());
+        assertEquals(SESSION_ID, managementSession.getSessionId().toString());
+        assertEquals(NetconfSsh.VALUE, managementSession.getTransport());
     }
 
     @Test
     public void testThisInstance() throws Exception {
-        Assert.assertEquals(session, session.thisInstance());
+        assertEquals(session, session.thisInstance());
     }
 
     @Test
@@ -193,13 +194,12 @@ public class NetconfServerSessionTest {
         session.stopExiCommunication();
         //handler is replaced only after next send message call
         final ChannelHandler exiEncoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER);
-        Assert.assertTrue(ChannelOutboundHandlerAdapter.class.equals(exiEncoder.getClass()));
+        assertTrue(ChannelOutboundHandlerAdapter.class.equals(exiEncoder.getClass()));
         session.sendMessage(msg);
         channel.runPendingTasks();
         final ChannelHandler decoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER);
-        Assert.assertTrue(NetconfXMLToMessageDecoder.class.equals(decoder.getClass()));
+        assertTrue(NetconfXMLToMessageDecoder.class.equals(decoder.getClass()));
         final ChannelHandler encoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER);
-        Assert.assertTrue(NetconfMessageToXMLEncoder.class.equals(encoder.getClass()));
+        assertTrue(NetconfMessageToXMLEncoder.class.equals(encoder.getClass()));
     }
-
 }