1 package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test;
3 import static org.junit.Assert.*;
7 import org.junit.BeforeClass;
9 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
10 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
11 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.*;
15 public class JsonIdentityrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
18 public static void initialize() {
19 dataLoad("/json-to-cnsn/identityref", 2, "identityref-module", "cont");
23 public void jsonIdentityrefToCompositeNode() {
24 CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/identityref/json/data.json", false,
25 JsonToCompositeNodeProvider.INSTANCE);
26 assertNotNull(compositeNode);
28 TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
30 assertEquals("cont", compositeNode.getNodeType().getLocalName());
32 List<Node<?>> childs = compositeNode.getChildren();
33 assertEquals(1, childs.size());
34 Node<?> nd = childs.iterator().next();
35 assertTrue(nd instanceof CompositeNode);
36 assertEquals("cont1", nd.getNodeType().getLocalName());
38 childs = ((CompositeNode) nd).getChildren();
39 assertEquals(4, childs.size());
40 SimpleNode<?> lf11 = null;
41 SimpleNode<?> lf12 = null;
42 SimpleNode<?> lf13 = null;
43 SimpleNode<?> lf14 = null;
44 for (Node<?> child : childs) {
45 assertTrue(child instanceof SimpleNode);
46 if (child.getNodeType().getLocalName().equals("lf11")) {
47 lf11 = (SimpleNode<?>) child;
48 } else if (child.getNodeType().getLocalName().equals("lf12")) {
49 lf12 = (SimpleNode<?>) child;
50 } else if (child.getNodeType().getLocalName().equals("lf13")) {
51 lf13 = (SimpleNode<?>) child;
52 } else if (child.getNodeType().getLocalName().equals("lf14")) {
53 lf14 = (SimpleNode<?>) child;
57 assertTrue(lf11.getValue() instanceof QName);
58 assertEquals("iden", ((QName) lf11.getValue()).getLocalName());
59 assertEquals("identity:module", ((QName) lf11.getValue()).getNamespace().toString());
61 assertTrue(lf12.getValue() instanceof QName);
62 assertEquals("iden_local", ((QName) lf12.getValue()).getLocalName());
63 assertEquals("identityref:module", ((QName) lf12.getValue()).getNamespace().toString());
65 assertTrue(lf13.getValue() instanceof QName);
66 assertEquals("iden_local", ((QName) lf13.getValue()).getLocalName());
67 assertEquals("identityref:module", ((QName) lf13.getValue()).getNamespace().toString());
69 assertTrue(lf14.getValue() instanceof QName);
70 assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName());
71 assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString());