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\""));
}
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);
}
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\"/>"));
}
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\"/>"));
}
Aggregations