Merge "Test of conversing of yang + xml files to json 2."
authorEd Warnicke <eaw@cisco.com>
Fri, 8 Nov 2013 10:47:40 +0000 (10:47 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 8 Nov 2013 10:47:40 +0000 (10:47 +0000)
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/YangAndXmlToJsonConversionJsonReaderTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/YangAndXmlToJsonConversionRegExTest.java [moved from opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/YangAndXmlToJsonConversion.java with 51% similarity]
opendaylight/md-sal/sal-rest-connector/src/test/resources/yang-to-json-conversion/simple-yang-types/xml/awaited_output.json

index b4cf6c985b6aa8a9995ccb43ed4c27fe6f494166..c6296eb7ea14ce82726dcd080b548dc375e26940 100644 (file)
@@ -1,15 +1,14 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
+import javax.ws.rs.WebApplicationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
@@ -18,12 +17,13 @@ import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
+import org.opendaylight.controller.sal.restconf.impl.StructuredData;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 import org.opendaylight.yangtools.yang.data.impl.XmlTreeBuilder;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.*;
 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.slf4j.Logger;
@@ -114,5 +114,135 @@ final class TestUtils {
         }
 
     }
+    
+    static String convertXmlDataAndYangToJson(String xmlDataPath, String yangPath) {
+        String jsonResult = null;
+        Set<Module> modules = null;
+
+        try {
+            modules = TestUtils.loadModules(YangAndXmlToJsonConversionJsonReaderTest.class.getResource(yangPath).getPath());
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+        assertNotNull("modules can't be null.", modules);
+
+        InputStream xmlStream = YangAndXmlToJsonConversionJsonReaderTest.class.getResourceAsStream(xmlDataPath);
+        CompositeNode compositeNode = null;
+        try {
+            compositeNode = TestUtils.loadCompositeNode(xmlStream);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+        assertNotNull("Composite node can't be null", compositeNode);
+
+        StructuredDataToJsonProvider structuredDataToJsonProvider = StructuredDataToJsonProvider.INSTANCE;
+        for (Module module : modules) {
+            for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
+                StructuredData structuredData = new StructuredData(compositeNode, dataSchemaNode);
+                ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
+                try {
+                    structuredDataToJsonProvider.writeTo(structuredData, null, null, null, null, null, byteArrayOS);
+                } catch (WebApplicationException | IOException e) {
+                    e.printStackTrace();
+                }
+                assertFalse(
+                        "Returning JSON string can't be empty for node " + dataSchemaNode.getQName().getLocalName(),
+                        byteArrayOS.toString().isEmpty());
+                jsonResult = byteArrayOS.toString();
+                try {
+                    outputToFile(byteArrayOS);
+                } catch (IOException e) {
+                    System.out.println("Output file wasn't cloased sucessfuly.");
+                }
+            }
+        }
+        return jsonResult;
+    }
+    
+    static void outputToFile(ByteArrayOutputStream outputStream) throws IOException {
+        FileOutputStream fileOS = null;
+        try {
+            String path = YangAndXmlToJsonConversionJsonReaderTest.class.getResource("/yang-to-json-conversion/xml").getPath();
+            File outFile = new File(path + "/data.json");
+            fileOS = new FileOutputStream(outFile);
+            try {
+                fileOS.write(outputStream.toByteArray());
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            fileOS.close();
+        } catch (FileNotFoundException e1) {
+            e1.printStackTrace();
+        }
+    }    
+    
+    static String readJsonFromFile(String path,boolean removeWhiteChars) {
+        FileReader fileReader = getFileReader(path);
+
+        StringBuilder strBuilder = new StringBuilder();
+        char[] buffer = new char[1000];
+
+        while (true) {
+            int loadedCharNum;
+            try {
+                loadedCharNum = fileReader.read(buffer);
+            } catch (IOException e) {
+                break;
+            }
+            if (loadedCharNum == -1) {
+                break;
+            }
+            strBuilder.append(buffer, 0, loadedCharNum);
+        }
+        try {
+            fileReader.close();
+        } catch (IOException e) {
+            System.out.println("The file wasn't closed");
+        }
+        String rawStr = strBuilder.toString();
+        if (removeWhiteChars) {        
+            rawStr = rawStr.replace("\n", "");
+            rawStr = rawStr.replace("\r", "");
+            rawStr = rawStr.replace("\t", "");
+            rawStr = removeSpaces(rawStr);
+        }
+
+        return rawStr;
+    }
+    
+    private static FileReader getFileReader(String path) {
+        String fullPath = YangAndXmlToJsonConversionJsonReaderTest.class.getResource(path).getPath();
+        assertNotNull("Path to file can't be null.", fullPath);
+        File file = new File(fullPath);
+        assertNotNull("File can't be null", file);
+        FileReader fileReader = null;
+        try {
+            fileReader = new FileReader(file);
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        }
+        assertNotNull("File reader can't be null.", fileReader);
+        return fileReader;
+    }
+
+    private static String removeSpaces(String rawStr) {
+        StringBuilder strBuilder = new StringBuilder();
+        int i = 0;
+        int quoteCount = 0;
+        while (i < rawStr.length()) {
+            if (rawStr.substring(i, i + 1).equals("\"")) {
+                quoteCount++;
+            }
+
+            if (!rawStr.substring(i, i + 1).equals(" ") || (quoteCount % 2 == 1)) {
+                strBuilder.append(rawStr.charAt(i));
+            }
+            i++;
+        }
+
+        return strBuilder.toString();
+    }    
+    
+    
 
 }
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/YangAndXmlToJsonConversionJsonReaderTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/YangAndXmlToJsonConversionJsonReaderTest.java
new file mode 100644 (file)
index 0000000..0f39088
--- /dev/null
@@ -0,0 +1,243 @@
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.*;
+import java.util.*;
+
+import org.junit.Test;
+
+import com.google.gson.stream.JsonReader;
+
+public class YangAndXmlToJsonConversionJsonReaderTest {
+
+    @Test
+    public void simpleYangTypesWithJsonReaderTest() {
+        String jsonOutput;
+        jsonOutput = TestUtils.readJsonFromFile("/yang-to-json-conversion/simple-yang-types/xml/awaited_output.json",
+                false);
+
+//        jsonOutput = TestUtils.convertXmlDataAndYangToJson("/yang-to-json-conversion/simple-yang-types/xml/data.xml",
+//                "/yang-to-json-conversion/simple-yang-types");
+        
+        StringReader strReader = new StringReader(jsonOutput);
+        JsonReader jReader = new JsonReader(strReader);
+        try {
+            checkCont1(jReader);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void checkCont1(JsonReader jReader) throws IOException {
+        jReader.beginObject();
+        assertNotNull("cont1 is missing.", jReader.hasNext());
+        jReader.nextName();
+        checkCont1Elements(jReader, prepareInputData(jReader), "cont1/");
+        jReader.endObject();
+
+    }
+
+    private Map<String, String> prepareInputData(JsonReader jReader) {
+        Map<String, String> dataMap = new HashMap<>();
+        dataMap.put("cont1/lf11", "lf");
+        dataMap.put("cont1/lflst11.1", "55");
+        dataMap.put("cont1/lflst11.2", "56");
+        dataMap.put("cont1/lflst11.3", "57");
+        dataMap.put("cont1/lflst12.1", "lflst12 str1");
+        dataMap.put("cont1/lflst12.2", "lflst12 str2");
+        dataMap.put("cont1/lflst12.3", "lflst12 str3");
+
+        dataMap.put("cont1/lst11.1/lf111", "140");
+        dataMap.put("cont1/lst11.1/lf112", "lf112 str");
+        dataMap.put("cont1/lst11.1/cont111/lf1111", "lf1111 str");
+        dataMap.put("cont1/lst11.1/cont111/lflst1111.1", "2048");
+        dataMap.put("cont1/lst11.1/cont111/lflst1111.2", "1024");
+        dataMap.put("cont1/lst11.1/cont111/lflst1111.3", "4096");
+        dataMap.put("cont1/lst11.1/cont111/lst1111.1/lf1111A", "lf1111A str11");
+        dataMap.put("cont1/lst11.1/cont111/lst1111.1/lf1111B", "4");
+        dataMap.put("cont1/lst11.1/cont111/lst1111.2/lf1111A", "lf1111A str12");
+        dataMap.put("cont1/lst11.1/cont111/lst1111.2/lf1111B", "7");
+        dataMap.put("cont1/lst11.1/lst111.1/lf1111", "65");
+        dataMap.put("cont1/lst11.1/lst112.1/lf1121", "lf1121 str11");
+
+        dataMap.put("cont1/lst11.2/lf111", "141");
+        dataMap.put("cont1/lst11.2/lf112", "lf112 str2");
+        dataMap.put("cont1/lst11.2/cont111/lf1111", "lf1111 str2");
+        dataMap.put("cont1/lst11.2/cont111/lflst1111.1", "2049");
+        dataMap.put("cont1/lst11.2/cont111/lflst1111.2", "1025");
+        dataMap.put("cont1/lst11.2/cont111/lflst1111.3", "4097");
+        dataMap.put("cont1/lst11.2/cont111/lst1111.1/lf1111A", "lf1111A str21");
+        dataMap.put("cont1/lst11.2/cont111/lst1111.1/lf1111B", "5");
+        dataMap.put("cont1/lst11.2/cont111/lst1111.2/lf1111A", "lf1111A str22");
+        dataMap.put("cont1/lst11.2/cont111/lst1111.2/lf1111B", "8");
+        dataMap.put("cont1/lst11.2/lst111.1/lf1111", "55");
+        dataMap.put("cont1/lst11.2/lst111.2/lf1111", "56");
+        dataMap.put("cont1/lst11.2/lst112.1/lf1121", "lf1121 str21");
+        dataMap.put("cont1/lst11.2/lst112.2/lf1121", "lf1121 str22");
+
+        return dataMap;
+
+    }
+
+    private void checkCont1Elements(JsonReader jReader, Map<String, String> dataMap, String pthPref) throws IOException {
+        Set<String> keys = new HashSet<>();
+        jReader.beginObject();
+        while (jReader.hasNext()) {
+            String keyName = jReader.nextName();
+            if (keyName.equals("lf11")) {
+                assertEquals("Key " + keyName + " has incorrect value.", dataMap.get(pthPref + keyName),
+                        jReader.nextString());
+                keys.add(keyName);
+            } else if (keyName.equals("lflst11")) {
+                checkLflstValues(jReader, pthPref + keyName, dataMap);
+                keys.add(keyName);
+            } else if (keyName.equals("lflst12")) {
+                checkLflstValues(jReader, pthPref + keyName, dataMap);
+                keys.add(keyName);
+            } else if (keyName.equals("lst11")) {
+                checkLst11(jReader, pthPref + keyName, dataMap);
+                keys.add(keyName);
+            } else {
+                assertTrue("Key " + keyName + " doesn't exists in yang file.", false);
+            }
+        }
+        jReader.endObject();
+        assertEquals("Incorrect number of keys in cont1", 4, keys.size());
+
+    }
+
+    private void checkLst11(JsonReader jReader, String pthPref, Map<String, String> dataMap) throws IOException {
+        jReader.beginArray();
+
+        int arrayLength = 0;
+        while (jReader.hasNext()) {
+            checkLst11Elements(jReader, pthPref + "." + ++arrayLength + "/", dataMap);
+        }
+        jReader.endArray();
+        assertEquals("Incorrect number of items in lst11 array.", 2, arrayLength);
+    }
+
+    private void checkLst11Elements(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginObject();
+        while (jReader.hasNext()) {
+            String keyName = jReader.nextName();
+            if (keyName.equals("lf111")) {
+                assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+            } else if (keyName.equals("lf112")) {
+                assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+            } else if (keyName.equals("cont111")) {
+                checkCont111(jReader, pthPref + keyName, data);
+            } else if (keyName.equals("lst111")) {
+                checkLst111(jReader, pthPref + keyName, data);
+            } else if (keyName.equals("lst112")) {
+                checkLst112(jReader, pthPref + keyName, data);
+            } else {
+                assertTrue("Key " + keyName + " doesn't exists in yang file.", false);
+            }
+        }
+        jReader.endObject();
+    }
+
+    private void checkLst112(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginArray();
+        int arrayIndex = 0;
+        while (jReader.hasNext()) {
+            checkLst112Elements(jReader, pthPref + "." + ++arrayIndex + "/", data);
+        }
+        jReader.endArray();
+    }
+
+    private void checkLst112Elements(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginObject();
+        if (jReader.hasNext()) {
+            String keyName = jReader.nextName();
+            assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+        }
+        jReader.endObject();
+
+    }
+
+    private void checkLst111(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginArray();
+        int arrayIndex = 0;
+        while (jReader.hasNext()) {
+            checkLst111Elements(jReader, pthPref + "." + ++arrayIndex + "/", data);
+        }
+        jReader.endArray();
+    }
+
+    private void checkLst111Elements(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginObject();
+        if (jReader.hasNext()) {
+            String keyName = jReader.nextName();
+            assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+        }
+        jReader.endObject();
+    }
+
+    private void checkCont111(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginObject();
+        checkCont111Elements(jReader, pthPref + "/", data);
+        jReader.endObject();
+    }
+
+    private void checkCont111Elements(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        while (jReader.hasNext()) {
+            String keyName = jReader.nextName();
+            if (keyName.equals("lf1111")) {
+                assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+            } else if (keyName.equals("lflst1111")) {
+                checkLflstValues(jReader, pthPref + keyName, data);
+            } else if (keyName.equals("lst1111")) {
+                checkLst1111(jReader, pthPref + keyName, data);
+            }
+        }
+
+    }
+
+    private void checkLst1111(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginArray();
+        int arrayIndex = 0;
+        while (jReader.hasNext()) {
+            checkLst1111Elements(jReader, pthPref + "." + ++arrayIndex + "/", data);
+        }
+        jReader.endArray();
+    }
+
+    private void checkLst1111Elements(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginObject();
+        while (jReader.hasNext()) {
+            String keyName = jReader.nextName();
+            if (keyName.equals("lf1111A")) {
+                assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+
+            } else if (keyName.equals("lf1111B")) {
+                assertEquals("Incorrect value for key " + keyName, data.get(pthPref + keyName), jReader.nextString());
+            }
+        }
+        jReader.endObject();
+    }
+
+    private void checkLflstValues(JsonReader jReader, String pthPref, Map<String, String> data) throws IOException {
+        jReader.beginArray();
+        int arrayIndex = 1;
+        String keyValue = null;
+        List<String> searchedValues = new ArrayList<>();
+        while ((keyValue = data.get(pthPref + "." + arrayIndex++)) != null) {
+            searchedValues.add(keyValue);
+        }
+
+        while (jReader.hasNext()) {
+            String value = jReader.nextString();
+            assertTrue("Value " + value + " of lflst " + pthPref + " wasn't found", searchedValues.contains(value));
+        }
+
+        jReader.endArray();
+    }
+
+
+
+}
@@ -1,22 +1,14 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
-import java.io.*;
-import java.util.Set;
-import java.util.regex.*;
+import java.util.regex.Pattern;
 
-import javax.ws.rs.WebApplicationException;
+import org.junit.Test;
 
-import org.junit.*;
-import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
-import org.opendaylight.controller.sal.restconf.impl.StructuredData;
-import org.opendaylight.yangtools.yang.model.api.*;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+public class YangAndXmlToJsonConversionRegExTest {
 
-public class YangAndXmlToJsonConversion {
-
-    @Ignore
     @Test
     /**
      * Test for simple yang types (leaf, list, leaf-list, container and various combination of them)
@@ -25,15 +17,14 @@ public class YangAndXmlToJsonConversion {
     public void simpleYangTypesTest() {
         String jsonOutput = null;
 
-        jsonOutput = convertXmlDataAndYangToJson("/yang-to-json-conversion/simple-yang-types/xml/data.xml",
-                "/yang-to-json-conversion/simple-yang-types");
+//        jsonOutput = TestUtils.convertXmlDataAndYangToJson("/yang-to-json-conversion/simple-yang-types/xml/data.xml",
+//                "/yang-to-json-conversion/simple-yang-types");
 
-//         jsonOutput =
-//         readJsonFromFile("/yang-to-json-conversion/simple-yang-types/xml/output.json");
+         jsonOutput =
+         TestUtils.readJsonFromFile("/yang-to-json-conversion/simple-yang-types/xml/awaited_output.json",true);
 
         verifyJsonOutputForSimpleYangTypes(jsonOutput);
-
-    }
+    }    
 
     private void verifyJsonOutputForSimpleYangTypes(String jsonOutput) {
 
@@ -149,125 +140,69 @@ public class YangAndXmlToJsonConversion {
         return null;
     }
 
-    private String readJsonFromFile(String path) {
-        String fullPath = YangAndXmlToJsonConversion.class.getResource(path).getPath();
-        assertNotNull("Path to file can't be null.", fullPath);
-        File file = new File(fullPath);
-        assertNotNull("File can't be null", file);
-        FileReader fileReader = null;
-        try {
-            fileReader = new FileReader(file);
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-        }
-        assertNotNull("File reader can't be null.", fileReader);
-
-        StringBuilder strBuilder = new StringBuilder();
-        char[] buffer = new char[1000];
-
-        while (true) {
-            int loadedCharNum;
-            try {
-                loadedCharNum = fileReader.read(buffer);
-            } catch (IOException e) {
-                break;
-            }
-            if (loadedCharNum == -1) {
-                break;
-            }
-            strBuilder.append(buffer, 0, loadedCharNum);
-        }
-        try {
-            fileReader.close();
-        } catch (IOException e) {
-            System.out.println("The file wasn't closed");
-            ;
-        }
-        String rawStr = strBuilder.toString();
-        rawStr = rawStr.replace("\n", "");
-        rawStr = rawStr.replace("\r", "");
-        rawStr = rawStr.replace("\t", "");
-        rawStr = removeSpaces(rawStr);
-
-        return rawStr;
-    }
-
-    private String removeSpaces(String rawStr) {
-        StringBuilder strBuilder = new StringBuilder();
-        int i = 0;
-        int quoteCount = 0;
-        while (i < rawStr.length()) {
-            if (rawStr.substring(i, i + 1).equals("\"")) {
-                quoteCount++;
-            }
 
-            if (!rawStr.substring(i, i + 1).equals(" ") || (quoteCount % 2 == 1)) {
-                strBuilder.append(rawStr.charAt(i));
-            }
-            i++;
-        }
-
-        return strBuilder.toString();
-    }
 
-    private String convertXmlDataAndYangToJson(String xmlDataPath, String yangPath) {
-        String jsonResult = null;
-        Set<Module> modules = null;
 
-        try {
-            modules = TestUtils.loadModules(YangAndXmlToJsonConversion.class.getResource(yangPath).getPath());
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-        }
-        assertNotNull("modules can't be null.", modules);
-
-        InputStream xmlStream = YangAndXmlToJsonConversion.class.getResourceAsStream(xmlDataPath);
-        CompositeNode compositeNode = null;
-        try {
-            compositeNode = TestUtils.loadCompositeNode(xmlStream);
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
-        }
-        assertNotNull("Composite node can't be null", compositeNode);
+//    private String convertXmlDataAndYangToJson(String xmlDataPath, String yangPath) {
+//        String jsonResult = null;
+//        Set<Module> modules = null;
+//
+//        try {
+//            modules = TestUtils.loadModules(YangAndXmlToJsonConversionJsonReaderTest.class.getResource(yangPath).getPath());
+//        } catch (FileNotFoundException e) {
+//            e.printStackTrace();
+//        }
+//        assertNotNull("modules can't be null.", modules);
+//
+//        InputStream xmlStream = YangAndXmlToJsonConversionJsonReaderTest.class.getResourceAsStream(xmlDataPath);
+//        CompositeNode compositeNode = null;
+//        try {
+//            compositeNode = TestUtils.loadCompositeNode(xmlStream);
+//        } catch (FileNotFoundException e) {
+//            e.printStackTrace();
+//        }
+//        assertNotNull("Composite node can't be null", compositeNode);
+//
+//        StructuredDataToJsonProvider structuredDataToJsonProvider = StructuredDataToJsonProvider.INSTANCE;
+//        for (Module module : modules) {
+//            for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
+//                StructuredData structuredData = new StructuredData(compositeNode, dataSchemaNode);
+//                ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
+//                try {
+//                    structuredDataToJsonProvider.writeTo(structuredData, null, null, null, null, null, byteArrayOS);
+//                } catch (WebApplicationException | IOException e) {
+//                    e.printStackTrace();
+//                }
+//                assertFalse(
+//                        "Returning JSON string can't be empty for node " + dataSchemaNode.getQName().getLocalName(),
+//                        byteArrayOS.toString().isEmpty());
+//                jsonResult = byteArrayOS.toString();
+//                try {
+//                    outputToFile(byteArrayOS);
+//                } catch (IOException e) {
+//                    System.out.println("Output file wasn't cloased sucessfuly.");
+//                }
+//            }
+//        }
+//        return jsonResult;
+//    }
+//
+//    private void outputToFile(ByteArrayOutputStream outputStream) throws IOException {
+//        FileOutputStream fileOS = null;
+//        try {
+//            String path = YangAndXmlToJsonConversionJsonReaderTest.class.getResource("/yang-to-json-conversion/xml").getPath();
+//            File outFile = new File(path + "/data.json");
+//            fileOS = new FileOutputStream(outFile);
+//            try {
+//                fileOS.write(outputStream.toByteArray());
+//            } catch (IOException e) {
+//                e.printStackTrace();
+//            }
+//            fileOS.close();
+//        } catch (FileNotFoundException e1) {
+//            e1.printStackTrace();
+//        }
+//    }
+    
 
-        StructuredDataToJsonProvider structuredDataToJsonProvider = StructuredDataToJsonProvider.INSTANCE;
-        for (Module module : modules) {
-            for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
-                StructuredData structuredData = new StructuredData(compositeNode, dataSchemaNode);
-                ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
-                try {
-                    structuredDataToJsonProvider.writeTo(structuredData, null, null, null, null, null, byteArrayOS);
-                } catch (WebApplicationException | IOException e) {
-                    e.printStackTrace();
-                }
-                assertFalse(
-                        "Returning JSON string can't be empty for node " + dataSchemaNode.getQName().getLocalName(),
-                        byteArrayOS.toString().isEmpty());
-                jsonResult = byteArrayOS.toString();
-                try {
-                    outputToFile(byteArrayOS);
-                } catch (IOException e) {
-                    System.out.println("Output file wasn't cloased sucessfuly.");
-                }
-            }
-        }
-        return jsonResult;
-    }
-
-    private void outputToFile(ByteArrayOutputStream outputStream) throws IOException {
-        FileOutputStream fileOS = null;
-        try {
-            String path = YangAndXmlToJsonConversion.class.getResource("/yang-to-json-conversion/xml").getPath();
-            File outFile = new File(path + "/data.json");
-            fileOS = new FileOutputStream(outFile);
-            try {
-                fileOS.write(outputStream.toByteArray());
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-            fileOS.close();
-        } catch (FileNotFoundException e1) {
-            e1.printStackTrace();
-        }
-    }
 }
index e76e7bd9ef4f20c5405ef8a71046fcd504047d18..a0e5f2f0f2b804d182b9b1f1c310f61e150e9718 100644 (file)
                         "lf1111B": 7
                     }
                     ]
-                }
+                },
+                "lst111" : [
+                {
+                       "lf1111" : 65
+                       }
+                       ],
+                       "lst112" : [
+                       {
+                       "lf1121" : "lf1121 str11"
+                       }
+                       ]
+                
             },
             {
                 "lf111":141,
                         "lf1111B": 8
                     }
                     ]
-                }
+                },
+                "lst111" : [
+                {
+                       "lf1111" : 55
+                       },
+                {
+                       "lf1111" : 56
+                       }
+                       ],
             }        
         ]
+                       "lst112" : [
+                       {
+                       "lf1121" : "lf1121 str21"
+                       },
+                       {
+                       "lf1121" : "lf1121 str22"
+                       }
+                       ]
+            }
+            ]
     }
 }
\ No newline at end of file