1 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.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.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;
23 public class CnSnToXmlWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader {
26 public static void initialize() {
27 dataLoad("/xml-to-cnsn/data-of-several-modules/yang",2,"module1","cont_m1");
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);
37 // String.format("<data>" +
40 // "\n\t\tlf1 m1 value" +
45 // "\n\t\tlf1 m2 value" +
50 StringBuilder regex = new StringBuilder();
53 regex.append(".*<data.*");
54 regex.append(".*xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"");
58 regex.append(".*<contB_m1.*\\/>");
59 regex.append(".*xmlns=\"module:one\"");
61 regex.append(".*<lf1_m1.*>");
62 regex.append(".*<\\/lf1_m1>");
63 regex.append(".*<\\/cont_m1>");
65 regex.append(".*<contB_m2.*/>");
66 regex.append(".*<cont_m2.*");
67 regex.append(".*xmlns=\"module:two\"");
69 regex.append(".*<lf1_m2.*>");
70 regex.append(".*<\\/lf1_m2>");
71 regex.append(".*<\\/cont_m2>");
73 regex.append(".*<\\/data.*>");
78 Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
79 Matcher matcher = ptrn.matcher(output);
81 assertTrue(matcher.find());
85 private CompositeNode prepareCnSn() throws URISyntaxException {
86 CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data");
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");
94 data.addValue(contB_m1);
95 data.addValue(cont_m1);
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);