* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-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 io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
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.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.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.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;
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 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;
private NetconfServerSession session;
private EmbeddedChannel channel;
private NetconfMessage msg;
final NetconfHelloMessageAdditionalHeader header =
new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, SSH_TRANSPORT, SESSION_ID);
channel = new EmbeddedChannel();
final NetconfHelloMessageAdditionalHeader header =
new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, SSH_TRANSPORT, SESSION_ID);
channel = new EmbeddedChannel();
session.sendMessage(msg);
channel.runPendingTasks();
final Object o = channel.readOutbound();
session.sendMessage(msg);
channel.runPendingTasks();
final Object o = channel.readOutbound();
session.sendMessage(msg);
channel.runPendingTasks();
final Object o = channel.readOutbound();
session.sendMessage(msg);
channel.runPendingTasks();
final Object o = channel.readOutbound();
}
@Test
public void testSendNotification() throws Exception {
doNothing().when(listener).onNotification(any(), any());
final Document msgDoc = XmlUtil.readXmlToDocument("<notification></notification>");
}
@Test
public void testSendNotification() throws Exception {
doNothing().when(listener).onNotification(any(), any());
final Document msgDoc = XmlUtil.readXmlToDocument("<notification></notification>");
- Assert.assertEquals(msg, o);
- verify(listener).onNotification(session, msg);
+ assertEquals(notif, o);
+ verify(listener).onNotification(session, notif);
- 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();
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();
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,
public void testToManagementSession() throws Exception {
final NetconfHelloMessageAdditionalHeader header =
new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, TCP_TRANSPORT, SESSION_ID);
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);
- Assert.assertEquals(new String(managementSession.getSourceHost().getValue()), HOST);
- 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)
public void testToManagementSessionUnknownTransport() throws Exception {
final NetconfHelloMessageAdditionalHeader header =
new NetconfHelloMessageAdditionalHeader(USER, HOST, PORT, "http", SESSION_ID);
}
@Test(expected = IllegalArgumentException.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);
}
@Test
public void testToManagementSessionIpv6() throws Exception {
final NetconfHelloMessageAdditionalHeader header =
new NetconfHelloMessageAdditionalHeader(USER, "::1", PORT, SSH_TRANSPORT, SESSION_ID);
}
@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);
- Assert.assertEquals(new String(managementSession.getSourceHost().getValue()), "::1");
- 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());
new NetconfXMLToMessageDecoder());
channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
new NetconfMessageToXMLEncoder());
new NetconfXMLToMessageDecoder());
channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
new NetconfMessageToXMLEncoder());
session.stopExiCommunication();
//handler is replaced only after next send message call
final ChannelHandler exiEncoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER);
session.stopExiCommunication();
//handler is replaced only after next send message call
final ChannelHandler exiEncoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER);
session.sendMessage(msg);
channel.runPendingTasks();
final ChannelHandler decoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER);
session.sendMessage(msg);
channel.runPendingTasks();
final ChannelHandler decoder = channel.pipeline().get(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER);