Additional test for instance-identifier 22/5022/4
authorJozef Gloncak <jgloncak@cisco.com>
Mon, 27 Jan 2014 14:19:35 +0000 (15:19 +0100)
committerJozef Gloncak <jgloncak@cisco.com>
Fri, 31 Jan 2014 14:56:13 +0000 (15:56 +0100)
- test for instance identifier
- correction of ignored test (adding revisions to wrong tests)
- instance identifier with leaflist predicate:
-- serialize codec
-- XML output
-- JSON output

Change-Id: Iae4ee2f2ff3c1b3445958f1d69673df9f56b0e2a
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnJsonBasicYangTypesTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonIdentityrefTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithDataFromSeveralModulesTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnInstanceIdentifierToXmlTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java
opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/json/jsondata_leaf_list.json [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/xml/xmldata_leaf_list.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/yang/augment-module-leaf-list.yang [new file with mode: 0644]

index 318159063ab481454298b738d3fc8ceb18b7fdff..874e8b0d1f8f5e7cf151a4c548624b01d72576a5 100644 (file)
@@ -21,7 +21,6 @@ import java.util.Set;
 import javax.ws.rs.WebApplicationException;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
@@ -52,7 +51,7 @@ public class CnSnJsonBasicYangTypesTest extends YangAndXmlAndDataSchemaLoader {
      * Test of json output when as input are specified composite node with empty
      * data + YANG file
      */
-    @Ignore
+
     @Test
     public void compositeNodeAndYangWithJsonReaderEmptyDataTest() {
         CompositeNode compositeNode = prepareCompositeNodeWithEmpties();
@@ -540,49 +539,49 @@ public class CnSnJsonBasicYangTypesTest extends YangAndXmlAndDataSchemaLoader {
                 TestUtils.buildQName("cont1", "simple:yang:types", "2013-11-5"), null, null, ModifyAction.CREATE, null);
 
         // lst11_1
-        MutableCompositeNode lst11_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11"), cont1,
+        MutableCompositeNode lst11_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11","simple:yang:types","2013-11-5"), cont1,
                 null, ModifyAction.CREATE, null);
         cont1.getChildren().add(lst11_1);
 
-        MutableSimpleNode<?> lf111_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_1,
+        MutableSimpleNode<?> lf111_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111","simple:yang:types","2013-11-5"), lst11_1,
                 (short) 1, ModifyAction.CREATE, null);
         lst11_1.getChildren().add(lf111_1);
 
         // lst111_1_1
-        MutableCompositeNode lst111_1_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+        MutableCompositeNode lst111_1_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
                 lst11_1, null, ModifyAction.CREATE, null);
         lst11_1.getChildren().add(lst111_1_1);
-        MutableSimpleNode<?> lf1111_1_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111"),
+        MutableSimpleNode<?> lf1111_1_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111","simple:yang:types","2013-11-5"),
                 lst111_1_1, (int) 34, ModifyAction.CREATE, null);
         lst111_1_1.getChildren().add(lf1111_1_1);
         lst111_1_1.init();
         // :lst111_1_1
 
         // lst111_1_2
-        MutableCompositeNode lst111_1_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+        MutableCompositeNode lst111_1_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
                 lst11_1, null, ModifyAction.CREATE, null);
         lst11_1.getChildren().add(lst111_1_2);
-        MutableSimpleNode<?> lf1111_1_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111"),
+        MutableSimpleNode<?> lf1111_1_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111","simple:yang:types","2013-11-5"),
                 lst111_1_2, (int) 35, ModifyAction.CREATE, null);
         lst111_1_2.getChildren().add(lf1111_1_2);
         lst111_1_2.init();
         // :lst111_1_2
 
         // lst111_1_3
-        MutableCompositeNode lst111_1_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+        MutableCompositeNode lst111_1_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
                 lst11_1, null, ModifyAction.CREATE, null);
         lst11_1.getChildren().add(lst111_1_3);
         lst111_1_2.init();
         // :lst111_1_3
 
         // lst111_1_4
