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.Node;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
23 public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
26 public static void initialization() {
27 dataLoad("/cnsn-to-json/choice");
31 * Test when some data are in one case node and other in another. This isn't correct. Next Json validator should
32 * return error because nodes has to be from one case below concrete choice.
35 @Test(expected=DataValidationException.class)
36 public void nodeSchemasOnVariousChoiceCasePathTest() {
37 testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
41 * Test when some data are in one case node and other in another. Additionally data are loadef from various choices.
42 * This isn't correct. Next Json validator should return error because nodes has to be from one case below concrete
46 @Test(expected=DataValidationException.class)
47 public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
48 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml",
49 "choice-case-test:cont");
53 * Test when second level data are red first, then first and at the end third level. Level represents pass through
58 public void nodeSchemasWithRandomOrderAccordingLevel() {
59 testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
63 * Test when element from no first case is used
66 public void nodeSchemasNotInFirstCase() {
67 testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
71 * Test when element in case is list
74 public void nodeSchemaAsList() {
75 testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
79 * Test when element in case is container
82 public void nodeSchemaAsContainer() {
83 testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
87 * Test when element in case is leaflist
90 public void nodeSchemaAsLeafList() {
91 testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
98 public void nodeSchemasInMultipleChoicesTest() {
99 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
103 * Test whether is possible to find data schema for node which is specified as dirrect subnode of choice (case
104 * without CASE key word)
107 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
108 testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
112 * Test of multiple use of choices
115 public void nodeSchemasInThreeChoicesAtSameLevel() {
116 testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
119 private void testWrapper(String xmlPath, String pathToSchemaNode) {
120 Node<?> node = TestUtils.readInputToCnSn(xmlPath, XmlToCompositeNodeProvider.INSTANCE);
121 TestUtils.normalizeCompositeNode(node, modules, pathToSchemaNode);
123 TestUtils.writeCompNodeWithSchemaContextToOutput(node, modules, dataSchemaNode,
124 StructuredDataToJsonProvider.INSTANCE);
125 } catch (WebApplicationException | IOException e) {
126 // shouldn't end here