2030d9125a142032e340b3025eeb078a5434a00d
[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.*;
11
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
15 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
16 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
17 import org.opendaylight.yangtools.yang.data.api.*;
18
19 public class JsonLeafrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
20
21     @BeforeClass
22     public static void initialize() {
23         dataLoad("/json-to-cnsn/leafref");
24     }
25
26     /**
27      * JSON values which represents leafref are always loaded to simple node as
28      * string
29      */
30     @Test
31     public void jsonIdentityrefToCompositeNode() {
32         CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/leafref/json/data.json", false,
33                 JsonToCompositeNodeProvider.INSTANCE);
34         assertNotNull(compositeNode);
35         TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
36
37         assertEquals("cont", compositeNode.getNodeType().getLocalName());
38
39         SimpleNode<?> lf2 = null;
40         for (Node<?> childNode : compositeNode.getChildren()) {
41             if (childNode instanceof SimpleNode) {
42                 if (childNode.getNodeType().getLocalName().equals("lf2")) {
43                     lf2 = (SimpleNode<?>) childNode;
44                     break;
45                 }
46             }
47         }
48
49         assertNotNull(lf2);
50         assertTrue(lf2.getValue() instanceof String);
51         assertEquals("121", (String) lf2.getValue());
52
53     }
54
55 }