-        MutableCompositeNode lst111_1_4 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+        MutableCompositeNode lst111_1_4 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
                 lst11_1, null, ModifyAction.CREATE, null);
         lst11_1.getChildren().add(lst111_1_4);
         lst111_1_2.init();
         // :lst111_1_4
 
-        MutableCompositeNode cont111_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111"),
+        MutableCompositeNode cont111_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111","simple:yang:types","2013-11-5"),
                 lst11_1, null, ModifyAction.CREATE, null);
         lst11_1.getChildren().add(cont111_1);
 
@@ -590,39 +589,39 @@ public class CnSnJsonBasicYangTypesTest extends YangAndXmlAndDataSchemaLoader {
         // :lst11_1
 
         // lst11_2
-        MutableCompositeNode lst11_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11"), cont1,
+        MutableCompositeNode lst11_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11","simple:yang:types","2013-11-5"), cont1,
                 null, ModifyAction.CREATE, null);
         cont1.getChildren().add(lst11_2);
 
-        MutableSimpleNode<?> lf111_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_2,
+        MutableSimpleNode<?> lf111_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111","simple:yang:types","2013-11-5"), lst11_2,
                 (short) 2, ModifyAction.CREATE, null);
         lst11_2.getChildren().add(lf111_2);
 
         // cont111_2
-        MutableCompositeNode cont111_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111"),
+        MutableCompositeNode cont111_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111","simple:yang:types","2013-11-5"),
                 lst11_2, null, ModifyAction.CREATE, null);
         lst11_2.getChildren().add(cont111_2);
 
-        MutableSimpleNode<?> lflst1111_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111"),
+        MutableSimpleNode<?> lflst1111_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111","simple:yang:types","2013-11-5"),
                 cont111_2, (int) 1024, ModifyAction.CREATE, null);
         cont111_2.getChildren().add(lflst1111_2_2);
-        MutableSimpleNode<?> lflst1111_2_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111"),
+        MutableSimpleNode<?> lflst1111_2_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111","simple:yang:types","2013-11-5"),
                 cont111_2, (int) 4096, ModifyAction.CREATE, null);
         cont111_2.getChildren().add(lflst1111_2_3);
 
         // lst1111_2
-        MutableCompositeNode lst1111_2_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+        MutableCompositeNode lst1111_2_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
                 cont111_2, null, ModifyAction.CREATE, null);
         cont111_2.getChildren().add(lst1111_2_1);
-        MutableSimpleNode<?> lf1111B_2_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111B"),
+        MutableSimpleNode<?> lf1111B_2_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111B","simple:yang:types","2013-11-5"),
                 lst1111_2_1, (short) 4, ModifyAction.CREATE, null);
         lst1111_2_1.getChildren().add(lf1111B_2_1);
         lst1111_2_1.init();
 
-        MutableCompositeNode lst1111_2_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+        MutableCompositeNode lst1111_2_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
                 cont111_2, null, ModifyAction.CREATE, null);
         cont111_2.getChildren().add(lst1111_2_2);
-        MutableSimpleNode<?> lf1111A_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111A"),
+        MutableSimpleNode<?> lf1111A_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111A","simple:yang:types","2013-11-5"),
                 lst1111_2_2, "lf1111A str12", ModifyAction.CREATE, null);
         lst1111_2_2.getChildren().add(lf1111A_2_2);
         lst1111_2_2.init();
@@ -631,7 +630,7 @@ public class CnSnJsonBasicYangTypesTest extends YangAndXmlAndDataSchemaLoader {
         cont111_2.init();
         // :cont111_2
 
-        MutableCompositeNode lst112_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst112"), lst11_2,
+        MutableCompositeNode lst112_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst112","simple:yang:types","2013-11-5"), lst11_2,
                 null, ModifyAction.CREATE, null);
         lst11_2.getChildren().add(lst112_2);
         lst112_2.init();
