Add test for generated code checking list of dependencies.
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnJsonChoiceCaseTest.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
2
3 import static org.junit.Assert.assertTrue;
4
5 import java.io.IOException;
6
7 import javax.ws.rs.WebApplicationException;
8
9 import org.junit.BeforeClass;
10 import org.junit.Test;
11 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
12 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
13 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
14 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16
17 public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
18
19     @BeforeClass
20     public static void initialization() {
21         dataLoad("/cnsn-to-json/choice");
22     }
23
24     /**
25      * Test when some data are in one case node and other in another. This isn't
26      * correct. Next Json validator should return error because nodes has to be
27      * from one case below concrete choice.
28      * 
29      */
30     @Test
31     public void nodeSchemasOnVariousChoiceCasePathTest() {
32         testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
33     }
34
35     /**
36      * Test when some data are in one case node and other in another.
37      * Additionally data are loadef from various choices. This isn't correct.
38      * Next Json validator should return error because nodes has to be from one
39      * case below concrete choice.
40      * 
41      */
42     @Test
43     public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
44         testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml",
45                 "choice-case-test:cont");
46     }
47
48     /**
49      * Test when second level data are red first, then first and at the end
50      * third level. Level represents pass through couple choice-case
51      */
52
53     @Test
54     public void nodeSchemasWithRandomOrderAccordingLevel() {
55         testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
56     }
57
58     /**
59      * Test when element from no first case is used
60      */
61     @Test
62     public void nodeSchemasNotInFirstCase() {
63         testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
64     }
65
66     /**
67      * Test when element in case is list
68      */
69     @Test
70     public void nodeSchemaAsList() {
71         testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
72     }
73
74     /**
75      * Test when element in case is container
76      */
77     @Test
78     public void nodeSchemaAsContainer() {
79         testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
80     }
81
82     /**
83      * Test when element in case is leaflist
84      */
85     @Test
86     public void nodeSchemaAsLeafList() {
87         testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
88     }
89
90     /**
91      * 
92      */
93     @Test
94     public void nodeSchemasInMultipleChoicesTest() {
95         testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
96     }
97
98     /**
99      * Test whether is possible to find data schema for node which is specified
100      * as dirrect subnode of choice (case without CASE key word)
101      */
102     @Test
103     public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
104         testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
105     }
106
107     /**
108      * Test of multiple use of choices
109      */
110     @Test
111     public void nodeSchemasInThreeChoicesAtSameLevel() {
112         testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
113     }
114
115     private void testWrapper(String xmlPath, String pathToSchemaNode) {
116         CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, XmlToCompositeNodeProvider.INSTANCE);
117         TestUtils.normalizeCompositeNode(compNode, modules, pathToSchemaNode);
118         try {
119             TestUtils.writeCompNodeWithSchemaContextToOutput(compNode, modules, dataSchemaNode,
120                     StructuredDataToJsonProvider.INSTANCE);
121         } catch (WebApplicationException | IOException e) {
122             // shouldn't end here
123             assertTrue(false);
124         }
125     }
126 }