X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fjson%2Fto%2Fcnsn%2Ftest%2FJsonLeafrefToCnSnTest.java;fp=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fjson%2Fto%2Fcnsn%2Ftest%2FJsonLeafrefToCnSnTest.java;h=2bb42d903af4f77aebbdc6a8dfb375643c5c0a55;hb=6eb461f54fe6705b07f34b6cee197ea968de4991;hp=0000000000000000000000000000000000000000;hpb=6397a0f2a8b4e0aecb7c42f589d17cd7511827c3;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonLeafrefToCnSnTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonLeafrefToCnSnTest.java new file mode 100644 index 0000000000..2bb42d903a --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonLeafrefToCnSnTest.java @@ -0,0 +1,48 @@ +package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test; + +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; +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.*; + +public class JsonLeafrefToCnSnTest extends YangAndXmlAndDataSchemaLoader { + + @BeforeClass + public static void initialize() { + dataLoad("/json-to-cnsn/leafref"); + } + + /** + * JSON values which represents leafref are always loaded to simple node as + * string + */ + @Test + public void jsonIdentityrefToCompositeNode() { + CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/leafref/json/data.json", false, + JsonToCompositeNodeProvider.INSTANCE); + assertNotNull(compositeNode); + TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName); + + assertEquals("cont", compositeNode.getNodeType().getLocalName()); + + SimpleNode lf2 = null; + for (Node childNode : compositeNode.getChildren()) { + if (childNode instanceof SimpleNode) { + if (childNode.getNodeType().getLocalName().equals("lf2")) { + lf2 = (SimpleNode) childNode; + break; + } + } + } + + assertNotNull(lf2); + assertTrue(lf2.getValue() instanceof String); + assertEquals("121", (String) lf2.getValue()); + + } + +}