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