Search in sources :

Example 1 with NetconfServerSession

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));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NetconfTerminationReason(org.opendaylight.netconf.api.NetconfTerminationReason) NetconfServerSessionListener(org.opendaylight.netconf.impl.NetconfServerSessionListener) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Channel(io.netty.channel.Channel) NetconfServerSession(org.opendaylight.netconf.impl.NetconfServerSession) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) ChannelPromise(io.netty.channel.ChannelPromise) Document(org.w3c.dom.Document) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) Test(org.junit.Test)

Example 2 with NetconfServerSession

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));
}
Also used : Channel(io.netty.channel.Channel) NetconfServerSession(org.opendaylight.netconf.impl.NetconfServerSession) ChannelHandler(io.netty.channel.ChannelHandler) Document(org.w3c.dom.Document) ChannelPipeline(io.netty.channel.ChannelPipeline) Test(org.junit.Test)

Aggregations

Channel (io.netty.channel.Channel)2 Test (org.junit.Test)2 NetconfServerSession (org.opendaylight.netconf.impl.NetconfServerSession)2 Document (org.w3c.dom.Document)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 ChannelPromise (io.netty.channel.ChannelPromise)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfTerminationReason (org.opendaylight.netconf.api.NetconfTerminationReason)1 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)1 NetconfServerSessionListener (org.opendaylight.netconf.impl.NetconfServerSessionListener)1