Changed mount point URI decoding in restconf
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / json / test / CnSnToJsonWithDataFromSeveralModulesTest.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
2
3 import static org.junit.Assert.assertTrue;
4
5 import java.io.IOException;
6 import java.net.URI;
7 import java.net.URISyntaxException;
8 import java.util.regex.Matcher;
9 import java.util.regex.Pattern;
10
11 import javax.ws.rs.WebApplicationException;
12
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;
23
24 public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader {
25
26     @BeforeClass
27     public static void initialize() {
28         dataLoad("/xml-to-cnsn/data-of-several-modules/yang",2,"module1","cont_m1");
29     }
30
31     @Test
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);
36
37 //         String output =
38 //         String.format("\"data\"   :   {\n" +
39 //                             "\t\"cont_m1\"   :  {\n" +
40 //                                 "\t\t\"lf1_m1\"   :  \"lf1 m1 value\"\n" +
41 //                             "\t}\n" +
42 //                             "\t\"cont_m2\"   :  {\n" +
43 //                                 "\t\t\"lf1_m2\"   :  \"lf1 m2 value\"\n" +
44 //                             "\t}\n" +
45 //                      "}");
46
47         StringBuilder regex = new StringBuilder();
48         regex.append("^");
49
50         regex.append(".*\"data\"");
51         regex.append(".*:");
52         regex.append(".*\\{");
53         
54         regex.append(".*\"contB_m1\"");
55         regex.append(".*:");
56         regex.append(".*\\{");
57         regex.append(".*\\}");
58         
59         regex.append(".*\"cont_m1\"");
60         regex.append(".*:");
61         regex.append(".*\\{");
62         regex.append(".*\\}");
63
64         regex.append(".*\"contB_m2\"");
65         regex.append(".*:");
66         regex.append(".*\\{");
67         regex.append(".*\\}");
68         
69         regex.append(".*\"cont_m2\"");
70         regex.append(".*:");
71         regex.append(".*\\{");
72         regex.append(".*\\}");
73         
74         regex.append(".*\\}");
75
76         regex.append(".*");
77         regex.append("$");
78
79         Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
80         Matcher matcher = ptrn.matcher(output);
81
82         assertTrue(matcher.find());
83
84     }
85
86     private CompositeNode prepareCnSn() throws URISyntaxException {
87         CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data");
88
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");
94         
95         data.addValue(contB_m1);
96         data.addValue(cont_m1);
97
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);
105         return data;
106     }
107
108 }