@@ -640,25 +639,25 @@ public class CnSnJsonBasicYangTypesTest extends YangAndXmlAndDataSchemaLoader {
         // :lst11_2
 
         // lst11_3
-        MutableCompositeNode lst11_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11"), cont1,
+        MutableCompositeNode lst11_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11","simple:yang:types","2013-11-5"), cont1,
                 null, ModifyAction.CREATE, null);
         cont1.getChildren().add(lst11_3);
 
-        MutableSimpleNode<?> lf111_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_3,
+        MutableSimpleNode<?> lf111_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111","simple:yang:types","2013-11-5"), lst11_3,
                 (short) 3, ModifyAction.CREATE, null);
         lst11_3.getChildren().add(lf111_3);
 
         // cont111_3
-        MutableCompositeNode cont111_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111"),
+        MutableCompositeNode cont111_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111","simple:yang:types","2013-11-5"),
                 lst11_3, null, ModifyAction.CREATE, null);
         lst11_3.getChildren().add(cont111_3);
 
-        MutableCompositeNode lst1111_3_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+        MutableCompositeNode lst1111_3_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
                 cont111_3, null, ModifyAction.CREATE, null);
         cont111_3.getChildren().add(lst1111_3_1);
         lst1111_3_1.init();
 
-        MutableCompositeNode lst1111_3_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+        MutableCompositeNode lst1111_3_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
                 cont111_3, null, ModifyAction.CREATE, null);
         cont111_3.getChildren().add(lst1111_3_2);
         lst1111_3_2.init();
index 392f444cf2def8ae783c4dba0fa95b0d740746d3..745f11c210db6c44f90ba97ccacfd6624dc1eb4e 100644 (file)
@@ -17,13 +17,15 @@ import java.util.regex.Pattern;
 import javax.ws.rs.WebApplicationException;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 
 public class CnSnToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
@@ -33,7 +35,6 @@ public class CnSnToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
         dataLoad("/cnsn-to-json/identityref", 2, "identityref-module", "cont");
     }
 
-    @Ignore
     @Test
     public void identityrefToJsonTest() {
         String json = null;
@@ -53,7 +54,6 @@ public class CnSnToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
         assertTrue(mtch.matches());
     }
 
-    @Ignore
     @Test
     public void identityrefToJsonWithoutQNameTest() {
         String json = null;
@@ -74,13 +74,13 @@ public class CnSnToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
     }
 
     private CompositeNode prepareCompositeNode(Object value) {
-        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
+        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont","identityref:module","2013-12-2"), null, null,
                 ModifyAction.CREATE, null);
-        MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1"), cont, null,
+        MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1","identityref:module","2013-12-2"), cont, null,
                 ModifyAction.CREATE, null);
         cont.getChildren().add(cont1);
 
-        MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont1, value,
+        MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1","identityref:module","2013-12-2"), cont1, value,
                 ModifyAction.CREATE, null);
 
         cont1.getChildren().add(lf1);
index d1dca95f43418c4e4a1e34b820ae4e67f6aeeee0..17d7fe6be09eaa18f48ac5831527fc58076dbe18 100644 (file)
@@ -20,8 +20,13 @@ import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
-import org.opendaylight.controller.sal.restconf.impl.test.*;
-import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
+import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
+import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -39,20 +44,13 @@ public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLo
         dataLoad("/cnsn-to-json/simple-data-types");
     }
 
-    // FIXME
-    @Ignore
     @Test
