1 package org.opendaylight.controller.sal.restconf.impl.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;
13 public class ToJsonLeafrefType extends YangAndXmlAndDataSchemaLoader {
16 public static void initialization() {
17 dataLoad("/yang-to-json-conversion/leafref", 2, "main-module", "cont");
21 public void leafrefAbsolutePathToExistingLeafTest() {
24 json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
25 .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_absolut_ref_to_existing_leaf.xml"),
26 "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
27 } catch (WebApplicationException | IOException e) {
32 java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf3\":\\p{Blank}*true.*",
33 java.util.regex.Pattern.DOTALL);
34 Matcher mtch = ptrn.matcher(json);
35 assertTrue(mtch.matches());
39 public void leafrefRelativePathToExistingLeafTest() {
42 json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
43 .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_relativ_ref_to_existing_leaf.xml"),
44 "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
45 } catch (WebApplicationException | IOException e) {
50 java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf2\":\\p{Blank}*121.*",
51 java.util.regex.Pattern.DOTALL);
52 Matcher mtch = ptrn.matcher(json);
53 assertTrue(mtch.matches());
57 * Tests case when reference to not existing element is present. In this
58 * case value from single node is printed as string.
61 public void leafrefToNonExistingLeafTest() {
64 json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
65 .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_ref_to_non_existing_leaf.xml"),
66 "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
67 } catch (WebApplicationException | IOException e) {
72 java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(".*\"lf5\":\\p{Blank}*\"137\".*",
73 java.util.regex.Pattern.DOTALL);
74 Matcher mtch = ptrn.matcher(json);
75 assertTrue(mtch.matches());
79 * Tests case when non leaf element is referenced. In this case value from
80 * single node is printed as string.
83 public void leafrefToNotLeafTest() {
86 json = TestUtils.writeCompNodeWithSchemaContextToJson(
87 TestUtils.loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_ref_to_not_leaf.xml"),
88 "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
89 } catch (WebApplicationException | IOException e) {
94 java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(
95 ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf6\":\\p{Blank}*\"44.33\".*",
96 java.util.regex.Pattern.DOTALL);
97 Matcher mtch = ptrn.matcher(json);
98 assertTrue(mtch.matches());
102 * Tests case when leaflist element is refers to leaf.
105 public void leafrefFromLeafListToLeafTest() {
109 .writeCompNodeWithSchemaContextToJson(
111 .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml"),
112 "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
113 } catch (WebApplicationException | IOException e) {
114 // shouldn't end here
118 java.util.regex.Pattern ptrn = java.util.regex.Pattern
120 ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lflst1\":\\p{Blank}*.*345,\\p{Space}*346,\\p{Space}*347.*",
121 java.util.regex.Pattern.DOTALL);
122 Matcher mtch = ptrn.matcher(json);
123 assertTrue(mtch.matches());
127 * Tests case when leaflist element is refers to leaf.
130 public void leafrefFromLeafrefToLeafrefTest() {
133 json = TestUtils.writeCompNodeWithSchemaContextToJson(TestUtils
134 .loadCompositeNode("/yang-to-json-conversion/leafref/xml/data_from_leafref_to_leafref.xml"),
135 "/yang-to-json-conversion/leafref/xml", modules, dataSchemaNode);
136 } catch (WebApplicationException | IOException e) {
137 // shouldn't end here
141 java.util.regex.Pattern ptrn = java.util.regex.Pattern.compile(
142 ".*\"cont-augment-module\\p{Blank}*:\\p{Blank}*lf7\":\\p{Blank}*200.*", java.util.regex.Pattern.DOTALL);
143 Matcher mtch = ptrn.matcher(json);
144 assertTrue(mtch.matches());