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.rest.impl.XmlToCompositeNodeProvider;
13 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
14 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
17 public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
20 public static void initialization() {
21 dataLoad("/cnsn-to-json/choice");
25 * Test when some data are in one case node and other in another. This isn't
26 * correct. Next Json validator should return error because nodes has to be
27 * from one case below concrete choice.
31 public void nodeSchemasOnVariousChoiceCasePathTest() {
32 testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
36 * Test when some data are in one case node and other in another.
37 * Additionally data are loadef from various choices. This isn't correct.
38 * Next Json validator should return error because nodes has to be from one
39 * case below concrete choice.
43 public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
44 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml",
45 "choice-case-test:cont");
49 * Test when second level data are red first, then first and at the end
50 * third level. Level represents pass through couple choice-case
54 public void nodeSchemasWithRandomOrderAccordingLevel() {
55 testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
59 * Test when element from no first case is used
62 public void nodeSchemasNotInFirstCase() {
63 testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
67 * Test when element in case is list
70 public void nodeSchemaAsList() {
71 testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
75 * Test when element in case is container
78 public void nodeSchemaAsContainer() {
79 testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
83 * Test when element in case is leaflist
86 public void nodeSchemaAsLeafList() {
87 testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
94 public void nodeSchemasInMultipleChoicesTest() {
95 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
99 * Test whether is possible to find data schema for node which is specified
100 * as dirrect subnode of choice (case without CASE key word)
103 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
104 testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
108 * Test of multiple use of choices
111 public void nodeSchemasInThreeChoicesAtSameLevel() {
112 testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
115 private void testWrapper(String xmlPath, String pathToSchemaNode) {
116 CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, XmlToCompositeNodeProvider.INSTANCE);
117 TestUtils.normalizeCompositeNode(compNode, modules, pathToSchemaNode);
119 TestUtils.writeCompNodeWithSchemaContextToOutput(compNode, modules, dataSchemaNode,
120 StructuredDataToJsonProvider.INSTANCE);
121 } catch (WebApplicationException | IOException e) {
122 // shouldn't end here