- @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))
- .iterator().next().getDocument();
- assertEquals(XmlUtil.toString(msg), XmlUtil.toString(doc));
- XMLAssert.assertXMLEqual(msg, doc);
+ testChunkChannel.writeOutbound(this.msg);
+ Queue<Object> messages = testChunkChannel.outboundMessages();
+ assertFalse(messages.isEmpty());
+
+ int msgLength = this.msgFactory.put(this.msg).length;
+ int chunkCount = msgLength / NetconfMessageConstants.MAX_CHUNK_SIZE;
+ if ((msgLength % NetconfMessageConstants.MAX_CHUNK_SIZE) != 0) {
+ chunkCount++;
+ }
+ for (int i = 1; i <= chunkCount; i++) {
+ ByteBuf recievedOutbound = (ByteBuf) messages.poll();
+ int exptHeaderLength = NetconfMessageConstants.MAX_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,
+ eom);
+ assertArrayEquals(NetconfMessageConstants.endOfChunk, 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);
+ assertEquals(exptHeaderLength, messageHeader.getLength());
+
+ testChunkChannel.writeInbound(recievedOutbound);
+ }
+ assertTrue(messages.isEmpty());
+
+ NetconfMessage receivedMessage = (NetconfMessage) testChunkChannel.readInbound();
+ assertNotNull(receivedMessage);
+ assertTrue(this.msg.getDocument().isEqualNode(receivedMessage.getDocument()));