- @Test
- public void testParseEOM() throws IOException, SAXException, DeserializerException, DocumentedException,
- ParserConfigurationException {
- final Document msg = XmlFileLoader.xmlFileToDocument("netconfMessages/client_hello.xml");
- final byte[] bytes = this.parser.put(new NetconfMessage(msg));
- final Document doc = this.parser
- .parse(ByteArray.subByte(bytes, 0, bytes.length - NetconfMessageFactory.endOfMessage.length))
- .getDocument();
- assertEquals(XmlUtil.toString(msg), XmlUtil.toString(doc));
- XMLAssert.assertXMLEqual(msg, doc);
+ testChunkChannel.writeOutbound(this.msg);
+ Queue<Object> messages = testChunkChannel.outboundMessages();
+ assertFalse(messages.isEmpty());
+
+ 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 = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
+ if (i == chunkCount) {
+ 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.END_OF_CHUNK, eom);
+ }
+
+ byte[] header = new byte[String.valueOf(exptHeaderLength).length()
+ + NetconfMessageConstants.MIN_HEADER_LENGTH - 1];
+ recievedOutbound.getBytes(0, header);
+ NetconfMessageHeader messageHeader = NetconfMessageHeader.fromBytes(header);
+ assertEquals(exptHeaderLength, messageHeader.getLength());
+
+ testChunkChannel.writeInbound(recievedOutbound);
+ }
+ assertTrue(messages.isEmpty());
+
+ NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound();
+ assertNotNull(receivedMessage);
+ assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());