1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
6 import java.io.IOException;
7 import java.util.regex.Matcher;
9 import javax.ws.rs.WebApplicationException;
12 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
13 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
17 * All tests are commented now because leafref isn't supported now
21 public class ToJsonLeafrefType extends YangAndXmlAndDataSchemaLoader {
24 public static void initialization() {
25 dataLoad("/cnsn-to-json/leafref", 2, "main-module", "cont");
30 public void leafrefAbsolutePathToExistingLeafTest() {
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) {
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());
49 public void leafrefRelativePathToExistingLeafTest() {
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) {
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());
67 * Tests case when reference to not existing element is present. In this
68 * case value from single node is printed as string.
72 public void leafrefToNonExistingLeafTest() {
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) {
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());
90 * Tests case when non leaf element is referenced. In this case value from
91 * single node is printed as string.
95 public void leafrefToNotLeafTest() {
98 json = TestUtils.writeCompNodeWithSchemaContextToJson(
99 TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_ref_to_not_leaf.xml"), modules,
101 } catch (WebApplicationException | IOException e) {
102 // shouldn't end here
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());
114 * Tests case when leaflist element is refers to leaf.
118 public void leafrefFromLeafListToLeafTest() {
122 .writeCompNodeWithSchemaContextToJson(
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
131 java.util.regex.Pattern ptrn = java.util.regex.Pattern
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());
140 * Tests case when leaflist element is refers to leaf.
144 public void leafrefFromLeafrefToLeafrefTest() {
147 json = TestUtils.writeCompNodeWithSchemaContextToJson(
148 TestUtils.loadCompositeNode("/cnsn-to-json/leafref/xml/data_from_leafref_to_leafref.xml"), modules,
150 } catch (WebApplicationException | IOException e) {
151 // shouldn't end here
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());