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