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;
14 import javax.ws.rs.WebApplicationException;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
19 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
20 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
21 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
22 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
24 public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
27 public static void initialization() {
28 dataLoad("/cnsn-to-json/choice");
32 * Test when some data are in one case node and other in another. This isn't
33 * correct. Next Json validator should return error because nodes has to be
34 * from one case below concrete choice.
38 public void nodeSchemasOnVariousChoiceCasePathTest() {
39 testWrapper("/cnsn-to-json/choice/xml/data_various_path_err.xml", "choice-case-test:cont");
43 * Test when some data are in one case node and other in another.
44 * Additionally data are loadef from various choices. This isn't correct.
45 * Next Json validator should return error because nodes has to be from one
46 * case below concrete choice.
50 public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
51 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml",
52 "choice-case-test:cont");
56 * Test when second level data are red first, then first and at the end
57 * third level. Level represents pass through couple choice-case
61 public void nodeSchemasWithRandomOrderAccordingLevel() {
62 testWrapper("/cnsn-to-json/choice/xml/data_random_level.xml", "choice-case-test:cont");
66 * Test when element from no first case is used
69 public void nodeSchemasNotInFirstCase() {
70 testWrapper("/cnsn-to-json/choice/xml/data_no_first_case.xml", "choice-case-test:cont");
74 * Test when element in case is list
77 public void nodeSchemaAsList() {
78 testWrapper("/cnsn-to-json/choice/xml/data_list.xml", "choice-case-test:cont");
82 * Test when element in case is container
85 public void nodeSchemaAsContainer() {
86 testWrapper("/cnsn-to-json/choice/xml/data_container.xml", "choice-case-test:cont");
90 * Test when element in case is leaflist
93 public void nodeSchemaAsLeafList() {
94 testWrapper("/cnsn-to-json/choice/xml/data_leaflist.xml", "choice-case-test:cont");
101 public void nodeSchemasInMultipleChoicesTest() {
102 testWrapper("/cnsn-to-json/choice/xml/data_more_choices_same_level.xml", "choice-case-test:cont");
106 * Test whether is possible to find data schema for node which is specified
107 * as dirrect subnode of choice (case without CASE key word)
110 public void nodeSchemasInCaseNotDefinedWithCaseKeyword() {
111 testWrapper("/cnsn-to-json/choice/xml/data_case_defined_without_case.xml", "choice-case-test:cont");
115 * Test of multiple use of choices
118 public void nodeSchemasInThreeChoicesAtSameLevel() {
119 testWrapper("/cnsn-to-json/choice/xml/data_three_choices_same_level.xml", "choice-case-test:cont");
122 private void testWrapper(String xmlPath, String pathToSchemaNode) {
123 CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, XmlToCompositeNodeProvider.INSTANCE);
124 TestUtils.normalizeCompositeNode(compNode, modules, pathToSchemaNode);
126 TestUtils.writeCompNodeWithSchemaContextToOutput(compNode, modules, dataSchemaNode,
127 StructuredDataToJsonProvider.INSTANCE);
128 } catch (WebApplicationException | IOException e) {
129 // shouldn't end here