Fixed RESTConf support for identity-ref build-in datatype
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / ToJsonChoiceCaseTest.java
1 package org.opendaylight.controller.sal.restconf.impl.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.*;
10
11 public class ToJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
12
13     @BeforeClass
14     public static void initialization() {
15         dataLoad("/yang-to-json-conversion/choice");
16     }
17
18     /**
19      * Test when some data are in one case node and other in another. This isn't
20      * correct. Next Json validator should return error because nodes has to be
21      * from one case below concrete choice.
22      * 
23      */
24     @Test
25     public void nodeSchemasOnVariousChoiceCasePathTest() {
26         try {
27             TestUtils.writeCompNodeWithSchemaContextToJson(
28                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path_err.xml"),
29                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
30         } catch (WebApplicationException | IOException e) {
31             // shouldn't end here
32             assertTrue(false);
33         }
34     }
35
36     /**
37      * Test when some data are in one case node and other in another.
38      * Additionally data are loadef from various choices. This isn't correct.
39      * Next Json validator should return error because nodes has to be from one
40      * case below concrete choice.
41      * 
42      */
43     @Test
44     public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
45         try {
46             TestUtils
47                     .writeCompNodeWithSchemaContextToJson(
48                             TestUtils
49                                     .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml"),
50                             "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
51         } catch (WebApplicationException | IOException e) {
52             // shouldn't end here
53             assertTrue(false);
54         }
55     }
56
57     /**
58      * Test when second level data are red first, then first and at the end
59      * third level. Level represents pass through couple choice-case
60      */
61
62     @Test
63     public void nodeSchemasWithRandomOrderAccordingLevel() {
64         try {
65             TestUtils.writeCompNodeWithSchemaContextToJson(
66                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_random_level.xml"),
67                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
68
69         } catch (WebApplicationException | IOException e) {
70             // shouldn't end here
71             assertTrue(false);
72         }
73     }
74
75     /**
76      * Test when element from no first case is used
77      */
78     @Test
79     public void nodeSchemasNotInFirstCase() {
80         try {
81             TestUtils.writeCompNodeWithSchemaContextToJson(
82                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_no_first_case.xml"),
83                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
84         } catch (WebApplicationException | IOException e) {
85             // shouldn't end here
86             assertTrue(false);
87         }
88     }
89
90     /**
91      * Test when element in case is list
92      */
93     @Test
94     public void nodeSchemaAsList() {
95         try {
96             TestUtils.writeCompNodeWithSchemaContextToJson(
97                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_list.xml"),
98                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
99         } catch (WebApplicationException | IOException e) {
100             // shouldn't end here
101             assertTrue(false);
102         }
103     }
104
105     /**
106      * Test when element in case is container
107      */
108     @Test
109     public void nodeSchemaAsContainer() {
110         try {
111             TestUtils.writeCompNodeWithSchemaContextToJson(
112                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_container.xml"),
113                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
114         } catch (WebApplicationException | IOException e) {
115             // shouldn't end here
116             assertTrue(false);
117         }
118     }
119
120     /**
121      * Test when element in case is leaflist
122      */
123     @Test
124     public void nodeSchemaAsLeafList() {
125         try {
126             TestUtils.writeCompNodeWithSchemaContextToJson(
127                     TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_leaflist.xml"),
128                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
129         } catch (WebApplicationException | IOException e) {
130             // shouldn't end here
131             assertTrue(false);
132         }
133     }
134
135     /**
136      * 
137      */
138     @Test
139     public void nodeSchemasInMultipleChoicesTest() {
140         try {
141             TestUtils
142                     .writeCompNodeWithSchemaContextToJson(TestUtils
143                             .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml"),
144                             "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
145         } catch (WebApplicationException | IOException e) {
146             // shouldn't end here
147             assertTrue(false);
148         }
149     }
150
151     /**
152      * Test whether is possible to find data schema for node which is specified
153      * as dirrect subnode of choice (case without CASE key word)
154      */
155     @Test
156     public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
157         try {
158             TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
159                     .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml"),
160                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
161         } catch (WebApplicationException | IOException e) {
162             // shouldn't end here
163             assertTrue(false);
164         }
165     }
166
167     /**
168      * Test of multiple use of choices
169      */
170     @Test
171     public void nodeSchemasInThreeChoicesAtSameLevel() {
172         try {
173             TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
174                     .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml"),
175                     "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
176         } catch (WebApplicationException | IOException e) {
177             // shouldn't end here
178             assertTrue(false);
179         }
180     }
181 }