X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FXmlAndJsonToCnSnInstanceIdentifierTest.java;h=6bd5178f1343a6b328ea641613abda7424896dc7;hb=d7d67c58c7aacbb320f6d3d43918f80ccc2808d1;hp=5476d71320e9ae7a3a0fce6a9ec87f8dfe80088f;hpb=24fa75eae25771889b94c316f55282c39795d166;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java index 5476d71320..6bd5178f13 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java @@ -8,27 +8,26 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - import java.io.IOException; import java.net.URISyntaxException; -import java.util.List; +import java.util.Iterator; import java.util.Map; - import javax.ws.rs.WebApplicationException; - import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; 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.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.Node; import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +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; public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader { @@ -39,82 +38,93 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch @Test public void loadXmlToCnSn() throws WebApplicationException, IOException, URISyntaxException { - CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata.xml", + Node node = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata.xml", XmlToCompositeNodeProvider.INSTANCE); + + assertTrue(node instanceof CompositeNode); + CompositeNode cnSn = (CompositeNode)node; TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath); verifyListPredicate(cnSn); } @Test public void loadXmlLeafListToCnSn() throws WebApplicationException, IOException, URISyntaxException { - CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata_leaf_list.xml", + Node node = TestUtils.readInputToCnSn("/instanceidentifier/xml/xmldata_leaf_list.xml", XmlToCompositeNodeProvider.INSTANCE); + + assertTrue(node instanceof CompositeNode); + CompositeNode cnSn = (CompositeNode)node; TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath); verifyLeafListPredicate(cnSn); } @Test public void loadJsonToCnSn() throws WebApplicationException, IOException, URISyntaxException { - CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata.json", + Node node = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata.json", JsonToCompositeNodeProvider.INSTANCE); + + assertTrue(node instanceof CompositeNode); + CompositeNode cnSn = (CompositeNode)node; TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath); verifyListPredicate(cnSn); } @Test public void loadJsonLeafListToCnSn() throws WebApplicationException, IOException, URISyntaxException { - CompositeNode cnSn = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata_leaf_list.json", + Node node = TestUtils.readInputToCnSn("/instanceidentifier/json/jsondata_leaf_list.json", JsonToCompositeNodeProvider.INSTANCE); + assertTrue(node instanceof CompositeNode); + CompositeNode cnSn = (CompositeNode)node; + TestUtils.normalizeCompositeNode(cnSn, modules, schemaNodePath); verifyLeafListPredicate(cnSn); } - private void verifyLeafListPredicate(CompositeNode cnSn) throws URISyntaxException { + private void verifyLeafListPredicate(final CompositeNode cnSn) throws URISyntaxException { SimpleNode lf11 = getSnWithInstanceIdentifierWhenLeafList(cnSn); Object value = lf11.getValue(); - assertTrue(value instanceof InstanceIdentifier); + assertTrue(value instanceof YangInstanceIdentifier); - InstanceIdentifier instanceIdentifier = (InstanceIdentifier) value; - List pathArguments = instanceIdentifier.getPath(); - assertEquals(3, pathArguments.size()); + YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value; + Iterator it = instanceIdentifier.getPathArguments().iterator(); 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()); + assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType()); + assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType()); + + PathArgument arg = it.next(); + assertFalse(it.hasNext()); + assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), arg.getNodeType()); + + assertTrue(arg instanceof NodeWithValue); + assertEquals("lflst11_1", ((NodeWithValue) arg).getValue()); } - private void verifyListPredicate(CompositeNode cnSn) throws URISyntaxException { + private void verifyListPredicate(final CompositeNode cnSn) throws URISyntaxException { SimpleNode lf111 = getSnWithInstanceIdentifierWhenList(cnSn); Object value = lf111.getValue(); - assertTrue(value instanceof InstanceIdentifier); + assertTrue(value instanceof YangInstanceIdentifier); - InstanceIdentifier instanceIdentifier = (InstanceIdentifier) value; - List pathArguments = instanceIdentifier.getPath(); - assertEquals(4, pathArguments.size()); + YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value; + Iterator it = instanceIdentifier.getPathArguments().iterator(); 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("lst11", "augment:module", revisionDate), pathArguments.get(2).getNodeType()); - assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), pathArguments.get(3) - .getNodeType()); - - assertTrue(pathArguments.get(2) instanceof NodeIdentifierWithPredicates); - Map predicates = ((NodeIdentifierWithPredicates) pathArguments.get(2)).getKeyValues(); + assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType()); + assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType()); + + PathArgument arg = it.next(); + assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), arg.getNodeType()); + assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), it.next().getNodeType()); + assertFalse(it.hasNext()); + + assertTrue(arg instanceof NodeIdentifierWithPredicates); + Map predicates = ((NodeIdentifierWithPredicates) arg).getKeyValues(); assertEquals(2, predicates.size()); assertEquals("value1", predicates.get(TestUtils.buildQName("keyvalue111", "augment:module", revisionDate))); assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate))); } - private SimpleNode getSnWithInstanceIdentifierWhenList(CompositeNode cnSn) throws URISyntaxException { + private SimpleNode getSnWithInstanceIdentifierWhenList(final CompositeNode cnSn) throws URISyntaxException { CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module", "2014-01-17")); assertNotNull(cont1); @@ -127,7 +137,7 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch return lf111; } - private SimpleNode getSnWithInstanceIdentifierWhenLeafList(CompositeNode cnSn) throws URISyntaxException { + private SimpleNode getSnWithInstanceIdentifierWhenLeafList(final CompositeNode cnSn) throws URISyntaxException { CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module", "2014-01-17")); assertNotNull(cont1);