1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
8 import javax.activation.UnsupportedDataTypeException;
9 import javax.ws.rs.WebApplicationException;
12 import org.opendaylight.yangtools.yang.model.api.*;
14 public class ToJsonChoiceCaseTest {
16 private static Set<Module> modules;
17 private static DataSchemaNode dataSchemaNode;
20 public static void initialization() {
21 modules = TestUtils.resolveModules("/yang-to-json-conversion/choice");
22 Module module = TestUtils.resolveModule(null, modules);
23 dataSchemaNode = TestUtils.resolveDataSchemaNode(module, null);
28 * Test when some data are in one case node and other in another. This isn't
29 * correct. Next Json validator should return error because nodes has to be
30 * from one case below concrete choice.
34 public void nodeSchemasOnVariousChoiceCasePathTest() {
36 TestUtils.writeCompNodeWithSchemaContextToJson(
37 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path_err.xml"),
38 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
39 } catch (WebApplicationException | IOException e) {
46 * Test when some data are in one case node and other in another.
47 * Additionally data are loadef from various choices. This isn't
48 * correct. Next Json validator should return error because nodes has to be
49 * from one case below concrete choice.
53 public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
56 .writeCompNodeWithSchemaContextToJson(
58 .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level_various_paths_err.xml"),
59 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
60 } catch (WebApplicationException | IOException e) {
67 * Test when second level data are red first, then first and at the end
68 * third level. Level represents pass through couple choice-case
72 public void nodeSchemasWithRandomOrderAccordingLevel() {
74 TestUtils.writeCompNodeWithSchemaContextToJson(
75 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_random_level.xml"),
76 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
78 } catch (WebApplicationException | IOException e) {
85 * Test when element from no first case is used
88 public void nodeSchemasNotInFirstCase() {
90 TestUtils.writeCompNodeWithSchemaContextToJson(
91 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_no_first_case.xml"),
92 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
93 } catch (WebApplicationException | IOException e) {
100 * Test when element in case is list
103 public void nodeSchemaAsList() {
105 TestUtils.writeCompNodeWithSchemaContextToJson(
106 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_list.xml"),
107 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
108 } catch (WebApplicationException | IOException e) {
109 // shouldn't end here
115 * Test when element in case is container
118 public void nodeSchemaAsContainer() {
120 TestUtils.writeCompNodeWithSchemaContextToJson(
121 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_container.xml"),
122 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
123 } catch (WebApplicationException | IOException e) {
124 // shouldn't end here
130 * Test when element in case is leaflist
133 public void nodeSchemaAsLeafList() {
135 TestUtils.writeCompNodeWithSchemaContextToJson(
136 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_leaflist.xml"),
137 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
138 } catch (WebApplicationException | IOException e) {
139 // shouldn't end here
148 public void nodeSchemasInMultipleChoicesTest() {
151 .writeCompNodeWithSchemaContextToJson(TestUtils
152 .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_more_choices_same_level.xml"),
153 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
154 } catch (WebApplicationException | IOException e) {
155 // shouldn't end here
161 * Test whether is possible to find data schema for node which is specified
162 * as dirrect subnode of choice (case without CASE key word)
165 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
167 TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
168 .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_case_defined_without_case.xml"),
169 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
170 } catch (WebApplicationException | IOException e) {
171 // shouldn't end here
177 * Test of multiple use of choices
180 public void nodeSchemasInThreeChoicesAtSameLevel() {
182 TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
183 .loadCompositeNode("/yang-to-json-conversion/choice/xml/data_three_choices_same_level.xml"),
184 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
185 } catch (WebApplicationException | IOException e) {
186 // shouldn't end here