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>
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;
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;
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);
CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap();
assertEquals(topLevelElementName, compNode.getNodeType().getLocalName());
- verifyCompositeNode(compNode, namespace);
+ return compNode;
}
private void verityMultipleItemsInList(CompositeNode compositeNode) {
--- /dev/null
+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);
+
+ }
+
+}
--- /dev/null
+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);
+ }
+
+
+}
--- /dev/null
+{
+ "main:cont":{
+ "augment-main-a:cont1":{
+ "lf11":"lf11 value from a"
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "main:cont":{
+ "augment-main-b:cont1":{
+ "lf11":"lf11 value from b"
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<cont xmlns="ns:main">
+ <cont1 xmlns="ns:augment:main:a">
+ <lf11>lf11 value for a</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+<cont xmlns="ns:main">
+ <cont1 xmlns="ns:augment:main:b">
+ <lf11>lf11 value for b</lf11>
+ </cont1>
+</cont>
\ No newline at end of file
--- /dev/null
+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;
+ }
+ }
+ }
+
+}
--- /dev/null
+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;
+ }
+ }
+ }
+
+}
--- /dev/null
+module main {
+ namespace "ns:main";
+ prefix "ma";
+
+ revision "2014-01-21" {
+ }
+
+ container cont {
+ }
+}
\ No newline at end of file