More test for improving of code coverage + test refactoring
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / json / to / cnsn / test / JsonLeafrefToCnSnTest.java
1 package org.opendaylight.controller.sal.restconf.impl.json.to.cnsn.test;
2
3 import static org.junit.Assert.*;
4
5 import org.junit.BeforeClass;
6 import org.junit.Test;
7 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
8 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
9 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
10 import org.opendaylight.yangtools.yang.data.api.*;
11
12 public class JsonLeafrefToCnSnTest extends YangAndXmlAndDataSchemaLoader {
13
14     @BeforeClass
15     public static void initialize() {
16         dataLoad("/json-to-cnsn/leafref");
17     }
18
19     /**
20      * JSON values which represents leafref are always loaded to simple node as
21      * string
22      */
23     @Test
24     public void jsonIdentityrefToCompositeNode() {
25         CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/leafref/json/data.json", false,
26                 JsonToCompositeNodeProvider.INSTANCE);
27         assertNotNull(compositeNode);
28         TestUtils.normalizeCompositeNode(compositeNode, modules, searchedModuleName + ":" + searchedDataSchemaName);
29
30         assertEquals("cont", compositeNode.getNodeType().getLocalName());
31
32         SimpleNode<?> lf2 = null;
33         for (Node<?> childNode : compositeNode.getChildren()) {
34             if (childNode instanceof SimpleNode) {
35                 if (childNode.getNodeType().getLocalName().equals("lf2")) {
36                     lf2 = (SimpleNode<?>) childNode;
37                     break;
38                 }
39             }
40         }
41
42         assertNotNull(lf2);
43         assertTrue(lf2.getValue() instanceof String);
44         assertEquals("121", (String) lf2.getValue());
45
46     }
47
48 }