import javax.ws.rs.WebApplicationException;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
* Test of json output when as input are specified composite node with empty
* data + YANG file
*/
- @Ignore
+
@Test
public void compositeNodeAndYangWithJsonReaderEmptyDataTest() {
CompositeNode compositeNode = prepareCompositeNodeWithEmpties();
TestUtils.buildQName("cont1", "simple:yang:types", "2013-11-5"), null, null, ModifyAction.CREATE, null);
// lst11_1
- MutableCompositeNode lst11_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11"), cont1,
+ MutableCompositeNode lst11_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11","simple:yang:types","2013-11-5"), cont1,
null, ModifyAction.CREATE, null);
cont1.getChildren().add(lst11_1);
- MutableSimpleNode<?> lf111_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_1,
+ MutableSimpleNode<?> lf111_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111","simple:yang:types","2013-11-5"), lst11_1,
(short) 1, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lf111_1);
// lst111_1_1
- MutableCompositeNode lst111_1_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+ MutableCompositeNode lst111_1_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lst111_1_1);
- MutableSimpleNode<?> lf1111_1_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111"),
+ MutableSimpleNode<?> lf1111_1_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111","simple:yang:types","2013-11-5"),
lst111_1_1, (int) 34, ModifyAction.CREATE, null);
lst111_1_1.getChildren().add(lf1111_1_1);
lst111_1_1.init();
// :lst111_1_1
// lst111_1_2
- MutableCompositeNode lst111_1_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+ MutableCompositeNode lst111_1_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lst111_1_2);
- MutableSimpleNode<?> lf1111_1_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111"),
+ MutableSimpleNode<?> lf1111_1_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111","simple:yang:types","2013-11-5"),
lst111_1_2, (int) 35, ModifyAction.CREATE, null);
lst111_1_2.getChildren().add(lf1111_1_2);
lst111_1_2.init();
// :lst111_1_2
// lst111_1_3
- MutableCompositeNode lst111_1_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+ MutableCompositeNode lst111_1_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lst111_1_3);
lst111_1_2.init();
// :lst111_1_3
// lst111_1_4
- MutableCompositeNode lst111_1_4 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111"),
+ MutableCompositeNode lst111_1_4 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst111","simple:yang:types","2013-11-5"),
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(lst111_1_4);
lst111_1_2.init();
// :lst111_1_4
- MutableCompositeNode cont111_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111"),
+ MutableCompositeNode cont111_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111","simple:yang:types","2013-11-5"),
lst11_1, null, ModifyAction.CREATE, null);
lst11_1.getChildren().add(cont111_1);
// :lst11_1
// lst11_2
- MutableCompositeNode lst11_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11"), cont1,
+ MutableCompositeNode lst11_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11","simple:yang:types","2013-11-5"), cont1,
null, ModifyAction.CREATE, null);
cont1.getChildren().add(lst11_2);
- MutableSimpleNode<?> lf111_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_2,
+ MutableSimpleNode<?> lf111_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111","simple:yang:types","2013-11-5"), lst11_2,
(short) 2, ModifyAction.CREATE, null);
lst11_2.getChildren().add(lf111_2);
// cont111_2
- MutableCompositeNode cont111_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111"),
+ MutableCompositeNode cont111_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111","simple:yang:types","2013-11-5"),
lst11_2, null, ModifyAction.CREATE, null);
lst11_2.getChildren().add(cont111_2);
- MutableSimpleNode<?> lflst1111_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111"),
+ MutableSimpleNode<?> lflst1111_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111","simple:yang:types","2013-11-5"),
cont111_2, (int) 1024, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lflst1111_2_2);
- MutableSimpleNode<?> lflst1111_2_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111"),
+ MutableSimpleNode<?> lflst1111_2_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lflst1111","simple:yang:types","2013-11-5"),
cont111_2, (int) 4096, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lflst1111_2_3);
// lst1111_2
- MutableCompositeNode lst1111_2_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+ MutableCompositeNode lst1111_2_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
cont111_2, null, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lst1111_2_1);
- MutableSimpleNode<?> lf1111B_2_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111B"),
+ MutableSimpleNode<?> lf1111B_2_1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111B","simple:yang:types","2013-11-5"),
lst1111_2_1, (short) 4, ModifyAction.CREATE, null);
lst1111_2_1.getChildren().add(lf1111B_2_1);
lst1111_2_1.init();
- MutableCompositeNode lst1111_2_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+ MutableCompositeNode lst1111_2_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
cont111_2, null, ModifyAction.CREATE, null);
cont111_2.getChildren().add(lst1111_2_2);
- MutableSimpleNode<?> lf1111A_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111A"),
+ MutableSimpleNode<?> lf1111A_2_2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1111A","simple:yang:types","2013-11-5"),
lst1111_2_2, "lf1111A str12", ModifyAction.CREATE, null);
lst1111_2_2.getChildren().add(lf1111A_2_2);
lst1111_2_2.init();
cont111_2.init();
// :cont111_2
- MutableCompositeNode lst112_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst112"), lst11_2,
+ MutableCompositeNode lst112_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst112","simple:yang:types","2013-11-5"), lst11_2,
null, ModifyAction.CREATE, null);
lst11_2.getChildren().add(lst112_2);
lst112_2.init();
// :lst11_2
// lst11_3
- MutableCompositeNode lst11_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11"), cont1,
+ MutableCompositeNode lst11_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst11","simple:yang:types","2013-11-5"), cont1,
null, ModifyAction.CREATE, null);
cont1.getChildren().add(lst11_3);
- MutableSimpleNode<?> lf111_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111"), lst11_3,
+ MutableSimpleNode<?> lf111_3 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111","simple:yang:types","2013-11-5"), lst11_3,
(short) 3, ModifyAction.CREATE, null);
lst11_3.getChildren().add(lf111_3);
// cont111_3
- MutableCompositeNode cont111_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111"),
+ MutableCompositeNode cont111_3 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont111","simple:yang:types","2013-11-5"),
lst11_3, null, ModifyAction.CREATE, null);
lst11_3.getChildren().add(cont111_3);
- MutableCompositeNode lst1111_3_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+ MutableCompositeNode lst1111_3_1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
cont111_3, null, ModifyAction.CREATE, null);
cont111_3.getChildren().add(lst1111_3_1);
lst1111_3_1.init();
- MutableCompositeNode lst1111_3_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111"),
+ MutableCompositeNode lst1111_3_2 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("lst1111","simple:yang:types","2013-11-5"),
cont111_3, null, ModifyAction.CREATE, null);
cont111_3.getChildren().add(lst1111_3_2);
lst1111_3_2.init();
import javax.ws.rs.WebApplicationException;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.ModifyAction;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
public class CnSnToJsonIdentityrefTest extends YangAndXmlAndDataSchemaLoader {
dataLoad("/cnsn-to-json/identityref", 2, "identityref-module", "cont");
}
- @Ignore
@Test
public void identityrefToJsonTest() {
String json = null;
assertTrue(mtch.matches());
}
- @Ignore
@Test
public void identityrefToJsonWithoutQNameTest() {
String json = null;
}
private CompositeNode prepareCompositeNode(Object value) {
- MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
+ MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont","identityref:module","2013-12-2"), null, null,
ModifyAction.CREATE, null);
- MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1"), cont, null,
+ MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont1","identityref:module","2013-12-2"), cont, null,
ModifyAction.CREATE, null);
cont.getChildren().add(cont1);
- MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1"), cont1, value,
+ MutableSimpleNode<?> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1","identityref:module","2013-12-2"), cont1, value,
ModifyAction.CREATE, null);
cont1.getChildren().add(lf1);
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
-import org.opendaylight.controller.sal.restconf.impl.test.*;
-import org.opendaylight.yangtools.yang.data.api.*;
+import org.opendaylight.controller.sal.restconf.impl.test.DummyType;
+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.ModifyAction;
+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.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
dataLoad("/cnsn-to-json/simple-data-types");
}
- // FIXME
- @Ignore
@Test
- public void incorrectTopLevelElementTest() {
-
+ public void incorrectTopLevelElementTest() throws WebApplicationException, IOException {
String jsonOutput = null;
- try {
- jsonOutput = TestUtils
- .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
- (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
- StructuredDataToJsonProvider.INSTANCE);
- } catch (WebApplicationException | IOException e) {
- LOG.error("WebApplicationException or IOException was raised");
- }
+ jsonOutput = TestUtils
+ .writeCompNodeWithSchemaContextToOutput(prepareCompositeNode(),
+ (Set<Module>) Collections.EMPTY_SET, prepareDataSchemaNode(),
+ StructuredDataToJsonProvider.INSTANCE);
assertNotNull(jsonOutput);
assertTrue(jsonOutput.contains("\"lf1\": \"\""));
}
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.Ignore;
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");
}
- @Ignore
@Test
public void dataFromSeveralModulesToJsonTest() throws WebApplicationException, IOException, URISyntaxException {
SchemaContext schemaContext = TestUtils.loadSchemaContext(modules);
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("^");
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(".*");
}
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.getChildren().add(cont_m1);
+
+ MutableSimpleNode<?> lf1_m1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1_m1", uri1, rev1),
+ cont_m1, "lf1 m1 value", null, null);
+ cont_m1.getChildren().add(lf1_m1);
+ cont_m1.init();
+
+ MutableCompositeNode contB_m1 = NodeFactory.createMutableCompositeNode(
+ TestUtils.buildQName("contB_m1", uri1, rev1), data, null, null, null);
+ data.getChildren().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.getChildren().add(cont_m2);
+
+ MutableSimpleNode<?> lf1_m2 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf1_m2", uri2, rev2),
+ cont_m1, "lf1 m2 value", null, null);
+ cont_m2.getChildren().add(lf1_m2);
+ cont_m2.init();
+
+ MutableCompositeNode contB_m2 = NodeFactory.createMutableCompositeNode(
+ TestUtils.buildQName("contB_m2", uri2, rev2), data, null, null, null);
+ data.getChildren().add(contB_m2);
+ contB_m2.init();
+
+ data.init();
return data;
}
@BeforeClass
public static void initialization() throws URISyntaxException {
- dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
+ dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
}
@Test
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.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
+import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
@BeforeClass
public static void initialize() {
- dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
+ dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
}
@Test
- public void saveCnSnToXml() throws WebApplicationException, IOException, URISyntaxException, XMLStreamException {
- CompositeNode cnSn = prepareCnSn();
+ public void saveCnSnToXmlTest() throws WebApplicationException, IOException, URISyntaxException, XMLStreamException {
+ CompositeNode cnSn = prepareCnSn(createInstanceIdentifier());
String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
StructuredDataToXmlProvider.INSTANCE);
- validateXmlOutput(output);
+ //uncomment for debug
// System.out.println(output);
+ validateXmlOutput(output);
}
@Ignore
@Test
- public void saveCnSnToJson() throws WebApplicationException, IOException, URISyntaxException {
- CompositeNode cnSn = prepareCnSn();
+ public void saveCnSnWithLeafListInstIdentifierToXmlTest() throws WebApplicationException, IOException,
+ URISyntaxException, XMLStreamException {
+ CompositeNode cnSn = prepareCnSn(createInstanceIdentifierWithLeafList());
+ String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
+ StructuredDataToXmlProvider.INSTANCE);
+ //uncomment for debug
+ // System.out.println(output);
+ validateXmlOutputWithLeafList(output);
+ }
+
+ @Test
+ public void saveCnSnToJsonTest() throws WebApplicationException, IOException, URISyntaxException {
+ CompositeNode cnSn = prepareCnSn(createInstanceIdentifier());
String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
StructuredDataToJsonProvider.INSTANCE);
- assertTrue(output
- .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module:lst11[augment-module:keyvalue111=\\\"value1\\\"][augment-module:keyvalue112=\\\"value2\\\"]/augment-augment-module:lf112\""));
+ boolean strInOutput = false;
+ strInOutput = output
+ .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module:lst11[augment-module:keyvalue111=\\\"value1\\\"][augment-module:keyvalue112=\\\"value2\\\"]/augment-augment-module:lf112\"");
+
+ if (!strInOutput) {
+ strInOutput = output
+ .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module:lst11[augment-module:keyvalue111='value1'][augment-module:keyvalue112='value2']/augment-augment-module:lf112\"");
+ }
+ //uncomment for debug
// System.out.println(output);
+ assertTrue(strInOutput);
+ }
+
+
+ @Test
+ public void saveCnSnWithLeafListInstIdentifierToJsonTest() throws WebApplicationException, IOException,
+ URISyntaxException {
+ CompositeNode cnSn = prepareCnSn(createInstanceIdentifierWithLeafList());
+ String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode,
+ StructuredDataToJsonProvider.INSTANCE);
+ //uncomment for debug
+ // System.out.println(output);
+ boolean strInOutput = false;
+ strInOutput = output
+ .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module-leaf-list:lflst11[.='lflst11_1']\"");
+ if (!strInOutput) {
+ strInOutput = output
+ .contains("\"augment-augment-module:lf111\": \"/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module-leaf-list:lflst11[.=\\\"lflst11_1\\\"]\"");
+ }
+
+ assertTrue(strInOutput);
}
private void validateXmlOutput(String xml) throws XMLStreamException {
+ ":lst11[" + aModulePrefix + ":keyvalue111='value1'][" + aModulePrefix + ":keyvalue112='value2']/"
+ aaModulePrefix + ":lf112";
-// System.out.println(xml);
assertTrue(xml.contains(instanceIdentifierValue));
}
- private CompositeNode prepareCnSn() throws URISyntaxException {
- CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("instance:identifier:module"), "cont");
- CompositeNodeWrapper cont1 = new CompositeNodeWrapper(new URI("instance:identifier:module"), "cont1");
- CompositeNodeWrapper lst11 = new CompositeNodeWrapper(new URI("augment:module"), "lst11");
- InstanceIdentifier instanceIdentifier = createInstanceIdentifier();
- SimpleNodeWrapper lf111 = new SimpleNodeWrapper(new URI("augment:augment:module"), "lf111", instanceIdentifier);
+ private void validateXmlOutputWithLeafList(String xml) throws XMLStreamException {
+ XMLInputFactory xmlInFactory = XMLInputFactory.newInstance();
+ XMLEventReader eventReader;
- lst11.addValue(lf111);
- cont1.addValue(lst11);
- cont.addValue(cont1);
+ eventReader = xmlInFactory.createXMLEventReader(new ByteArrayInputStream(xml.getBytes()));
+ String aModuleLfLstPrefix = null;
+ String iiModulePrefix = null;
+ while (eventReader.hasNext()) {
+ XMLEvent nextEvent = eventReader.nextEvent();
+ if (nextEvent.isStartElement()) {
+ StartElement startElement = (StartElement) nextEvent;
+ if (startElement.getName().getLocalPart().equals("lf111")) {
+ Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:module:leaf:list");
+
+ while (prefixes.hasNext() && aModuleLfLstPrefix == null) {
+ String prefix = (String) prefixes.next();
+ if (!prefix.isEmpty()) {
+ aModuleLfLstPrefix = prefix;
+ }
+ }
+ iiModulePrefix = startElement.getNamespaceContext().getPrefix("instance:identifier:module");
+ break;
+ }
+ }
+ }
+
+ assertNotNull(aModuleLfLstPrefix);
+ assertNotNull(iiModulePrefix);
+
+ String instanceIdentifierValue = "/" + iiModulePrefix + ":cont/" + iiModulePrefix + ":cont1/"
+ + aModuleLfLstPrefix + ":lflst11[.='lflst11_1']";
+
+ assertTrue(xml.contains(instanceIdentifierValue));
+
+ }
+
+ private CompositeNode prepareCnSn(InstanceIdentifier instanceIdentifier) throws URISyntaxException {
+ MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
+ TestUtils.buildQName("cont", "instance:identifier:module", "2014-01-17"), null, null,null,null);
+ MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(
+ TestUtils.buildQName("cont1", "instance:identifier:module", "2014-01-17"), cont, null,null,null);
+ MutableCompositeNode lst11 = NodeFactory.createMutableCompositeNode(
+ TestUtils.buildQName("lst11", "augment:module", "2014-01-17"), cont1, null,null,null);
+
+ MutableSimpleNode<?> lf111 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName("lf111", "augment:augment:module", "2014-01-17"),
+ lst11, instanceIdentifier,null,null);
+
+
+ lst11.getChildren().add(lf111);
+ lst11.init();
+
+ cont1.getChildren().add(lst11);
+ cont1.init();
+
+ cont.getChildren().add(cont1);
+ cont.init();
return cont;
}
return new InstanceIdentifier(pathArguments);
}
+ private InstanceIdentifier createInstanceIdentifierWithLeafList() throws URISyntaxException {
+ List<PathArgument> pathArguments = new ArrayList<>();
+ pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont")));
+ pathArguments.add(new NodeIdentifier(new QName(new URI("instance:identifier:module"), "cont1")));
+ pathArguments.add(new NodeWithValue(new QName(new URI("augment:module:leaf:list"), "lflst11"), "lflst11_1"));
+
+ return new InstanceIdentifier(pathArguments);
+ }
+
}
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
@BeforeClass
public static void initialize() {
- dataLoad("/instanceidentifier/yang", 3, "instance-identifier-module", "cont");
+ dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
}
@Test
CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata.xml",
XmlToCompositeNodeProvider.INSTANCE);
TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
- verify(cnSn);
+ verifyListPredicate(cnSn);
+ }
+
+ @Test
+ public void loadXmlLeafListToCnSn() throws WebApplicationException, IOException, URISyntaxException {
+ CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata_leaf_list.xml",
+ XmlToCompositeNodeProvider.INSTANCE);
+ TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
+ verifyLeafListPredicate(cnSn);
}
@Test
CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata.json",
JsonToCompositeNodeProvider.INSTANCE);
TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
- verify(cnSn);
+ verifyListPredicate(cnSn);
}
- private void verify(CompositeNode cnSn) throws URISyntaxException {
- SimpleNode<?> lf111 = getSnWithInstanceIdentifier(cnSn);
+ @Test
+ public void loadJsonLeafListToCnSn() throws WebApplicationException, IOException, URISyntaxException {
+ CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata_leaf_list.json",
+ JsonToCompositeNodeProvider.INSTANCE);
+ TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath);
+ verifyLeafListPredicate(cnSn);
+ }
+
+ private void verifyLeafListPredicate(CompositeNode cnSn) throws URISyntaxException {
+ SimpleNode<?> lf11 = getSnWithInstanceIdentifierWhenLeafList(cnSn);
+ Object value = lf11.getValue();
+ assertTrue(value instanceof InstanceIdentifier);
+
+ InstanceIdentifier instanceIdentifier = (InstanceIdentifier) value;
+ List<PathArgument> pathArguments = instanceIdentifier.getPath();
+ assertEquals(3, pathArguments.size());
+ String revisionDate = "2014-01-17";
+ assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
+ .getNodeType());
+ assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
+ .getNodeType());
+ assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), pathArguments.get(2)
+ .getNodeType());
+
+ assertTrue(pathArguments.get(2) instanceof NodeWithValue);
+ assertEquals("lflst11_1", ((NodeWithValue) pathArguments.get(2)).getValue());
+
+ }
+
+ private void verifyListPredicate(CompositeNode cnSn) throws URISyntaxException {
+ SimpleNode<?> lf111 = getSnWithInstanceIdentifierWhenList(cnSn);
Object value = lf111.getValue();
assertTrue(value instanceof InstanceIdentifier);
assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
}
- private SimpleNode<?> getSnWithInstanceIdentifier(CompositeNode cnSn) throws URISyntaxException {
+ private SimpleNode<?> getSnWithInstanceIdentifierWhenList(CompositeNode cnSn) throws URISyntaxException {
CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
"2014-01-17"));
assertNotNull(cont1);
return lf111;
}
+ private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(CompositeNode cnSn) throws URISyntaxException {
+ CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
+ "2014-01-17"));
+ assertNotNull(cont1);
+ SimpleNode<?> lf11 = cont1.getFirstSimpleByName(TestUtils.buildQName("lf11", "augment:module:leaf:list",
+ "2014-01-27"));
+ assertNotNull(lf11);
+ return lf11;
+ }
+
}
--- /dev/null
+{
+ "instance-identifier-module:cont": {
+ "cont1": {
+ "augment-module-leaf-list:lf11" : "/instance-identifier-module:cont/instance-identifier-module:cont1/augment-module-leaf-list:lflst11[.=\"lflst11_1\"]"
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<cont xmlns="instance:identifier:module">
+ <cont1>
+ <lflst11 xmlns="augment:module:leaf:list">lflst11_1</lflst11>
+ <lflst11 xmlns="augment:module:leaf:list">lflst11_2</lflst11>
+ <lflst11 xmlns="augment:module:leaf:list">lflst11_3</lflst11>
+ <lf11 xmlns:a="instance:identifier:module" xmlns:b="augment:module:leaf:list" xmlns="augment:module:leaf:list">/a:cont/a:cont1/b:lflst11[.="lflst11_1"]</lf11>
+ </cont1>
+</cont>
--- /dev/null
+module augment-module-leaf-list {
+ namespace "augment:module:leaf:list";
+
+ prefix "amodulelflst";
+
+ import instance-identifier-module {prefix imodule; revision-date 2014-01-17;}
+
+ revision 2014-01-27 {
+ }
+
+ augment "/imodule:cont/imodule:cont1" {
+ leaf-list lflst11 {
+ type string;
+ }
+ leaf lf11 {
+ type instance-identifier;
+ }
+ }
+
+}
\ No newline at end of file