-    public void incorrectTopLevelElementTest() {
-
+    public void incorrectTopLevelElementTest() throws WebApplicationException, IOException {
         String jsonOutput = null;
-        try {
-            jsonOutput = TestUtils
-                    .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
-                            (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
-                            StructuredDataToJsonProvider.INSTANCE);
-        } catch (WebApplicationException | IOException e) {
-            LOG.error("WebApplicationException or IOException was raised");
-        }
+        jsonOutput = TestUtils
+                .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
+                        (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
+                        StructuredDataToJsonProvider.INSTANCE);
         assertNotNull(jsonOutput);
         assertTrue(jsonOutput.contains("\"lf1\": \"\""));
     }
index 54664ae069a98e8ccc7dc120767e0e74dd570ec2..348edbd2945d6d1fb2f86ea0d1e3026a81132c47 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -18,40 +17,38 @@ import java.util.regex.Pattern;
 import javax.ws.rs.WebApplicationException;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
-import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
-import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
-import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader {
 
     @BeforeClass
     public static void initialize() {
-        dataLoad("/xml-to-cnsn/data-of-several-modules/yang",2,"module1","cont_m1");
+        dataLoad("/xml-to-cnsn/data-of-several-modules/yang", 2, "module1", "cont_m1");
     }
 
-    @Ignore
     @Test
     public void dataFromSeveralModulesToJsonTest() throws WebApplicationException, IOException, URISyntaxException {
         SchemaContext schemaContext = TestUtils.loadSchemaContext(modules);
         String output = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCnSn(), modules, schemaContext,
                 StructuredDataToJsonProvider.INSTANCE);
 
-//         String output =
-//         String.format("\"data\"   :   {\n" +
-//                             "\t\"cont_m1\"   :  {\n" +
-//                                 "\t\t\"lf1_m1\"   :  \"lf1 m1 value\"\n" +
-//                             "\t}\n" +
-//                             "\t\"cont_m2\"   :  {\n" +
-//                                 "\t\t\"lf1_m2\"   :  \"lf1 m2 value\"\n" +
-//                             "\t}\n" +
-//                     "}");
+        // String output =
+        // String.format("\"data\"   :   {\n" +
+        // "\t\"cont_m1\"   :  {\n" +
+        // "\t\t\"lf1_m1\"   :  \"lf1 m1 value\"\n" +
+        // "\t}\n" +
+        // "\t\"cont_m2\"   :  {\n" +
+        // "\t\t\"lf1_m2\"   :  \"lf1 m2 value\"\n" +
+        // "\t}\n" +
+        // "}");
 
         StringBuilder regex = new StringBuilder();
         regex.append("^");
@@ -59,27 +56,27 @@ public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataS
         regex.append(".*\"data\"");
         regex.append(".*:");
         regex.append(".*\\{");
-        
-        regex.append(".*\"contB_m1\"");
+
+        regex.append(".*\"cont_m1\"");
         regex.append(".*:");
         regex.append(".*\\{");
         regex.append(".*\\}");
-        
-        regex.append(".*\"cont_m1\"");
+
+        regex.append(".*\"contB_m1\"");
         regex.append(".*:");
         regex.append(".*\\{");
         regex.append(".*\\}");
 
-        regex.append(".*\"contB_m2\"");
+        regex.append(".*\"cont_m2\"");
         regex.append(".*:");
         regex.append(".*\\{");
         regex.append(".*\\}");
-        
-        regex.append(".*\"cont_m2\"");
+
+        regex.append(".*\"contB_m2\"");
         regex.append(".*:");
         regex.append(".*\\{");
         regex.append(".*\\}");
-        
+
         regex.append(".*\\}");
 
         regex.append(".*");
@@ -93,24 +90,44 @@ public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataS
     }
 
     private CompositeNode prepareCnSn() throws URISyntaxException {
-        CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data");
-
-        URI uriModule1 = new URI("module:one");
-        CompositeNodeWrapper cont_m1 = new CompositeNodeWrapper(uriModule1, "cont_m1");
-        SimpleNodeWrapper lf1_m1 = new SimpleNodeWrapper(uriModule1, "lf1_m1", "lf1 m1 value");
-        cont_m1.addValue(lf1_m1);
-        CompositeNodeWrapper contB_m1 = new CompositeNodeWrapper(uriModule1, "contB_m1");
-        
-        data.addValue(contB_m1);
-        data.addValue(cont_m1);
-
-        URI uriModule2 = new URI("module:two");
-        CompositeNodeWrapper cont_m2 = new CompositeNodeWrapper(uriModule2, "cont_m2");
-        SimpleNodeWrapper lf1_m2 = new SimpleNodeWrapper(uriModule2, "lf1_m2", "lf1 m2 value");
-        cont_m2.addValue(lf1_m2);
-        CompositeNodeWrapper contB_m2 = new CompositeNodeWrapper(uriModule2, "contB_m2");
-        data.addValue(contB_m2);
-        data.addValue(cont_m2);
+        String uri1 = "module:one";
+        String rev1 = "2014-01-17";
+
+        MutableCompositeNode data = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("data", "urn:ietf:params:xml:ns:netconf:base:1.0", "2000-01-01"), null, null,
+                null, null);
+
+        MutableCompositeNode cont_m1 = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("cont_m1", uri1, rev1), data, null, null, null);
+        data.getChildren().add(cont_m1);
+
+        MutableSimpleNode<?> lf1_m1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1_m1", uri1, rev1),
+                cont_m1, "lf1 m1 value", null, null);
+        cont_m1.getChildren().add(lf1_m1);
+        cont_m1.init();
+
+        MutableCompositeNode contB_m1 = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("contB_m1", uri1, rev1), data, null, null, null);
+        data.getChildren().add(contB_m1);
+        contB_m1.init();
+
+        String uri2 = "module:two";
+        String rev2 = "2014-01-17";
+        MutableCompositeNode cont_m2 = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("cont_m2", uri2, rev2), data, null, null, null);
+        data.getChildren().add(cont_m2);
+
+        MutableSimpleNode<?> lf1_m2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1_m2", uri2, rev2),
+                cont_m1, "lf1 m2 value", null, null);
+        cont_m2.getChildren().add(lf1_m2);
+        cont_m2.init();
+
+        MutableCompositeNode contB_m2 = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("contB_m2", uri2, rev2), data, null, null, null);
+        data.getChildren().add(contB_m2);
+        contB_m2.init();
+
+        data.init();
         return data;
     }
 
