1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
3 import static org.junit.Assert.assertTrue;
5 import java.io.IOException;
7 import java.net.URISyntaxException;
8 import java.util.regex.Matcher;
9 import java.util.regex.Pattern;
11 import javax.ws.rs.WebApplicationException;
13 import org.junit.BeforeClass;
14 import org.junit.Test;
15 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
16 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
17 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
18 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
19 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
20 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
21 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader {
27 public static void initialize() {
28 dataLoad("/xml-to-cnsn/data-of-several-modules/yang",2,"module1","cont_m1");
32 public void dataFromSeveralModulesToJsonTest() throws WebApplicationException, IOException, URISyntaxException {
33 SchemaContext schemaContext = TestUtils.loadSchemaContext(modules);
34 String output = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCnSn(), modules, schemaContext,
35 StructuredDataToJsonProvider.INSTANCE);
38 // String.format("\"data\" : {\n" +
39 // "\t\"cont_m1\" : {\n" +
40 // "\t\t\"lf1_m1\" : \"lf1 m1 value\"\n" +
42 // "\t\"cont_m2\" : {\n" +
43 // "\t\t\"lf1_m2\" : \"lf1 m2 value\"\n" +
47 StringBuilder regex = new StringBuilder();
50 regex.append(".*\"data\"");
52 regex.append(".*\\{");
54 regex.append(".*\"contB_m1\"");
56 regex.append(".*\\{");
57 regex.append(".*\\}");
59 regex.append(".*\"cont_m1\"");
61 regex.append(".*\\{");
62 regex.append(".*\\}");
64 regex.append(".*\"contB_m2\"");
66 regex.append(".*\\{");
67 regex.append(".*\\}");
69 regex.append(".*\"cont_m2\"");
71 regex.append(".*\\{");
72 regex.append(".*\\}");
74 regex.append(".*\\}");
79 Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
80 Matcher matcher = ptrn.matcher(output);
82 assertTrue(matcher.find());
86 private CompositeNode prepareCnSn() throws URISyntaxException {
87 CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data");
89 URI uriModule1 = new URI("module:one");
90 CompositeNodeWrapper cont_m1 = new CompositeNodeWrapper(uriModule1, "cont_m1");
91 SimpleNodeWrapper lf1_m1 = new SimpleNodeWrapper(uriModule1, "lf1_m1", "lf1 m1 value");
92 cont_m1.addValue(lf1_m1);
93 CompositeNodeWrapper contB_m1 = new CompositeNodeWrapper(uriModule1, "contB_m1");
95 data.addValue(contB_m1);
96 data.addValue(cont_m1);
98 URI uriModule2 = new URI("module:two");
99 CompositeNodeWrapper cont_m2 = new CompositeNodeWrapper(uriModule2, "cont_m2");
100 SimpleNodeWrapper lf1_m2 = new SimpleNodeWrapper(uriModule2, "lf1_m2", "lf1 m2 value");
101 cont_m2.addValue(lf1_m2);
102 CompositeNodeWrapper contB_m2 = new CompositeNodeWrapper(uriModule2, "contB_m2");
103 data.addValue(contB_m2);
104 data.addValue(cont_m2);