X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fcnsn%2Fto%2Fjson%2Ftest%2FCnSnToJsonWithDataFromSeveralModulesTest.java;h=a84fc79b86fbc9bb1d028859b629aeb1ecbfe622;hp=fdc10b7150fdb35711f0713676fdfd5074e17086;hb=c222e37f2a0f0f3f6266242fbea2d3b018f4e6e3;hpb=3d7c462c9ae27873c3a6cd484f2f228f74cd8b12 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithDataFromSeveralModulesTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithDataFromSeveralModulesTest.java index fdc10b7150..a84fc79b86 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithDataFromSeveralModulesTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithDataFromSeveralModulesTest.java @@ -1,31 +1,35 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test; import static org.junit.Assert.assertTrue; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.ws.rs.WebApplicationException; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider; -import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; -import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; -import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper; import org.opendaylight.controller.sal.restconf.impl.test.TestUtils; import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader; import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode; +import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode; +import org.opendaylight.yangtools.yang.data.impl.NodeFactory; import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataSchemaLoader { @BeforeClass public static void initialize() { - dataLoad("/xml-to-cnsn/data-of-several-modules/yang",2,"module1","cont_m1"); + dataLoad("/xml-to-cnsn/data-of-several-modules/yang", 2, "module1", "cont_m1"); } @Test @@ -34,15 +38,15 @@ public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataS String output = TestUtils.writeCompNodeWithSchemaContextToOutput(prepareCnSn(), modules, schemaContext, StructuredDataToJsonProvider.INSTANCE); -// String output = -// String.format("\"data\" : {\n" + -// "\t\"cont_m1\" : {\n" + -// "\t\t\"lf1_m1\" : \"lf1 m1 value\"\n" + -// "\t}\n" + -// "\t\"cont_m2\" : {\n" + -// "\t\t\"lf1_m2\" : \"lf1 m2 value\"\n" + -// "\t}\n" + -// "}"); + // String output = + // String.format("\"data\" : {\n" + + // "\t\"cont_m1\" : {\n" + + // "\t\t\"lf1_m1\" : \"lf1 m1 value\"\n" + + // "\t}\n" + + // "\t\"cont_m2\" : {\n" + + // "\t\t\"lf1_m2\" : \"lf1 m2 value\"\n" + + // "\t}\n" + + // "}"); StringBuilder regex = new StringBuilder(); regex.append("^"); @@ -50,27 +54,27 @@ public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataS regex.append(".*\"data\""); regex.append(".*:"); regex.append(".*\\{"); - - regex.append(".*\"contB_m1\""); + + regex.append(".*\"cont_m1\""); regex.append(".*:"); regex.append(".*\\{"); regex.append(".*\\}"); - - regex.append(".*\"cont_m1\""); + + regex.append(".*\"contB_m1\""); regex.append(".*:"); regex.append(".*\\{"); regex.append(".*\\}"); - regex.append(".*\"contB_m2\""); + regex.append(".*\"cont_m2\""); regex.append(".*:"); regex.append(".*\\{"); regex.append(".*\\}"); - - regex.append(".*\"cont_m2\""); + + regex.append(".*\"contB_m2\""); regex.append(".*:"); regex.append(".*\\{"); regex.append(".*\\}"); - + regex.append(".*\\}"); regex.append(".*"); @@ -84,24 +88,44 @@ public class CnSnToJsonWithDataFromSeveralModulesTest extends YangAndXmlAndDataS } private CompositeNode prepareCnSn() throws URISyntaxException { - CompositeNodeWrapper data = new CompositeNodeWrapper(new URI("urn:ietf:params:xml:ns:netconf:base:1.0"), "data"); - - URI uriModule1 = new URI("module:one"); - CompositeNodeWrapper cont_m1 = new CompositeNodeWrapper(uriModule1, "cont_m1"); - SimpleNodeWrapper lf1_m1 = new SimpleNodeWrapper(uriModule1, "lf1_m1", "lf1 m1 value"); - cont_m1.addValue(lf1_m1); - CompositeNodeWrapper contB_m1 = new CompositeNodeWrapper(uriModule1, "contB_m1"); - - data.addValue(contB_m1); - data.addValue(cont_m1); - - URI uriModule2 = new URI("module:two"); - CompositeNodeWrapper cont_m2 = new CompositeNodeWrapper(uriModule2, "cont_m2"); - SimpleNodeWrapper lf1_m2 = new SimpleNodeWrapper(uriModule2, "lf1_m2", "lf1 m2 value"); - cont_m2.addValue(lf1_m2); - CompositeNodeWrapper contB_m2 = new CompositeNodeWrapper(uriModule2, "contB_m2"); - data.addValue(contB_m2); - data.addValue(cont_m2); + String uri1 = "module:one"; + String rev1 = "2014-01-17"; + + MutableCompositeNode data = NodeFactory.createMutableCompositeNode( + TestUtils.buildQName("data", "urn:ietf:params:xml:ns:netconf:base:1.0", "2000-01-01"), null, null, + null, null); + + MutableCompositeNode cont_m1 = NodeFactory.createMutableCompositeNode( + TestUtils.buildQName("cont_m1", uri1, rev1), data, null, null, null); + data.getValue().add(cont_m1); + + MutableSimpleNode lf1_m1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1_m1", uri1, rev1), + cont_m1, "lf1 m1 value", null, null); + cont_m1.getValue().add(lf1_m1); + cont_m1.init(); + + MutableCompositeNode contB_m1 = NodeFactory.createMutableCompositeNode( + TestUtils.buildQName("contB_m1", uri1, rev1), data, null, null, null); + data.getValue().add(contB_m1); + contB_m1.init(); + + String uri2 = "module:two"; + String rev2 = "2014-01-17"; + MutableCompositeNode cont_m2 = NodeFactory.createMutableCompositeNode( + TestUtils.buildQName("cont_m2", uri2, rev2), data, null, null, null); + data.getValue().add(cont_m2); + + MutableSimpleNode lf1_m2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1_m2", uri2, rev2), + cont_m1, "lf1 m2 value", null, null); + cont_m2.getValue().add(lf1_m2); + cont_m2.init(); + + MutableCompositeNode contB_m2 = NodeFactory.createMutableCompositeNode( + TestUtils.buildQName("contB_m2", uri2, rev2), data, null, null, null); + data.getValue().add(contB_m2); + contB_m2.init(); + + data.init(); return data; }