Merge "Refactor Subnet.isSubnetOf - reduce number of 'if' statements. Added unitests."
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / ToJsonLeafrefType.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.IOException;
7 import java.util.regex.Matcher;
8
9 import javax.ws.rs.WebApplicationException;
10
11 import org.junit.*;
12 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
13 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
14
15 /**
16  * 
17  * All tests are commented now because leafref isn't supported now
18  * 
19  */
20
21 public class ToJsonLeafrefType extends YangAndXmlAndDataSchemaLoader {
22
23     @BeforeClass
24     public static void initialization() {
25         dataLoad("/cnsn-to-json/leafref", 2, "main-module", "cont");
26     }
27
28     @Ignore
29     @Test
30     public void leafrefAbsolutePathToExistingLeafTest() {
31         String json = null;
32         try {
33             json = TestUtils.writeCompNodeWithSchemaContextToJson(
34                     TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_absolut_ref_to_existing_leaf.xml"),
35                     modules, dataSchemaNode);
36         } catch (WebApplicationException | IOException e) {
37             // shouldn't end here
38             assertTrue(false);
39         }
40         assertNotNull(json);
41         java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf3\":\\p{Blank}*true.*",
42                 java.util.regex.Pattern.DOTALL);
43         Matcher mtch = ptrn.matcher(json);
44         assertTrue(mtch.matches());
45     }
46
47     @Ignore
48     @Test
49     public void leafrefRelativePathToExistingLeafTest() {
50         String json = null;
51         try {
52             json = TestUtils.writeCompNodeWithSchemaContextToJson(
53                     TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_relativ_ref_to_existing_leaf.xml"),
54                     modules, dataSchemaNode);
55         } catch (WebApplicationException | IOException e) {
56             // shouldn't end here
57             assertTrue(false);
58         }
59         assertNotNull(json);
60         java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf2\":\\p{Blank}*121.*",
61                 java.util.regex.Pattern.DOTALL);
62         Matcher mtch = ptrn.matcher(json);
63         assertTrue(mtch.matches());
64     }
65
66     /**
67      * Tests case when reference to not existing element is present. In this
68      * case value from single node is printed as string.
69      */
70     @Ignore
71     @Test
72     public void leafrefToNonExistingLeafTest() {
73         String json = null;
74         try {
75             json = TestUtils.writeCompNodeWithSchemaContextToJson(
76                     TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_ref_to_non_existing_leaf.xml"),
77                     modules, dataSchemaNode);
78         } catch (WebApplicationException | IOException e) {
79             // shouldn't end here
80             assertTrue(false);
81         }
82         assertNotNull(json);
83         java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf5\":\\p{Blank}*\"137\".*",
84                 java.util.regex.Pattern.DOTALL);
85         Matcher mtch = ptrn.matcher(json);
86         assertTrue(mtch.matches());
87     }
88
89     /**
90      * Tests case when non leaf element is referenced. In this case value from
91      * single node is printed as string.
92      */
93     @Ignore
94     @Test
95     public void leafrefToNotLeafTest() {
96         String json = null;
97         try {
98             json = TestUtils.writeCompNodeWithSchemaContextToJson(
99                     TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_ref_to_not_leaf.xml"), modules,
100                     dataSchemaNode);
101         } catch (WebApplicationException | IOException e) {
102             // shouldn't end here
103             assertTrue(false);
104         }
105         assertNotNull(json);
106         java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(
107                 ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf6\":\\p{Blank}*\"44.33\".*",
108                 java.util.regex.Pattern.DOTALL);
109         Matcher mtch = ptrn.matcher(json);
110         assertTrue(mtch.matches());
111     }
112
113     /**
114      * Tests case when leaflist element is refers to leaf.
115      */
116     @Ignore
117     @Test
118     public void leafrefFromLeafListToLeafTest() {
119         String json = null;
120         try {
121             json = TestUtils
122                     .writeCompNodeWithSchemaContextToJson(
123                             TestUtils
124                                     .loadCompositeNode("/cnsn-to-json/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml"),
125                             modules, dataSchemaNode);
126         } catch (WebApplicationException | IOException e) {
127             // shouldn't end here
128             assertTrue(false);
129         }
130         assertNotNull(json);
131         java.util.regex.Pattern ptrn = java.util.regex.Pattern
132                 .compile(
133                         ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lflst1\":\\p{Blank}*.*345,\\p{Space}*346,\\p{Space}*347.*",
134                         java.util.regex.Pattern.DOTALL);
135         Matcher mtch = ptrn.matcher(json);
136         assertTrue(mtch.matches());
137     }
138
139     /**
140      * Tests case when leaflist element is refers to leaf.
141      */
142     @Ignore
143     @Test
144     public void leafrefFromLeafrefToLeafrefTest() {
145         String json = null;
146         try {
147             json = TestUtils.writeCompNodeWithSchemaContextToJson(
148                     TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_from_leafref_to_leafref.xml"), modules,
149                     dataSchemaNode);
150         } catch (WebApplicationException | IOException e) {
151             // shouldn't end here
152             assertTrue(false);
153         }
154         assertNotNull(json);
155         java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(
156                 ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf7\":\\p{Blank}*200.*", java.util.regex.Pattern.DOTALL);
157         Matcher mtch = ptrn.matcher(json);
158         assertTrue(mtch.matches());
159     }
160
161 }