From 847e52a362ef3749cc78e475b4875c876d20b530 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 11 Sep 2019 16:06:59 +0200 Subject: [PATCH] AbstractNormalizedNodeDataOutput fails to write out header In case AbstractNormalizedNodeDataOutput is used in a way, where NormalizedNodeDataOutput.writePathArgument() is the first method invoked, the stream header would not be output, leading to it being unreadable. Change-Id: I4ababb360129b2ef673d0546333599dd10fbdd9e Signed-off-by: Robert Varga --- .../NormalizedNodeStreamReaderWriterTest.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java b/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java index e1bf0447e6..aed87ad355 100644 --- a/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java +++ b/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java @@ -214,17 +214,32 @@ public class NormalizedNodeStreamReaderWriterTest { } @Test - public void testSchemaPathSerialization() throws Exception { + public void testSchemaPathSerialization() throws IOException { final SchemaPath expected = SchemaPath.create(true, TestModel.ANY_XML_QNAME); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos)); - nnout.writeSchemaPath(expected); + try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos))) { + nnout.writeSchemaPath(expected); + } + + NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( + bos.toByteArray())); + assertEquals(expected, nnin.readSchemaPath()); + } + + @Test + public void testWritePathArgument() throws IOException { + final NodeIdentifier expected = new NodeIdentifier(TestModel.BOOLEAN_LEAF_QNAME); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + try (NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos))) { + nnout.writePathArgument(expected); + } NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( bos.toByteArray())); - SchemaPath actual = nnin.readSchemaPath(); - assertEquals(expected, actual); + assertEquals(expected, nnin.readPathArgument()); } private static String largeString(final int pow) { -- 2.36.6