1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
8 import javax.activation.UnsupportedDataTypeException;
9 import javax.ws.rs.WebApplicationException;
12 import org.opendaylight.yangtools.yang.model.api.*;
14 public class ToJsonChoiceCaseTest {
16 private static Set<Module> modules;
17 private static DataSchemaNode dataSchemaNode;
20 public static void initialization() {
21 modules = TestUtils.resolveModules("/yang-to-json-conversion/choice");
22 Module module = TestUtils.resolveModule(null, modules);
23 dataSchemaNode = TestUtils.resolveDataSchemaNode(module, null);
28 * Test when some data are in one case node and other in another. Exception
32 public void compNodeDataOnVariousChoiceCasePathTest() {
33 boolean exceptionCatched = false;
35 TestUtils.writeCompNodeWithSchemaContextToJson(
36 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_various_path.xml"),
37 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
38 } catch (UnsupportedDataTypeException e) {
39 exceptionCatched = true;
41 } catch (WebApplicationException | IOException e) {
46 assertTrue(exceptionCatched);
51 * Test when second level data are red first, then first and at the end
52 * third level. Level represents pass through couple choice-case
56 public void compNodeDataWithRandomOrderAccordingLevel() {
58 String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
59 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_random_level.xml"),
60 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
61 } catch (WebApplicationException | IOException e) {
68 * Test when element from no first case is used
72 public void compNodeDataNoFirstCase() {
74 String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
75 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_no_first_case.xml"),
76 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
77 } catch (WebApplicationException | IOException e) {
84 * Test when element in case is list
88 public void compNodeDataAsList() {
90 String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
91 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_list.xml"),
92 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
93 } catch (WebApplicationException | IOException e) {
100 * Test when element in case is container
104 public void compNodeDataAsContainer() {
106 String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
107 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_container.xml"),
108 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
109 } catch (WebApplicationException | IOException e) {
110 // shouldn't end here
116 * Test when element in case is container
120 public void compNodeDataAsLeafList() {
122 String jsonOutput = TestUtils.writeCompNodeWithSchemaContextToJson(
123 TestUtils.loadCompositeNode("/yang-to-json-conversion/choice/xml/data_leaflist.xml"),
124 "/yang-to-json-conversion/choice/xml", modules, dataSchemaNode);
125 } catch (WebApplicationException | IOException e) {
126 // shouldn't end here