1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
3 import static org.junit.Assert.assertTrue;
5 import java.io.IOException;
7 import javax.ws.rs.WebApplicationException;
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;
15 public class ToJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
18 public static void initialization() {
19 dataLoad("/cnsn-to-json/choice");
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.
29 public void nodeSchemasOnVariousChoiceCasePathTest() {
30 testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
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.
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");
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
52 public void nodeSchemasWithRandomOrderAccordingLevel() {
53 testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
57 * Test when element from no first case is used
60 public void nodeSchemasNotInFirstCase() {
61 testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
65 * Test when element in case is list
68 public void nodeSchemaAsList() {
69 testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
73 * Test when element in case is container
76 public void nodeSchemaAsContainer() {
77 testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
81 * Test when element in case is leaflist
84 public void nodeSchemaAsLeafList() {
85 testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
92 public void nodeSchemasInMultipleChoicesTest() {
93 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
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)
101 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
102 testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
106 * Test of multiple use of choices
109 public void nodeSchemasInThreeChoicesAtSameLevel() {
110 testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
113 private void testWrapper(String xmlPath, String pathToSchemaNode) {
114 CompositeNode compNode = TestUtils.loadCompositeNode(xmlPath);
115 TestUtils.normalizeCompositeNode(compNode, modules, dataSchemaNode, pathToSchemaNode);
117 TestUtils.writeCompNodeWithSchemaContextToJson(compNode, modules, dataSchemaNode);
118 } catch (WebApplicationException | IOException e) {
119 // shouldn't end here