Merge changes Ic434bf4a,I05a3fb18,I47a3783d,I8234bbfd
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / json / to / cnsn / test / JsonLeafrefToCnSnTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
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.data.api.CompositeNode;
20 import org.opendaylight.yangtools.yang.data.api.Node;
21 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
22
23 public class JsonLeafrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
24
25     @BeforeClass
26     public static void initialize() {
27         dataLoad("/json-to-cnsn/leafref");
28     }
29
30     /**
31      * JSON values which represents leafref are always loaded to simple node as string
32      */
33     @Test
34     public void jsonIdentityrefToCompositeNode() {
35         Node<?> node = TestUtils.readInputToCnSn("/json-to-cnsn/leafref/json/data.json", false,
36                 JsonToCompositeNodeProvider.INSTANCE);
37         assertNotNull(node);
38         TestUtils.normalizeCompositeNode(node, modules, searchedModuleName + ":" + searchedDataSchemaName);
39
40         assertEquals("cont", node.getNodeType().getLocalName());
41
42         SimpleNode<?> lf2 = null;
43         assertTrue(node instanceof CompositeNode);
44         for (Node<?> childNode : ((CompositeNode) node).getValue()) {
45             if (childNode instanceof SimpleNode) {
46                 if (childNode.getNodeType().getLocalName().equals("lf2")) {
47                     lf2 = (SimpleNode<?>) childNode;
48                     break;
49                 }
50             }
51         }
52
53         assertNotNull(lf2);
54         assertEquals(121, lf2.getValue());
55     }
56
57 }