index 5a81b326ab30a130bce2c0265f425166115e60fa..92de14bba4a730406f4a58b4e738b618cc05bf3b 100644 (file)
@@ -35,7 +35,7 @@ public class CnSnInstanceIdentifierToXmlTest extends YangAndXmlAndDataSchemaLoad
     
     @BeforeClass
     public static void initialization() throws URISyntaxException {
-        dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
+        dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
     }
 
     @Test
index 9723af7671e41dc75fd5de5521bee3fa6606817a..18b5ce490ff137f7da978052a09819a6a5b4e1d1 100644 (file)
@@ -32,41 +32,83 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
-import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
-import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 
 public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
 
     @BeforeClass
     public static void initialize() {
-        dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
+        dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
     }
 
     @Test
-    public void saveCnSnToXml() throws WebApplicationException, IOException, URISyntaxException, XMLStreamException {
-        CompositeNode cnSn = prepareCnSn();
+    public void saveCnSnToXmlTest() throws WebApplicationException, IOException, URISyntaxException, XMLStreamException {
+        CompositeNode cnSn = prepareCnSn(createInstanceIdentifier());
         String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
                 StructuredDataToXmlProvider.INSTANCE);
-        validateXmlOutput(output);
+        //uncomment for debug
         // System.out.println(output);
+        validateXmlOutput(output);
 
     }
 
     @Ignore
     @Test
