+ @Test
+ public void testNormalizedNodeStreaming() throws IOException {
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
+
+ NormalizedNode<?, ?> testContainer = createTestContainer();
+ nnout.writeNormalizedNode(testContainer);
+
+ QName toaster = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","toaster");
+ QName darknessFactor = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","darknessFactor");
+ QName description = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","description");
+ ContainerNode toasterNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(toaster))
+ .withChild(ImmutableNodes.leafNode(darknessFactor, "1000"))
+ .withChild(ImmutableNodes.leafNode(description, largeString(20))).build();
+
+ ContainerNode toasterContainer = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).withChild(toasterNode).build();
+ nnout.writeNormalizedNode(toasterContainer);
+
+ final byte[] bytes = bos.toByteArray();
+ assertEquals(1049618, bytes.length);
+
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
+
+ NormalizedNode<?, ?> node = nnin.readNormalizedNode();
+ Assert.assertEquals(testContainer, node);
+
+ node = nnin.readNormalizedNode();
+ Assert.assertEquals(toasterContainer, node);
+ }
+
+ private static NormalizedNode<?, ?> createTestContainer() {
+ byte[] bytes1 = {1, 2, 3};
+ LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
+ new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build();
+
+ byte[] bytes2 = {};
+ LeafSetEntryNode<Object> entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
+ new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)).withValue(bytes2).build();
+
+ return TestModel.createBaseTestContainerBuilder()
+ .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
+ new NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME))
+ .withChild(entry1).withChild(entry2).build())
+ .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1, 2, 3, 4}))
+ .withChild(ImmutableNodes.leafNode(TestModel.EMPTY_QNAME, Empty.getInstance()))
+ .withChild(Builders.orderedMapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(TestModel.ORDERED_LIST_QNAME))
+ .withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME,
+ TestModel.ID_QNAME, 11)).build()).build();
+ }