Bug 2766: Fixed parsing and serializing XPath Instance Identifiers
[yangtools.git] / yang / yang-data-codec-gson / src / test / java / org / opendaylight / yangtools / yang / data / codec / gson / NormalizedNodeToJsonStreamTest.java
index 62e7cf18cd8ce742beebabe5971d5bdd60b2143c..90fd51b80302a420df40ef01a93ef81cec99a4f0 100644 (file)
@@ -95,6 +95,32 @@ public class NormalizedNodeToJsonStreamTest {
 
     }
 
+    @Test
+    public void leafListNodeInContainerMultiline() throws IOException, URISyntaxException {
+        Writer writer = new StringWriter();
+        NormalizedNode<?, ?> leafListNodeInContainer = TestingNormalizedNodeStructuresCreator.leafListNodeInContainerMultiline();
+        String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer);
+        new JsonValidator() {
+
+            @Override
+            public void validate(String jsonOutput) {
+                JsonObject cont1 = resolveCont1(jsonOutput);
+                assertNotNull(cont1);
+                JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11");
+                assertNotNull(lflst11);
+
+                HashSet<Object> lflst11Values = Sets.newHashSet();
+                for (JsonElement jsonElement : lflst11) {
+                    assertTrue(jsonElement instanceof JsonPrimitive);
+                    lflst11Values.add(((JsonPrimitive) jsonElement).getAsString());
+                }
+
+                assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"), lflst11Values);
+            }
+        }.validate(jsonOutput);
+
+    }
+
     @Test
     public void leafNodeViaAugmentationInContainer() throws IOException, URISyntaxException {
         Writer writer = new StringWriter();
@@ -174,7 +200,7 @@ public class NormalizedNodeToJsonStreamTest {
                 assertNotNull(lf111);
 
                 assertEquals("key111 value", key111.getAsString());
-                assertEquals("/complexjson:cont1/complexjson:lflst11", lf112.getAsString());
+                assertEquals("/complexjson:cont1/complexjson:lflst11[.='foo']", lf112.getAsString());
                 assertEquals("lf113 value", lf113.getAsString());
                 assertEquals("lf111 value", lf111.getAsString());
             }
@@ -355,11 +381,11 @@ public class NormalizedNodeToJsonStreamTest {
 
     private String normalizedNodeToJsonStreamTransformation(final Writer writer,
             final NormalizedNode<?, ?> inputStructure) throws IOException {
-        writer.write("{\n");
+
         final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.create(schemaContext, writer, 2);
         final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream);
         nodeWriter.write(inputStructure);
-        writer.write("\n}");
+
         nodeWriter.close();
         return writer.toString();
     }