-    public void saveCnSnToJson() throws WebApplicationException, IOException, URISyntaxException {
-        CompositeNode cnSn = prepareCnSn();
+    public void saveCnSnWithLeafListInstIdentifierToXmlTest() throws WebApplicationException, IOException,
+            URISyntaxException, XMLStreamException {
+        CompositeNode cnSn = prepareCnSn(createInstanceIdentifierWithLeafList());
+        String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
+                StructuredDataToXmlProvider.INSTANCE);
+        //uncomment for debug
+        // System.out.println(output);
+        validateXmlOutputWithLeafList(output);
+    }
+
+    @Test
+    public void saveCnSnToJsonTest() throws WebApplicationException, IOException, URISyntaxException {
+        CompositeNode cnSn = prepareCnSn(createInstanceIdentifier());
         String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
                 StructuredDataToJsonProvider.INSTANCE);
-        assertTrue(output
-                .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module:lst11[augment-module:keyvalue111=\\\"value1\\\"][augment-module:keyvalue112=\\\"value2\\\"]/augment-augment-module:lf112\""));
+        boolean strInOutput = false;
+        strInOutput = output
+                .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module:lst11[augment-module:keyvalue111=\\\"value1\\\"][augment-module:keyvalue112=\\\"value2\\\"]/augment-augment-module:lf112\"");
+
+        if (!strInOutput) {
+            strInOutput = output
+                    .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module:lst11[augment-module:keyvalue111='value1'][augment-module:keyvalue112='value2']/augment-augment-module:lf112\"");
+        }
+        //uncomment for debug
         // System.out.println(output);
+        assertTrue(strInOutput);
+    }
+
+
+    @Test
+    public void saveCnSnWithLeafListInstIdentifierToJsonTest() throws WebApplicationException, IOException,
+            URISyntaxException {
+        CompositeNode cnSn = prepareCnSn(createInstanceIdentifierWithLeafList());
+        String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
+                StructuredDataToJsonProvider.INSTANCE);
+        //uncomment for debug
+        // System.out.println(output);
+        boolean strInOutput = false;
+        strInOutput = output
+                .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module-leaf-list:lflst11[.='lflst11_1']\"");
+        if (!strInOutput) {
+            strInOutput = output
+                    .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module-leaf-list:lflst11[.=\\\"lflst11_1\\\"]\"");
+        }
+
+        assertTrue(strInOutput);
     }
 
     private void validateXmlOutput(String xml) throws XMLStreamException {
@@ -106,21 +148,66 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch
                 + ":lst11[" + aModulePrefix + ":keyvalue111='value1'][" + aModulePrefix + ":keyvalue112='value2']/"
                 + aaModulePrefix + ":lf112";
 
-//        System.out.println(xml);
         assertTrue(xml.contains(instanceIdentifierValue));
 
     }
 
