Apply style rules on whole sal-rest-connector
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / cnsn / to / xml / test / CnSnToXmlWithDataFromSeveralModulesTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.io.IOException;
13 import java.net.URI;
14 import java.net.URISyntaxException;
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
17 import javax.ws.rs.WebApplicationException;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
21 import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
22 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
23 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
24 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
25 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27
28 public class CnSnToXmlWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader {
29
30     @BeforeClass
31     public static void initialize() {
32         dataLoad("/xml-to-cnsn/data-of-several-modules/yang", 2, "module1", "cont_m1");
33     }
34
35     @Test
36     public void dataFromSeveralModulesToXmlTest() throws WebApplicationException, IOException, URISyntaxException {
37         SchemaContext schemaContext = TestUtils.loadSchemaContext(modules);
38         String output = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCnSn(), modules, schemaContext,
39                 StructuredDataToXmlProvider.INSTANCE);
40
41         // String output =
42         // String.format("<data>" +
43         // "\n<cont_m1>" +
44         // "\n\t<lf1_m1>" +
45         // "\n\t\tlf1 m1 value" +
46         // "\n\t</lf1_m1>" +
47         // "\n</cont_m1>" +
48         // "\n<cont_m2>" +
49         // "\n\t<lf1_m2>" +
50         // "\n\t\tlf1 m2 value" +
51         // "\n\t</lf1_m2>" +
52         // "\n</cont_m2>" +
53         // "\n</data>");
54
55         StringBuilder regex = new StringBuilder();
56         regex.append("^");
57
58         regex.append(".*<data.*");
59         regex.append(".*xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"");
60         regex.append(".*>");
61
62         regex.append(".*<contB_m1.*\\/>");
63         regex.append(".*xmlns=\"module:one\"");
64         regex.append(".*>");
65         regex.append(".*<lf1_m1.*>");
66         regex.append(".*<\\/lf1_m1>");
67         regex.append(".*<\\/cont_m1>");
68
69         regex.append(".*<contB_m2.*/>");
70         regex.append(".*<cont_m2.*");
71         regex.append(".*xmlns=\"module:two\"");
72         regex.append(".*>");
73         regex.append(".*<lf1_m2.*>");
74         regex.append(".*<\\/lf1_m2>");
75         regex.append(".*<\\/cont_m2>");
76
77         regex.append(".*<\\/data.*>");
78
79         regex.append(".*");
80         regex.append("$");
81
82         Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
83         Matcher matcher = ptrn.matcher(output);
84
85         assertTrue(matcher.find());
86
87     }
88
89     private CompositeNode prepareCnSn() throws URISyntaxException {
90         CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data");
91
92         URI uriModule1 = new URI("module:one");
93         CompositeNodeWrapper cont_m1 = new CompositeNodeWrapper(uriModule1, "cont_m1");
94         SimpleNodeWrapper lf1_m1 = new SimpleNodeWrapper(uriModule1, "lf1_m1", "lf1 m1 value");
95         cont_m1.addValue(lf1_m1);
96         CompositeNodeWrapper contB_m1 = new CompositeNodeWrapper(uriModule1, "contB_m1");
97
98         data.addValue(contB_m1);
99         data.addValue(cont_m1);
100
101         URI uriModule2 = new URI("module:two");
102         CompositeNodeWrapper cont_m2 = new CompositeNodeWrapper(uriModule2, "cont_m2");
103         SimpleNodeWrapper lf1_m2 = new SimpleNodeWrapper(uriModule2, "lf1_m2", "lf1 m2 value");
104         cont_m2.addValue(lf1_m2);
105         CompositeNodeWrapper contB_m2 = new CompositeNodeWrapper(uriModule2, "contB_m2");
106         data.addValue(contB_m2);
107         data.addValue(cont_m2);
108         return data;
109     }
110
111 }