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 / xml / test / CnSnToXmlWithDataFromSeveralModulesTest.java
1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.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.StructuredDataToXmlProvider;
16 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
17 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
18 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
19 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
20 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22
23 public class CnSnToXmlWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader {
24
25     @BeforeClass
26     public static void initialize() {
27         dataLoad("/xml-to-cnsn/data-of-several-modules/yang",2,"module1","cont_m1");
28     }
29
30     @Test
31     public void dataFromSeveralModulesToXmlTest() throws WebApplicationException, IOException, URISyntaxException {
32         SchemaContext schemaContext = TestUtils.loadSchemaContext(modules);
33         String output = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCnSn(), modules, schemaContext,
34                 StructuredDataToXmlProvider.INSTANCE);
35
36 //         String output =
37 //         String.format("<data>" +
38 //                       "\n<cont_m1>" +
39 //                              "\n\t<lf1_m1>" +
40 //                                  "\n\t\tlf1 m1 value" +
41 //                              "\n\t</lf1_m1>" +
42 //                         "\n</cont_m1>" +
43 //                         "\n<cont_m2>" +
44 //                             "\n\t<lf1_m2>" +
45 //                                 "\n\t\tlf1 m2 value" +
46 //                             "\n\t</lf1_m2>" +
47 //                         "\n</cont_m2>" +
48 //                     "\n</data>");
49
50         StringBuilder regex = new StringBuilder();
51         regex.append("^");
52
53         regex.append(".*<data.*");
54         regex.append(".*xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"");
55         regex.append(".*>");
56         
57         
58         regex.append(".*<contB_m1.*\\/>");
59         regex.append(".*xmlns=\"module:one\"");
60         regex.append(".*>");
61         regex.append(".*<lf1_m1.*>");
62         regex.append(".*<\\/lf1_m1>");
63         regex.append(".*<\\/cont_m1>");
64
65         regex.append(".*<contB_m2.*/>");
66         regex.append(".*<cont_m2.*");
67         regex.append(".*xmlns=\"module:two\"");
68         regex.append(".*>");
69         regex.append(".*<lf1_m2.*>");
70         regex.append(".*<\\/lf1_m2>");
71         regex.append(".*<\\/cont_m2>");
72
73         regex.append(".*<\\/data.*>");
74
75         regex.append(".*");
76         regex.append("$");
77
78         Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
79         Matcher matcher = ptrn.matcher(output);
80
81         assertTrue(matcher.find());
82
83     }
84
85     private CompositeNode prepareCnSn() throws URISyntaxException {
86         CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data");
87
88         URI uriModule1 = new URI("module:one");
89         CompositeNodeWrapper cont_m1 = new CompositeNodeWrapper(uriModule1, "cont_m1");
90         SimpleNodeWrapper lf1_m1 = new SimpleNodeWrapper(uriModule1, "lf1_m1", "lf1 m1 value");
91         cont_m1.addValue(lf1_m1);
92         CompositeNodeWrapper contB_m1 = new CompositeNodeWrapper(uriModule1, "contB_m1");
93         
94         data.addValue(contB_m1);
95         data.addValue(cont_m1);
96
97         URI uriModule2 = new URI("module:two");
98         CompositeNodeWrapper cont_m2 = new CompositeNodeWrapper(uriModule2, "cont_m2");
99         SimpleNodeWrapper lf1_m2 = new SimpleNodeWrapper(uriModule2, "lf1_m2", "lf1 m2 value");
100         cont_m2.addValue(lf1_m2);
101         CompositeNodeWrapper contB_m2 = new CompositeNodeWrapper(uriModule2, "contB_m2");
102         data.addValue(contB_m2);
103         data.addValue(cont_m2);
104         return data;
105     }
106
107 }