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.*;
12 import java.util.List;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
17 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
18 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.api.*;
22 public class JsonIdentityrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
25 public static void initialize() {
26 dataLoad("/json-to-cnsn/identityref", 2, "identityref-module", "cont");
30 public void jsonIdentityrefToCompositeNode() {
31 CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/identityref/json/data.json", false,
32 JsonToCompositeNodeProvider.INSTANCE);
33 assertNotNull(compositeNode);
35 TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
37 assertEquals("cont", compositeNode.getNodeType().getLocalName());
39 List<Node<?>> childs = compositeNode.getChildren();
40 assertEquals(1, childs.size());
41 Node<?> nd = childs.iterator().next();
42 assertTrue(nd instanceof CompositeNode);
43 assertEquals("cont1", nd.getNodeType().getLocalName());
45 childs = ((CompositeNode) nd).getChildren();
46 assertEquals(4, childs.size());
47 SimpleNode<?> lf11 = null;
48 SimpleNode<?> lf12 = null;
49 SimpleNode<?> lf13 = null;
50 SimpleNode<?> lf14 = null;
51 for (Node<?> child : childs) {
52 assertTrue(child instanceof SimpleNode);
53 if (child.getNodeType().getLocalName().equals("lf11")) {
54 lf11 = (SimpleNode<?>) child;
55 } else if (child.getNodeType().getLocalName().equals("lf12")) {
56 lf12 = (SimpleNode<?>) child;
57 } else if (child.getNodeType().getLocalName().equals("lf13")) {
58 lf13 = (SimpleNode<?>) child;
59 } else if (child.getNodeType().getLocalName().equals("lf14")) {
60 lf14 = (SimpleNode<?>) child;
64 assertTrue(lf11.getValue() instanceof QName);
65 assertEquals("iden", ((QName) lf11.getValue()).getLocalName());
66 assertEquals("identity:module", ((QName) lf11.getValue()).getNamespace().toString());
68 assertTrue(lf12.getValue() instanceof QName);
69 assertEquals("iden_local", ((QName) lf12.getValue()).getLocalName());
70 assertEquals("identityref:module", ((QName) lf12.getValue()).getNamespace().toString());
72 assertTrue(lf13.getValue() instanceof QName);
73 assertEquals("iden_local", ((QName) lf13.getValue()).getLocalName());
74 assertEquals("identityref:module", ((QName) lf13.getValue()).getNamespace().toString());
76 assertTrue(lf14.getValue() instanceof QName);
77 assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName());
78 assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString());