X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FMessageParserTest.java;h=e13415b64b71ad31aa6e2e846adbb360f3740183;hp=85bccba14ff01da5d559ad83ff6080e0ef5b6b42;hb=408eeef51f435abd2027f9d25ac5592066b202dd;hpb=509a8a4d570abc3a9a496837617015b1084c2761 diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/MessageParserTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/MessageParserTest.java index 85bccba14f..e13415b64b 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/MessageParserTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/MessageParserTest.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.netconf.impl; +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -22,9 +23,10 @@ import java.util.Queue; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.util.handler.ChunkedFramingMechanismEncoder; import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory; -import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator; -import org.opendaylight.controller.netconf.util.handler.NetconfMessageChunkDecoder; +import org.opendaylight.controller.netconf.util.handler.NetconfChunkAggregator; +import org.opendaylight.controller.netconf.util.handler.NetconfEOMAggregator; import org.opendaylight.controller.netconf.util.handler.NetconfMessageToXMLEncoder; import org.opendaylight.controller.netconf.util.handler.NetconfXMLToMessageDecoder; import org.opendaylight.controller.netconf.util.messages.FramingMechanism; @@ -47,7 +49,7 @@ public class MessageParserTest { FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK), new NetconfMessageToXMLEncoder(), - new NetconfMessageAggregator(FramingMechanism.CHUNK), new NetconfMessageChunkDecoder(), + new NetconfChunkAggregator(), new NetconfXMLToMessageDecoder()); testChunkChannel.writeOutbound(this.msg); @@ -59,26 +61,25 @@ public class MessageParserTest { enc.encode(null, msg, out); int msgLength = out.readableBytes(); - int chunkCount = msgLength / NetconfMessageConstants.MAX_CHUNK_SIZE; - if ((msgLength % NetconfMessageConstants.MAX_CHUNK_SIZE) != 0) { + int chunkCount = msgLength / ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE; + if ((msgLength % ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE) != 0) { chunkCount++; } for (int i = 1; i <= chunkCount; i++) { ByteBuf recievedOutbound = (ByteBuf) messages.poll(); - int exptHeaderLength = NetconfMessageConstants.MAX_CHUNK_SIZE; + int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE; if (i == chunkCount) { - exptHeaderLength = msgLength - (NetconfMessageConstants.MAX_CHUNK_SIZE * (i - 1)); - byte[] eom = new byte[NetconfMessageConstants.endOfChunk.length]; - recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageConstants.endOfChunk.length, + exptHeaderLength = msgLength - (ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE * (i - 1)); + byte[] eom = new byte[NetconfMessageConstants.END_OF_CHUNK.length]; + recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageConstants.END_OF_CHUNK.length, eom); - assertArrayEquals(NetconfMessageConstants.endOfChunk, eom); + assertArrayEquals(NetconfMessageConstants.END_OF_CHUNK, eom); } byte[] header = new byte[String.valueOf(exptHeaderLength).length() + NetconfMessageConstants.MIN_HEADER_LENGTH - 1]; recievedOutbound.getBytes(0, header); - NetconfMessageHeader messageHeader = new NetconfMessageHeader(); - messageHeader.fromBytes(header); + NetconfMessageHeader messageHeader = NetconfMessageHeader.fromBytes(header); assertEquals(exptHeaderLength, messageHeader.getLength()); testChunkChannel.writeInbound(recievedOutbound); @@ -87,26 +88,25 @@ public class MessageParserTest { NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound(); assertNotNull(receivedMessage); - assertTrue(this.msg.getDocument().isEqualNode(receivedMessage.getDocument())); + assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument()); } @Test public void testEOMFramingMechanismOnPipeline() throws Exception { EmbeddedChannel testChunkChannel = new EmbeddedChannel( FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM), - new NetconfMessageToXMLEncoder(), new NetconfMessageAggregator( - FramingMechanism.EOM), new NetconfXMLToMessageDecoder()); + new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder()); testChunkChannel.writeOutbound(this.msg); ByteBuf recievedOutbound = (ByteBuf) testChunkChannel.readOutbound(); - byte[] eom = new byte[NetconfMessageConstants.endOfMessage.length]; - recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageConstants.endOfMessage.length, eom); - assertArrayEquals(NetconfMessageConstants.endOfMessage, eom); + byte[] eom = new byte[NetconfMessageConstants.END_OF_MESSAGE.length]; + recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageConstants.END_OF_MESSAGE.length, eom); + assertArrayEquals(NetconfMessageConstants.END_OF_MESSAGE, eom); testChunkChannel.writeInbound(recievedOutbound); NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound(); assertNotNull(receivedMessage); - assertTrue(this.msg.getDocument().isEqualNode(receivedMessage.getDocument())); + assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument()); } }