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.rest.impl.StructuredDataToJsonProvider;
12 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
13 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
14 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
19 public static void initialization() {
20 dataLoad("/cnsn-to-json/choice");
24 * Test when some data are in one case node and other in another. This isn't
25 * correct. Next Json validator should return error because nodes has to be
26 * from one case below concrete choice.
30 public void nodeSchemasOnVariousChoiceCasePathTest() {
31 testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
35 * Test when some data are in one case node and other in another.
36 * Additionally data are loadef from various choices. This isn't correct.
37 * Next Json validator should return error because nodes has to be from one
38 * case below concrete choice.
42 public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
43 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml",
44 "choice-case-test:cont");
48 * Test when second level data are red first, then first and at the end
49 * third level. Level represents pass through couple choice-case
53 public void nodeSchemasWithRandomOrderAccordingLevel() {
54 testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
58 * Test when element from no first case is used
61 public void nodeSchemasNotInFirstCase() {
62 testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
66 * Test when element in case is list
69 public void nodeSchemaAsList() {
70 testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
74 * Test when element in case is container
77 public void nodeSchemaAsContainer() {
78 testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
82 * Test when element in case is leaflist
85 public void nodeSchemaAsLeafList() {
86 testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
93 public void nodeSchemasInMultipleChoicesTest() {
94 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
98 * Test whether is possible to find data schema for node which is specified
99 * as dirrect subnode of choice (case without CASE key word)
102 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
103 testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
107 * Test of multiple use of choices
110 public void nodeSchemasInThreeChoicesAtSameLevel() {
111 testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
114 private void testWrapper(String xmlPath, String pathToSchemaNode) {
115 CompositeNode compNode = TestUtils.loadCompositeNode(xmlPath);
116 TestUtils.normalizeCompositeNode(compNode, modules, pathToSchemaNode);
118 TestUtils.writeCompNodeWithSchemaContextToOutput(compNode, modules, dataSchemaNode,
119 StructuredDataToJsonProvider.INSTANCE);
120 } catch (WebApplicationException | IOException e) {
121 // shouldn't end here