-    private CompositeNode prepareCnSn() throws URISyntaxException {
-        CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("instance:identifier:module"), "cont");
-        CompositeNodeWrapper cont1 = new CompositeNodeWrapper(new URI("instance:identifier:module"), "cont1");
-        CompositeNodeWrapper lst11 = new CompositeNodeWrapper(new URI("augment:module"), "lst11");
-        InstanceIdentifier instanceIdentifier = createInstanceIdentifier();
-        SimpleNodeWrapper lf111 = new SimpleNodeWrapper(new URI("augment:augment:module"), "lf111", instanceIdentifier);
+    private void validateXmlOutputWithLeafList(String xml) throws XMLStreamException {
+        XMLInputFactory xmlInFactory = XMLInputFactory.newInstance();
+        XMLEventReader eventReader;
 
-        lst11.addValue(lf111);
-        cont1.addValue(lst11);
-        cont.addValue(cont1);
+        eventReader = xmlInFactory.createXMLEventReader(new ByteArrayInputStream(xml.getBytes()));
+        String aModuleLfLstPrefix = null;
+        String iiModulePrefix = null;
+        while (eventReader.hasNext()) {
+            XMLEvent nextEvent = eventReader.nextEvent();
+            if (nextEvent.isStartElement()) {
+                StartElement startElement = (StartElement) nextEvent;
+                if (startElement.getName().getLocalPart().equals("lf111")) {
+                    Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:module:leaf:list");
+
+                    while (prefixes.hasNext() && aModuleLfLstPrefix == null) {
+                        String prefix = (String) prefixes.next();
+                        if (!prefix.isEmpty()) {
+                            aModuleLfLstPrefix = prefix;
+                        }
+                    }
+                    iiModulePrefix = startElement.getNamespaceContext().getPrefix("instance:identifier:module");
+                    break;
+                }
+            }
+        }
+
+        assertNotNull(aModuleLfLstPrefix);
+        assertNotNull(iiModulePrefix);
+
+        String instanceIdentifierValue = "/" + iiModulePrefix + ":cont/" + iiModulePrefix + ":cont1/"
+                + aModuleLfLstPrefix + ":lflst11[.='lflst11_1']";
+
+        assertTrue(xml.contains(instanceIdentifierValue));
+
+    }
+
+    private CompositeNode prepareCnSn(InstanceIdentifier instanceIdentifier) throws URISyntaxException {
+        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("cont", "instance:identifier:module", "2014-01-17"), null, null,null,null);
+        MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("cont1", "instance:identifier:module", "2014-01-17"), cont, null,null,null);
+        MutableCompositeNode lst11 = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("lst11", "augment:module", "2014-01-17"), cont1, null,null,null);
+
+        MutableSimpleNode<?> lf111 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111", "augment:augment:module", "2014-01-17"),
+                lst11, instanceIdentifier,null,null);
+        
+        
+        lst11.getChildren().add(lf111);
+        lst11.init();
+
+        cont1.getChildren().add(lst11);
+        cont1.init();
+        
+        cont.getChildren().add(cont1);
+        cont.init();
 
         return cont;
     }
@@ -142,4 +229,13 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch
         return new InstanceIdentifier(pathArguments);
     }
 
+    private InstanceIdentifier createInstanceIdentifierWithLeafList() throws URISyntaxException {
+        List<PathArgument> pathArguments = new ArrayList<>();
+        pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont")));
+        pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont1")));
+        pathArguments.add(new NodeWithValue(new QName(new URI("augment:module:leaf:list"), "lflst11"), "lflst11_1"));
+
+        return new InstanceIdentifier(pathArguments);
+    }
+
 }
index e8d03fbe39193afdbbab632c4acf6d74f1bd9a76..5476d71320e9ae7a3a0fce6a9ec87f8dfe80088f 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 
@@ -33,7 +34,7 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
 
     @BeforeClass
     public static void initialize() {
-        dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
+        dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
     }
 
     @Test
@@ -41,7 +42,15 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata.xml",
                 XmlToCompositeNodeProvider.INSTANCE);
         TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
-        verify(cnSn);
+        verifyListPredicate(cnSn);
+    }
+
+    @Test
+    public void loadXmlLeafListToCnSn() throws WebApplicationException, IOException, URISyntaxException {
+        CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata_leaf_list.xml",
+                XmlToCompositeNodeProvider.INSTANCE);
+        TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
+        verifyLeafListPredicate(cnSn);
     }
 
     @Test
@@ -49,11 +58,40 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata.json",
                 JsonToCompositeNodeProvider.INSTANCE);
         TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
-        verify(cnSn);
+        verifyListPredicate(cnSn);
     }
 
