Cleanup use of deprecated constructs
[netconf.git] / netconf / netconf-impl / src / test / java / org / opendaylight / netconf / impl / NetconfServerSessionTest.java
index 84603bc5114c172058c27da99f53790b70762465..8a4c73fdcb4b18e083c131b69490804c000aef6f 100644 (file)
@@ -8,8 +8,8 @@
 
 package org.opendaylight.netconf.impl;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.verify;
 
@@ -22,20 +22,20 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.nettyutil.AbstractChannelInitializer;
 import org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec;
 import org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
+import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210.NetconfTcp;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfSsh;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
-import org.openexi.proc.common.EXIOptions;
 import org.w3c.dom.Document;
 
 public class NetconfServerSessionTest {
@@ -92,12 +92,12 @@ public class NetconfServerSessionTest {
     public void testSendNotification() throws Exception {
         doNothing().when(listener).onNotification(any(), any());
         final Document msgDoc = XmlUtil.readXmlToDocument("<notification></notification>");
-        final NetconfNotification msg = new NetconfNotification(msgDoc);
-        session.sendMessage(msg);
+        final NetconfNotification notif = new NetconfNotification(msgDoc);
+        session.sendMessage(notif);
         channel.runPendingTasks();
         final Object o = channel.readOutbound();
-        Assert.assertEquals(msg, o);
-        verify(listener).onNotification(session, msg);
+        Assert.assertEquals(notif, o);
+        verify(listener).onNotification(session, notif);
     }
 
     @Test
@@ -106,7 +106,7 @@ public class NetconfServerSessionTest {
         final Session managementSession = this.session.toManagementSession();
         this.session.onIncommingRpcSuccess();
         final Session afterRpcSuccess = this.session.toManagementSession();
-        Assert.assertEquals(managementSession.getInRpcs().getValue() + 1,
+        Assert.assertEquals(managementSession.getInRpcs().getValue().toJava() + 1,
                 afterRpcSuccess.getInRpcs().getValue().longValue());
     }
 
@@ -116,7 +116,7 @@ public class NetconfServerSessionTest {
         final Session managementSession = this.session.toManagementSession();
         this.session.onIncommingRpcFail();
         final Session afterRpcSuccess = this.session.toManagementSession();
-        Assert.assertEquals(managementSession.getInBadRpcs().getValue() + 1,
+        Assert.assertEquals(managementSession.getInBadRpcs().getValue().toJava() + 1,
                 afterRpcSuccess.getInBadRpcs().getValue().longValue());
     }
 
@@ -126,7 +126,7 @@ public class NetconfServerSessionTest {
         final Session managementSession = this.session.toManagementSession();
         this.session.onOutgoingRpcError();
         final Session afterRpcSuccess = this.session.toManagementSession();
-        Assert.assertEquals(managementSession.getOutRpcErrors().getValue() + 1,
+        Assert.assertEquals(managementSession.getOutRpcErrors().getValue().toJava() + 1,
                 afterRpcSuccess.getOutRpcErrors().getValue().longValue());
     }
 
@@ -134,11 +134,11 @@ public class NetconfServerSessionTest {
     public void testToManagementSession() throws Exception {
         final NetconfHelloMessageAdditionalHeader header =
                 new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, TCP_TRANSPORT, SESSION_ID);
-        final EmbeddedChannel channel = new EmbeddedChannel();
-        final NetconfServerSession tcpSession = new NetconfServerSession(listener, channel, 1L, header);
+        final EmbeddedChannel ch = new EmbeddedChannel();
+        final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         final Session managementSession = tcpSession.toManagementSession();
-        Assert.assertEquals(new String(managementSession.getSourceHost().getValue()), HOST);
+        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);
@@ -148,21 +148,22 @@ public class NetconfServerSessionTest {
     public void testToManagementSessionUnknownTransport() throws Exception {
         final NetconfHelloMessageAdditionalHeader header =
                 new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, "http", SESSION_ID);
-        final EmbeddedChannel channel = new EmbeddedChannel();
-        final NetconfServerSession tcpSession = new NetconfServerSession(listener, channel, 1L, header);
+        final EmbeddedChannel ch = new EmbeddedChannel();
+        final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         tcpSession.toManagementSession();
+        tcpSession.close();
     }
 
     @Test
     public void testToManagementSessionIpv6() throws Exception {
         final NetconfHelloMessageAdditionalHeader header =
                 new NetconfHelloMessageAdditionalHeader(USER, "::1", PORT, SSH_TRANSPORT, SESSION_ID);
-        final EmbeddedChannel channel = new EmbeddedChannel();
-        final NetconfServerSession tcpSession = new NetconfServerSession(listener, channel, 1L, header);
+        final EmbeddedChannel ch = new EmbeddedChannel();
+        final NetconfServerSession tcpSession = new NetconfServerSession(listener, ch, 1L, header);
         tcpSession.sessionUp();
         final Session managementSession = tcpSession.toManagementSession();
-        Assert.assertEquals(new String(managementSession.getSourceHost().getValue()), "::1");
+        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);
@@ -179,7 +180,7 @@ public class NetconfServerSessionTest {
                 new NetconfXMLToMessageDecoder());
         channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
                 new NetconfMessageToXMLEncoder());
-        final NetconfEXICodec codec = new NetconfEXICodec(new EXIOptions());
+        final NetconfEXICodec codec = NetconfEXICodec.forParameters(EXIParameters.empty());
         session.addExiHandlers(NetconfEXIToMessageDecoder.create(codec), NetconfMessageToEXIEncoder.create(codec));
     }
 
@@ -201,4 +202,4 @@ public class NetconfServerSessionTest {
         Assert.assertTrue(NetconfMessageToXMLEncoder.class.equals(encoder.getClass()));
     }
 
-}
\ No newline at end of file
+}