X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fimpl%2FMessageParserTest.java;h=88f4f1133726a3e8877fab7ccc3be161a5048b81;hb=38e1f73f062455df1c833d75128919a4473a71d2;hp=0b07c774f250ef1db726c2a15b20ad016956f28b;hpb=47c1b8e3d9835d336c79d6b4ca4e61417a05039e;p=netconf.git diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java index 0b07c774f2..88f4f11337 100644 --- a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java +++ b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/MessageParserTest.java @@ -21,6 +21,7 @@ import io.netty.channel.embedded.EmbeddedChannel; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Queue; +import org.custommonkey.xmlunit.XMLUnit; import org.junit.Before; import org.junit.Test; import org.opendaylight.netconf.api.NetconfMessage; @@ -31,7 +32,6 @@ import org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator; import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder; import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder; import org.opendaylight.netconf.util.messages.FramingMechanism; -import org.opendaylight.netconf.util.messages.NetconfMessageConstants; import org.opendaylight.netconf.util.test.XmlFileLoader; public class MessageParserTest { @@ -40,7 +40,7 @@ public class MessageParserTest { @Before public void setUp() throws Exception { - this.msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); + msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); } @Test @@ -52,7 +52,7 @@ public class MessageParserTest { new NetconfChunkAggregator(), new NetconfXMLToMessageDecoder()); - testChunkChannel.writeOutbound(this.msg); + testChunkChannel.writeOutbound(msg); Queue messages = testChunkChannel.outboundMessages(); assertFalse(messages.isEmpty()); @@ -66,7 +66,7 @@ public class MessageParserTest { chunkCount++; } - byte[] endOfChunkBytes = NetconfMessageConstants.END_OF_CHUNK.getBytes(StandardCharsets.UTF_8); + byte[] endOfChunkBytes = FramingMechanism.CHUNK_END_STR.getBytes(StandardCharsets.US_ASCII); for (int i = 1; i <= chunkCount; i++) { ByteBuf recievedOutbound = (ByteBuf) messages.poll(); int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE; @@ -77,8 +77,7 @@ public class MessageParserTest { assertArrayEquals(endOfChunkBytes, eom); } - byte[] header = new byte[String.valueOf(exptHeaderLength).length() - + NetconfMessageConstants.MIN_HEADER_LENGTH - 1]; + byte[] header = new byte[String.valueOf(exptHeaderLength).length() + 3]; recievedOutbound.getBytes(0, header); assertEquals(exptHeaderLength, getHeaderLength(header)); @@ -86,9 +85,10 @@ public class MessageParserTest { } assertTrue(messages.isEmpty()); - NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound(); + NetconfMessage receivedMessage = testChunkChannel.readInbound(); assertNotNull(receivedMessage); - assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument()); + XMLUnit.setIgnoreWhitespace(true); + assertXMLEqual(msg.getDocument(), receivedMessage.getDocument()); } @Test @@ -97,21 +97,22 @@ public class MessageParserTest { FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM), new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder()); - testChunkChannel.writeOutbound(this.msg); - ByteBuf recievedOutbound = (ByteBuf) testChunkChannel.readOutbound(); + testChunkChannel.writeOutbound(msg); + ByteBuf recievedOutbound = testChunkChannel.readOutbound(); - byte[] endOfMsgBytes = NetconfMessageConstants.END_OF_MESSAGE.getBytes(StandardCharsets.UTF_8); + byte[] endOfMsgBytes = FramingMechanism.EOM_STR.getBytes(StandardCharsets.US_ASCII); byte[] eom = new byte[endOfMsgBytes.length]; recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfMsgBytes.length, eom); assertArrayEquals(endOfMsgBytes, eom); testChunkChannel.writeInbound(recievedOutbound); - NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound(); + NetconfMessage receivedMessage = testChunkChannel.readInbound(); assertNotNull(receivedMessage); - assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument()); + XMLUnit.setIgnoreWhitespace(true); + assertXMLEqual(msg.getDocument(), receivedMessage.getDocument()); } - private static long getHeaderLength(byte[] bytes) { + private static long getHeaderLength(final byte[] bytes) { byte[] headerStart = new byte[]{(byte) 0x0a, (byte) 0x23}; return Long.parseLong(StandardCharsets.US_ASCII.decode( ByteBuffer.wrap(bytes, headerStart.length, bytes.length - headerStart.length - 1)).toString());