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;
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 {
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
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());
}
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());
}
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());
}
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);
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);
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));
}
Assert.assertTrue(NetconfMessageToXMLEncoder.class.equals(encoder.getClass()));
}
-}
\ No newline at end of file
+}