From: Jozef Gloncak Date: Tue, 21 Jan 2014 12:06:48 +0000 (+0100) Subject: Tests for loading data with augmented schema nodes with equal names X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~34^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=096a28364dbbb5974fa029364d46a130a141829e Tests for loading data with augmented schema nodes with equal names 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 --- diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java index afe458d6e0..3a90e73acb 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java @@ -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 index 0000000000..5650be57ce --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java @@ -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 index 0000000000..421a936d2d --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/xml/to/cnsn/test/XmlAugmentedElementToCnSnTest.java @@ -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 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 index 0000000000..6097bd11b1 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/dataa.json @@ -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 index 0000000000..297584a905 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/json/datab.json @@ -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 index 0000000000..97c5ae5246 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/dataa.xml @@ -0,0 +1,5 @@ + + + lf11 value for a + + \ 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 index 0000000000..b7696ca2a0 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/xml/datab.xml @@ -0,0 +1,5 @@ + + + lf11 value for b + + \ 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 index 0000000000..aa3bf3f253 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-a.yang @@ -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 index 0000000000..dcf493df08 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/augment-main-b.yang @@ -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 index 0000000000..e2917223a4 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/resources/common/augment/yang/main.yang @@ -0,0 +1,10 @@ +module main { + namespace "ns:main"; + prefix "ma"; + + revision "2014-01-21" { + } + + container cont { + } +} \ No newline at end of file