X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fimpl%2FMessageParserTest.java;h=abf2ad862f779cb5651f200fb484138482bbb5c0;hb=7ab97f33c1d0c7da891337d8ec0b117555914115;hp=3b88a231083fa50a1a1f6e7326d6a8d3fc6f0d29;hpb=e6bcd06e610be274e8f2df901b61789bb17c442a;p=controller.git 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 3b88a23108..abf2ad862f 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,34 +8,34 @@ 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; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.util.Queue; - import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.embedded.EmbeddedChannel; - +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.FramingMechanismHandlerFactory; -import org.opendaylight.controller.netconf.util.handler.NetconfMessageAggregator; -import org.opendaylight.controller.netconf.util.handler.NetconfMessageChunkDecoder; +import org.opendaylight.controller.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder; +import org.opendaylight.controller.netconf.nettyutil.handler.FramingMechanismHandlerFactory; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfChunkAggregator; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEOMAggregator; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfMessageToXMLEncoder; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToMessageDecoder; import org.opendaylight.controller.netconf.util.messages.FramingMechanism; -import org.opendaylight.controller.netconf.util.messages.NetconfMessageFactory; +import org.opendaylight.controller.netconf.util.messages.NetconfMessageConstants; import org.opendaylight.controller.netconf.util.messages.NetconfMessageHeader; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; -import org.opendaylight.protocol.framework.ProtocolMessageDecoder; -import org.opendaylight.protocol.framework.ProtocolMessageEncoder; public class MessageParserTest { private NetconfMessage msg; - private NetconfMessageFactory msgFactory = new NetconfMessageFactory(); @Before public void setUp() throws Exception { @@ -46,36 +46,39 @@ public class MessageParserTest { public void testChunkedFramingMechanismOnPipeline() throws Exception { EmbeddedChannel testChunkChannel = new EmbeddedChannel( FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK), - new ProtocolMessageEncoder(msgFactory), + new NetconfMessageToXMLEncoder(), - new NetconfMessageAggregator(FramingMechanism.CHUNK), new NetconfMessageChunkDecoder(), - new ProtocolMessageDecoder(msgFactory)); + new NetconfChunkAggregator(), + new NetconfXMLToMessageDecoder()); testChunkChannel.writeOutbound(this.msg); Queue messages = testChunkChannel.outboundMessages(); assertFalse(messages.isEmpty()); - int msgLength = msgFactory.put(this.msg).length; - int chunkCount = msgLength / NetconfMessageFactory.MAX_CHUNK_SIZE; - if ((msgLength % NetconfMessageFactory.MAX_CHUNK_SIZE) != 0) { + final NetconfMessageToXMLEncoder enc = new NetconfMessageToXMLEncoder(); + final ByteBuf out = Unpooled.buffer(); + enc.encode(null, msg, out); + int msgLength = out.readableBytes(); + + 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 = NetconfMessageFactory.MAX_CHUNK_SIZE; + int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE; if (i == chunkCount) { - exptHeaderLength = msgLength - (NetconfMessageFactory.MAX_CHUNK_SIZE * (i - 1)); - byte[] eom = new byte[NetconfMessageFactory.endOfChunk.length]; - recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageFactory.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(NetconfMessageFactory.endOfChunk, eom); + assertArrayEquals(NetconfMessageConstants.END_OF_CHUNK, eom); } - byte[] header = new byte[String.valueOf(exptHeaderLength).length() + NetconfMessageHeader.MIN_HEADER_LENGTH - - 1]; + 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); @@ -84,26 +87,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 ProtocolMessageEncoder(msgFactory), new NetconfMessageAggregator( - FramingMechanism.EOM), new ProtocolMessageDecoder(msgFactory)); + new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder()); testChunkChannel.writeOutbound(this.msg); ByteBuf recievedOutbound = (ByteBuf) testChunkChannel.readOutbound(); - byte[] eom = new byte[NetconfMessageFactory.endOfMessage.length]; - recievedOutbound.getBytes(recievedOutbound.readableBytes() - NetconfMessageFactory.endOfMessage.length, eom); - assertArrayEquals(NetconfMessageFactory.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()); } }