-    private void verify(CompositeNode cnSn) throws URISyntaxException {
-        SimpleNode<?> lf111 = getSnWithInstanceIdentifier(cnSn);
+    @Test
+    public void loadJsonLeafListToCnSn() throws WebApplicationException, IOException, URISyntaxException {
+        CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata_leaf_list.json",
+                JsonToCompositeNodeProvider.INSTANCE);
+        TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
+        verifyLeafListPredicate(cnSn);
+    }
+
+    private void verifyLeafListPredicate(CompositeNode cnSn) throws URISyntaxException {
+        SimpleNode<?> lf11 = getSnWithInstanceIdentifierWhenLeafList(cnSn);
+        Object value = lf11.getValue();
+        assertTrue(value instanceof InstanceIdentifier);
+
+        InstanceIdentifier instanceIdentifier = (InstanceIdentifier) value;
+        List<PathArgument> pathArguments = instanceIdentifier.getPath();
+        assertEquals(3, pathArguments.size());
+        String revisionDate = "2014-01-17";
+        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
+                .getNodeType());
+        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
+                .getNodeType());
+        assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), pathArguments.get(2)
+                .getNodeType());
+
+        assertTrue(pathArguments.get(2) instanceof NodeWithValue);
+        assertEquals("lflst11_1", ((NodeWithValue) pathArguments.get(2)).getValue());
+
+    }
+
+    private void verifyListPredicate(CompositeNode cnSn) throws URISyntaxException {
+        SimpleNode<?> lf111 = getSnWithInstanceIdentifierWhenList(cnSn);
         Object value = lf111.getValue();
         assertTrue(value instanceof InstanceIdentifier);
 
@@ -76,7 +114,7 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
     }
 
-    private SimpleNode<?> getSnWithInstanceIdentifier(CompositeNode cnSn) throws URISyntaxException {
+    private SimpleNode<?> getSnWithInstanceIdentifierWhenList(CompositeNode cnSn) throws URISyntaxException {
         CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
                 "2014-01-17"));
         assertNotNull(cont1);
@@ -89,4 +127,14 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         return lf111;
     }
 
+    private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(CompositeNode cnSn) throws URISyntaxException {
+        CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
+                "2014-01-17"));
+        assertNotNull(cont1);
+        SimpleNode<?> lf11 = cont1.getFirstSimpleByName(TestUtils.buildQName("lf11", "augment:module:leaf:list",
+                "2014-01-27"));
+        assertNotNull(lf11);
+        return lf11;
+    }
+
 }
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/json/jsondata_leaf_list.json b/opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/json/jsondata_leaf_list.json
new file mode 100644 (file)
index 0000000..63be4b9
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "instance-identifier-module:cont": {
+        "cont1": {
+            "augment-module-leaf-list:lf11" : "/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module-leaf-list:lflst11[.=\"lflst11_1\"]"
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/xml/xmldata_leaf_list.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/xml/xmldata_leaf_list.xml
new file mode 100644 (file)
index 0000000..00d58c2
--- /dev/null
@@ -0,0 +1,8 @@
+<cont xmlns="instance:identifier:module">
+    <cont1>
+        <lflst11 xmlns="augment:module:leaf:list">lflst11_1</lflst11>
+        <lflst11 xmlns="augment:module:leaf:list">lflst11_2</lflst11>
+        <lflst11 xmlns="augment:module:leaf:list">lflst11_3</lflst11>
+        <lf11 xmlns:a="instance:identifier:module" xmlns:b="augment:module:leaf:list" xmlns="augment:module:leaf:list">/a:cont/a:cont1/b:lflst11[.="lflst11_1"]</lf11>
+    </cont1>
+</cont>
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/yang/augment-module-leaf-list.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/yang/augment-module-leaf-list.yang
new file mode 100644 (file)
index 0000000..54c305b
--- /dev/null
@@ -0,0 +1,20 @@
+module augment-module-leaf-list {
+  namespace "augment:module:leaf:list";  
+
+  prefix "amodulelflst";  
+  
+  import instance-identifier-module {prefix imodule; revision-date 2014-01-17;}
+   
+  revision 2014-01-27 {    
+  }
+  
+    augment "/imodule:cont/imodule:cont1" {
+       leaf-list lflst11 {
+           type string;
+       }       
+       leaf lf11 {
+            type instance-identifier;
+       }
+    }   
+         
+}
\ No newline at end of file