Tests for loading data with augmented schema nodes with equal names 95/4495/1
authorJozef Gloncak <jgloncak@cisco.com>
Tue, 21 Jan 2014 12:06:48 +0000 (13:06 +0100)
committerJozef Gloncak <jgloncak@cisco.com>
Tue, 21 Jan 2014 12:10:15 +0000 (13:10 +0100)
Tests loading and normalization of JSON and XML data to composite/simple node structure when
schema node structure contains several nodes with equal name which were
added through augmentation.

Change-Id: I18d00ace7b3f7a4bd3c757330024798cec890784
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/xml/to/cnsn/test/XmlAugmentedElementToCnSnTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/dataa.json [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/datab.json [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/dataa.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/datab.xml [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-a.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-b.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/main.yang [new file with mode: 0644]

index afe458d6e0917e25903d4f655cf7b3a49640f8b5..3a90e73acbc4e8756ca88f127f2065245ac8dd05 100644 (file)
@@ -1,6 +1,7 @@
 package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -10,9 +11,11 @@ import java.util.Set;
 
 import javax.ws.rs.WebApplicationException;
 
+import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
+import org.opendaylight.controller.sal.restconf.impl.ResponseException;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
@@ -264,9 +267,28 @@ public class JsonToCnSnTest {
         assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName());
         assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString());
     }
+    
+    @Ignore
+    @Test
+    public void loadDataAugmentedSchemaMoreEqualNamesTest() {
+        boolean exceptionCaught = false;
+        try {
+            loadAndNormalizeData("/common/augment/json/dataa.json", "/common/augment/yang", "cont", "main");
+            loadAndNormalizeData("/common/augment/json/datab.json", "/common/augment/yang", "cont", "main");
+        } catch (ResponseException e) {
+            exceptionCaught = true;
+        }
+        
+        assertFalse(exceptionCaught);
+    }
 
     private void simpleTest(String jsonPath, String yangPath, String topLevelElementName, String namespace,
             String moduleName) {
+        CompositeNode compNode = loadAndNormalizeData(jsonPath, yangPath, topLevelElementName, moduleName);
+        verifyCompositeNode(compNode, namespace);
+    }
+
+    private CompositeNode loadAndNormalizeData(String jsonPath, String yangPath, String topLevelElementName, String moduleName) {
         CompositeNode compositeNode = TestUtils.readInputToCnSn(jsonPath, false, JsonToCompositeNodeProvider.INSTANCE);
         assertNotNull(compositeNode);
 
@@ -280,7 +302,7 @@ public class JsonToCnSnTest {
         CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
 
         assertEquals(topLevelElementName, compNode.getNodeType().getLocalName());
-        verifyCompositeNode(compNode, namespace);
+        return compNode;
     }
 
     private void verityMultipleItemsInList(CompositeNode compositeNode) {
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java
new file mode 100644 (file)
index 0000000..5650be5
--- /dev/null
@@ -0,0 +1,45 @@
+package org.opendaylight.controller.sal.restconf.impl.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.FileNotFoundException;
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
+import org.opendaylight.controller.sal.restconf.impl.ResponseException;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class RestGetAugmentedElementWhenEqualNamesTest {
+
+    @Ignore
+    @Test
+    public void getDataWithUrlMountPoint() throws UnsupportedEncodingException, URISyntaxException,
+            FileNotFoundException {
+        boolean exceptionCaught = false;
+
+        SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang");
+        ControllerContext controllerContext = ControllerContext.getInstance();
+        controllerContext.setSchemas(schemaContextTestModule);
+
+        try {
+            InstanceIdWithSchemaNode instanceIdentifierA = controllerContext
+                    .toInstanceIdentifier("main:cont/augment-main-a:cont1");
+            InstanceIdWithSchemaNode instanceIdentifierB = controllerContext
+                    .toInstanceIdentifier("main:cont/augment-main-b:cont1");
+
+            assertEquals("ns:augment:main:a", instanceIdentifierA.getSchemaNode().getQName().getNamespace().toString());
+            assertEquals("ns:augment:main:b", instanceIdentifierB.getSchemaNode().getQName().getNamespace());
+        } catch (ResponseException e) {
+            exceptionCaught = true;
+        }
+
+        assertFalse(exceptionCaught);
+
+    }
+
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/xml/to/cnsn/test/XmlAugmentedElementToCnSnTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/xml/to/cnsn/test/XmlAugmentedElementToCnSnTest.java
new file mode 100644 (file)
index 0000000..421a936
--- /dev/null
@@ -0,0 +1,44 @@
+package org.opendaylight.controller.sal.restconf.impl.xml.to.cnsn.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Set;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
+import org.opendaylight.controller.sal.restconf.impl.ResponseException;
+import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+
+public class XmlAugmentedElementToCnSnTest {
+
+    @Ignore
+    @Test
+    public void loadDataAugmentedSchemaMoreEqualNamesTest() {
+        boolean exceptionCaught = false;
+        try {
+            loadAndNormalizeData("/common/augment/xml/dataa.xml", "/common/augment/yang", "main","cont");
+            loadAndNormalizeData("/common/augment/xml/datab.xml", "/common/augment/yang", "main","cont");
+        } catch (ResponseException e) {
+            exceptionCaught = true;
+        }
+        
+        assertFalse(exceptionCaught);        
+    }
+    
+    
+    private void loadAndNormalizeData(String xmlPath, String yangPath, String topLevelElementName, String moduleName) {
+        CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, false,
+                XmlToCompositeNodeProvider.INSTANCE);
+        assertNotNull(compNode);
+        Set<Module> modules = TestUtils.loadModulesFrom(yangPath);
+
+        assertNotNull(modules);
+        TestUtils.normalizeCompositeNode(compNode, modules, topLevelElementName + ":" + moduleName);
+    }
+
+
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/dataa.json b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/dataa.json
new file mode 100644 (file)
index 0000000..6097bd1
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "main:cont":{
+        "augment-main-a:cont1":{
+            "lf11":"lf11 value from a"
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/datab.json b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/datab.json
new file mode 100644 (file)
index 0000000..297584a
--- /dev/null
@@ -0,0 +1,7 @@
+{
+    "main:cont":{
+        "augment-main-b:cont1":{
+            "lf11":"lf11 value from b"
+        }
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/dataa.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/dataa.xml
new file mode 100644 (file)
index 0000000..97c5ae5
--- /dev/null
@@ -0,0 +1,5 @@
+<cont xmlns="ns:main">
+    <cont1 xmlns="ns:augment:main:a">
+        <lf11>lf11 value for a</lf11>
+    </cont1>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/datab.xml b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/datab.xml
new file mode 100644 (file)
index 0000000..b7696ca
--- /dev/null
@@ -0,0 +1,5 @@
+<cont xmlns="ns:main">
+    <cont1 xmlns="ns:augment:main:b">
+        <lf11>lf11 value for b</lf11>
+    </cont1>
+</cont>
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-a.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-a.yang
new file mode 100644 (file)
index 0000000..aa3bf3f
--- /dev/null
@@ -0,0 +1,20 @@
+module augment-main-a {
+  namespace "ns:augment:main:a";  
+  prefix "aumaa";
+
+  
+  import main {prefix mn; revision-date 2014-01-21;}   
+
+
+  revision "2014-01-21" {    
+  }
+  
+  augment "/mn:cont" {
+    container cont1 {
+        leaf lf11 {
+            type string;
+        }
+    }
+  }
+  
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-b.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-b.yang
new file mode 100644 (file)
index 0000000..dcf493d
--- /dev/null
@@ -0,0 +1,20 @@
+module augment-main-b {
+  namespace "ns:augment:main:b";  
+  prefix "aumab";
+
+  
+  import main {prefix mn; revision-date 2014-01-21;}   
+
+
+  revision "2014-01-21" {    
+  }
+  
+  augment "/mn:cont" {
+    container cont1 {
+        leaf lf11 {
+            type string;
+        }
+    }
+  }
+  
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/main.yang b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/main.yang
new file mode 100644 (file)
index 0000000..e291722
--- /dev/null
@@ -0,0 +1,10 @@
+module main {
+  namespace "ns:main";  
+  prefix "ma";
+
+  revision "2014-01-21" {    
+  }
+  
+  container cont {
+  }
+}
\ No newline at end of file