2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.util.List;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
18 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
19 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 import org.opendaylight.yangtools.yang.data.api.Node;
23 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
25 public class JsonIdentityrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
28 public static void initialize() {
29 dataLoad("/json-to-cnsn/identityref", 2, "identityref-module", "cont");
33 public void jsonIdentityrefToCompositeNode() {
34 Node<?> node = TestUtils.readInputToCnSn("/json-to-cnsn/identityref/json/data.json", false,
35 JsonToCompositeNodeProvider.INSTANCE);
38 TestUtils.normalizeCompositeNode(node, modules, searchedModuleName + ":" + searchedDataSchemaName);
40 assertEquals("cont", node.getNodeType().getLocalName());
42 assert(node instanceof CompositeNode);
43 List<Node<?>> childs = ((CompositeNode)node).getValue();
44 assertEquals(1, childs.size());
45 Node<?> nd = childs.iterator().next();
46 assertTrue(nd instanceof CompositeNode);
47 assertEquals("cont1", nd.getNodeType().getLocalName());
49 childs = ((CompositeNode) nd).getValue();
50 assertEquals(4, childs.size());
51 SimpleNode<?> lf11 = null;
52 SimpleNode<?> lf12 = null;
53 SimpleNode<?> lf13 = null;
54 SimpleNode<?> lf14 = null;
55 for (Node<?> child : childs) {
56 assertTrue(child instanceof SimpleNode);
57 if (child.getNodeType().getLocalName().equals("lf11")) {
58 lf11 = (SimpleNode<?>) child;
59 } else if (child.getNodeType().getLocalName().equals("lf12")) {
60 lf12 = (SimpleNode<?>) child;
61 } else if (child.getNodeType().getLocalName().equals("lf13")) {
62 lf13 = (SimpleNode<?>) child;
63 } else if (child.getNodeType().getLocalName().equals("lf14")) {
64 lf14 = (SimpleNode<?>) child;
68 assertTrue(lf11.getValue() instanceof QName);
69 assertEquals("iden", ((QName) lf11.getValue()).getLocalName());
70 assertEquals("identity:module", ((QName) lf11.getValue()).getNamespace().toString());
72 assertTrue(lf12.getValue() instanceof QName);
73 assertEquals("iden_local", ((QName) lf12.getValue()).getLocalName());
74 assertEquals("identityref:module", ((QName) lf12.getValue()).getNamespace().toString());
76 assertTrue(lf13.getValue() instanceof QName);
77 assertEquals("iden_local", ((QName) lf13.getValue()).getLocalName());
78 assertEquals("identityref:module", ((QName) lf13.getValue()).getNamespace().toString());
80 assertTrue(lf14.getValue() instanceof QName);
81 assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName());
82 assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString());