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