Search in sources :

Example 11 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfXMLToHelloMessageDecoderTest method testDecodeWithHeader.

@Test
public void testDecodeWithHeader() throws Exception {
    final ByteBuf src = Unpooled.wrappedBuffer(String.format("%s\n%s", "[tomas;10.0.0.0:10000;tcp;client;]", "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>").getBytes());
    final List<Object> out = new ArrayList<>();
    new NetconfXMLToHelloMessageDecoder().decode(null, src, out);
    assertEquals(1, out.size());
    assertThat(out.get(0), CoreMatchers.instanceOf(NetconfHelloMessage.class));
    final NetconfHelloMessage hello = (NetconfHelloMessage) out.get(0);
    assertTrue(hello.getAdditionalHeader().isPresent());
    assertEquals("[tomas;10.0.0.0:10000;tcp;client;]" + System.lineSeparator(), hello.getAdditionalHeader().get().toFormattedString());
    assertThat(XmlUtil.toString(hello.getDocument()), CoreMatchers.containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\""));
}
Also used : ArrayList(java.util.ArrayList) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 12 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class Netconf539Test method testGetSessionForHelloMessage.

private void testGetSessionForHelloMessage(final String fileName) throws Exception {
    final Document helloDocument = XmlFileLoader.xmlFileToDocument(fileName);
    negotiator.startNegotiation();
    final NetconfHelloMessage helloMessage = new NetconfHelloMessage(helloDocument);
    final AbstractNetconfSession session = negotiator.getSessionForHelloMessage(helloMessage);
    Assert.assertNotNull(session);
    Assert.assertTrue("NetconfChunkAggregator was not installed in the Netconf pipeline", channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR) instanceof NetconfChunkAggregator);
    Assert.assertTrue("ChunkedFramingMechanismEncoder was not installed in the Netconf pipeline", channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER) instanceof ChunkedFramingMechanismEncoder);
}
Also used : ChunkedFramingMechanismEncoder(org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder) NetconfChunkAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) Document(org.w3c.dom.Document)

Example 13 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfHelloMessageToXMLEncoderTest method testEncode.

@Test
public void testEncode() throws Exception {
    final NetconfMessage msg = new NetconfHelloMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"), NetconfHelloMessageAdditionalHeader.fromString("[tomas;10.0.0.0:10000;tcp;client;]"));
    final ByteBuf destination = Unpooled.buffer();
    new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, destination);
    final String encoded = new String(destination.array());
    assertThat(encoded, containsString("[tomas;10.0.0.0:10000;tcp;client;]"));
    assertThat(encoded, containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 14 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfHelloMessageToXMLEncoderTest method testEncodeNoHeader.

@Test
public void testEncodeNoHeader() throws Exception {
    final NetconfMessage msg = new NetconfHelloMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
    final ByteBuf destination = Unpooled.buffer();
    new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, destination);
    final String encoded = new String(destination.array());
    assertThat(encoded, not(containsString("[tomas;10.0.0.0:10000;tcp;client;]")));
    assertThat(encoded, containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

NetconfHelloMessage (org.opendaylight.netconf.api.messages.NetconfHelloMessage)14 Test (org.junit.Test)8 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)5 ByteBuf (io.netty.buffer.ByteBuf)4 Document (org.w3c.dom.Document)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelProgressivePromise (io.netty.channel.ChannelProgressivePromise)1 ChannelPromise (io.netty.channel.ChannelPromise)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Promise (io.netty.util.concurrent.Promise)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1