use of org.opendaylight.netconf.impl.NetconfServerSession in project netconf by opendaylight.
the class DefaultCloseSessionTest method testDefaultCloseSession.
@Test
public void testDefaultCloseSession() throws Exception {
AutoCloseable res = mock(AutoCloseable.class);
doNothing().when(res).close();
DefaultCloseSession close = new DefaultCloseSession("", res);
final Document doc = XmlUtil.newDocument();
final XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
final Channel channel = mock(Channel.class);
doReturn("channel").when(channel).toString();
mockEventLoop(channel);
final ChannelFuture channelFuture = mock(ChannelFuture.class);
doReturn(channelFuture).when(channel).close();
doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
final ChannelPromise sendFuture = mock(ChannelPromise.class);
doAnswer(invocation -> {
invocation.<GenericFutureListener>getArgument(0).operationComplete(sendFuture);
return null;
}).when(sendFuture).addListener(any(GenericFutureListener.class));
doReturn(sendFuture).when(channel).newPromise();
doReturn(sendFuture).when(channel).writeAndFlush(any(), any());
doReturn(true).when(sendFuture).isSuccess();
final NetconfServerSessionListener listener = mock(NetconfServerSessionListener.class);
doNothing().when(listener).onSessionTerminated(any(NetconfServerSession.class), any(NetconfTerminationReason.class));
final NetconfServerSession session = new NetconfServerSession(listener, channel, 1L, NetconfHelloMessageAdditionalHeader.fromString("[netconf;10.12.0.102:48528;ssh;;;;;;]"));
close.setNetconfSession(session);
close.handleWithNoSubsequentOperations(doc, elem);
// Fake close response to trigger delayed close
session.sendMessage(new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<ok/>\n" + "</rpc-reply>")));
verify(channel).close();
verify(listener).onSessionTerminated(any(NetconfServerSession.class), any(NetconfTerminationReason.class));
}
use of org.opendaylight.netconf.impl.NetconfServerSession in project netconf by opendaylight.
the class DefaultStopExiTest method testHandleWithNoSubsequentOperations.
@Test
public void testHandleWithNoSubsequentOperations() throws Exception {
final DefaultStopExi exi = new DefaultStopExi("");
final Document doc = XmlUtil.newDocument();
Channel channel = mock(Channel.class);
doReturn("mockChannel").when(channel).toString();
ChannelPipeline pipeline = mock(ChannelPipeline.class);
doReturn(pipeline).when(channel).pipeline();
ChannelHandler channelHandler = mock(ChannelHandler.class);
doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
NetconfServerSession serverSession = new NetconfServerSession(null, channel, 2L, null);
exi.setNetconfSession(serverSession);
assertNotNull(exi.handleWithNoSubsequentOperations(doc, XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"))));
verify(pipeline, times(1)).replace(anyString(), anyString(), any(ChannelHandler.class));
}
Aggregations