2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
10 import static org.junit.Assert.assertTrue;
12 import java.io.IOException;
13 import javax.ws.rs.WebApplicationException;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
17 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
18 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
19 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
20 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
25 public static void initialization() {
26 dataLoad("/cnsn-to-json/choice");
30 * Test when some data are in one case node and other in another. This isn't correct. Next Json validator should
31 * return error because nodes has to be from one case below concrete choice.
35 public void nodeSchemasOnVariousChoiceCasePathTest() {
36 testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
40 * Test when some data are in one case node and other in another. Additionally data are loadef from various choices.
41 * This isn't correct. Next Json validator should return error because nodes has to be from one case below concrete
46 public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
47 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml",
48 "choice-case-test:cont");
52 * Test when second level data are red first, then first and at the end third level. Level represents pass through
57 public void nodeSchemasWithRandomOrderAccordingLevel() {
58 testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
62 * Test when element from no first case is used
65 public void nodeSchemasNotInFirstCase() {
66 testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
70 * Test when element in case is list
73 public void nodeSchemaAsList() {
74 testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
78 * Test when element in case is container
81 public void nodeSchemaAsContainer() {
82 testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
86 * Test when element in case is leaflist
89 public void nodeSchemaAsLeafList() {
90 testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
97 public void nodeSchemasInMultipleChoicesTest() {
98 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
102 * Test whether is possible to find data schema for node which is specified as dirrect subnode of choice (case
103 * without CASE key word)
106 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
107 testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
111 * Test of multiple use of choices
114 public void nodeSchemasInThreeChoicesAtSameLevel() {
115 testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
118 private void testWrapper(String xmlPath, String pathToSchemaNode) {
119 CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, XmlToCompositeNodeProvider.INSTANCE);
120 TestUtils.normalizeCompositeNode(compNode, modules, pathToSchemaNode);
122 TestUtils.writeCompNodeWithSchemaContextToOutput(compNode, modules, dataSchemaNode,
123 StructuredDataToJsonProvider.INSTANCE);
124 } catch (WebApplicationException | IOException e) {
125 // shouldn't end here