Search in sources :

Example 1 with NetconfServerSessionListener

use of org.opendaylight.netconf.impl.NetconfServerSessionListener 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)

Aggregations

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