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%2Ftest%2FCnSnToXmlAndJsonInstanceIdentifierTest.java;h=79e51681ca127955231057740d021a513d2e89ee;hp=18b5ce490ff137f7da978052a09819a6a5b4e1d1;hb=c222e37f2a0f0f3f6266242fbea2d3b018f4e6e3;hpb=6fd408a04fe4a3611843e2246ece6d7c34b76903 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java index 18b5ce490f..79e51681ca 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/CnSnToXmlAndJsonInstanceIdentifierTest.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.opendaylight.controller.sal.restconf.impl.test.TestUtils.containsStringData; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -19,29 +20,27 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; - import javax.ws.rs.WebApplicationException; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; - 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.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.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; import org.opendaylight.yangtools.yang.data.impl.NodeFactory; +import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder; public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader { @@ -55,21 +54,16 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch CompositeNode cnSn = prepareCnSn(createInstanceIdentifier()); String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode, StructuredDataToXmlProvider.INSTANCE); - //uncomment for debug - // System.out.println(output); validateXmlOutput(output); } - @Ignore @Test 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); } @@ -79,39 +73,46 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch String output = TestUtils.writeCompNodeWithSchemaContextToOutput(cnSn, modules, dataSchemaNode, StructuredDataToJsonProvider.INSTANCE); 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\""); + strInOutput = containsStringData( + output, + "\"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\""); + strInOutput = containsStringData( + output, + "\"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']\""); + strInOutput = containsStringData( + output, + "\"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\\\"]\""); + strInOutput = containsStringData( + output, + "\"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 { + private void validateXmlOutput(final String xml) throws XMLStreamException { XMLInputFactory xmlInFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader; @@ -124,7 +125,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch if (nextEvent.isStartElement()) { StartElement startElement = (StartElement) nextEvent; if (startElement.getName().getLocalPart().equals("lf111")) { - Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:augment:module"); + Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:augment:module"); while (prefixes.hasNext() && aaModulePrefix == null) { String prefix = (String) prefixes.next(); @@ -152,7 +153,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch } - private void validateXmlOutputWithLeafList(String xml) throws XMLStreamException { + private void validateXmlOutputWithLeafList(final String xml) throws XMLStreamException { XMLInputFactory xmlInFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader; @@ -164,7 +165,7 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch if (nextEvent.isStartElement()) { StartElement startElement = (StartElement) nextEvent; if (startElement.getName().getLocalPart().equals("lf111")) { - Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:module:leaf:list"); + Iterator prefixes = startElement.getNamespaceContext().getPrefixes("augment:module:leaf:list"); while (prefixes.hasNext() && aModuleLfLstPrefix == null) { String prefix = (String) prefixes.next(); @@ -188,31 +189,25 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch } - 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; + private CompositeNode prepareCnSn(final YangInstanceIdentifier instanceIdentifier) throws URISyntaxException { + CompositeNodeBuilder cont = ImmutableCompositeNode.builder(); + cont.setQName(QName.create("instance:identifier:module", "2014-01-17", "cont")); + + CompositeNodeBuilder cont1 = ImmutableCompositeNode.builder(); + cont1.setQName(QName.create("instance:identifier:module", "2014-01-17", "cont1")); + + CompositeNodeBuilder lst11 = ImmutableCompositeNode.builder(); + lst11.setQName(QName.create("augment:module", "2014-01-17", "lst11")); + + SimpleNode lf111 = NodeFactory.createImmutableSimpleNode( + QName.create("augment:augment:module", "2014-01-17", "lf111"), null, instanceIdentifier); + lst11.add(lf111); + cont1.add(lst11.toInstance()); + cont.add(cont1.toInstance()); + return cont.toInstance(); } - private InstanceIdentifier createInstanceIdentifier() throws URISyntaxException { + private YangInstanceIdentifier createInstanceIdentifier() throws URISyntaxException { List 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"))); @@ -226,16 +221,16 @@ public class CnSnToXmlAndJsonInstanceIdentifierTest extends YangAndXmlAndDataSch pathArguments.add(new NodeIdentifier(new QName(new URI("augment:augment:module"), "lf112"))); - return new InstanceIdentifier(pathArguments); + return YangInstanceIdentifier.create(pathArguments); } - private InstanceIdentifier createInstanceIdentifierWithLeafList() throws URISyntaxException { + private YangInstanceIdentifier createInstanceIdentifierWithLeafList() throws URISyntaxException { List 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); + return YangInstanceIdentifier.create(pathArguments); } }