Merge "Choice and case resolving in JSON output"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / ToJsonChoiceCaseTest.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.util.Set;
7
8 import javax.activation.UnsupportedDataTypeException;
9 import javax.ws.rs.WebApplicationException;
10
11 import org.junit.*;
12 import org.opendaylight.yangtools.yang.model.api.*;
13
14 public class ToJsonChoiceCaseTest {
15
16     private static Set<Module> modules;
17     private static DataSchemaNode dataSchemaNode;
18
19     @BeforeClass
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);
24
25     }
26
27     /**
28      * Test when some data are in one case node and other in another. Exception
29      * expected!!
30      */
31     @Test
32     public void compNodeDataOnVariousChoiceCasePathTest() {
33         boolean exceptionCatched = false;
34         try {
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;
40
41         } catch (WebApplicationException | IOException e) {
42             // shouldn't end here
43             assertTrue(false);
44         }
45
46         assertTrue(exceptionCatched);
47
48     }
49
50     /**
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
53      */
54     @Ignore
55     @Test
56     public void compNodeDataWithRandomOrderAccordingLevel() {
57         try {
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) {
62             // shouldn't end here
63             assertTrue(false);
64         }
65     }
66
67     /**
68      * Test when element from no first case is used
69      */
70     @Ignore
71     @Test
72     public void compNodeDataNoFirstCase() {
73         try {
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) {
78             // shouldn't end here
79             assertTrue(false);
80         }
81     }
82
83     /**
84      * Test when element in case is list
85      */
86     @Ignore
87     @Test
88     public void compNodeDataAsList() {
89         try {
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) {
94             // shouldn't end here
95             assertTrue(false);
96         }
97     }
98
99     /**
100      * Test when element in case is container
101      */
102     @Ignore
103     @Test
104     public void compNodeDataAsContainer() {
105         try {
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
111             assertTrue(false);
112         }
113     }
114
115     /**
116      * Test when element in case is container
117      */
118     @Ignore
119     @Test
120     public void compNodeDataAsLeafList() {
121         try {
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
127             assertTrue(false);
128         }
129     }
130
131 }