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%2FFromXmlToCompositeNodeTest.java;h=a72bd60d30eff23139841513505e02b5801d2ac5;hb=e640f23d9c37afac9ca51f48e155302bc65327ed;hp=6249d2a5b0d3a475fa6435714a24fc57d901a554;hpb=c57785bd755dfdeaf829ce80a4b8b383d8c04602;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/FromXmlToCompositeNodeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/FromXmlToCompositeNodeTest.java index 6249d2a5b0..a72bd60d30 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/FromXmlToCompositeNodeTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/FromXmlToCompositeNodeTest.java @@ -11,7 +11,7 @@ import javax.ws.rs.WebApplicationException; import org.junit.*; import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider; -import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; +import org.opendaylight.controller.sal.restconf.impl.*; import org.opendaylight.yangtools.yang.data.api.*; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.slf4j.*; @@ -41,9 +41,36 @@ public class FromXmlToCompositeNodeTest { String nameSpace = "data:container:yang"; assertEquals(nameSpace, compNode.getNodeType().getNamespace().toString()); + verifyNullAndEmptyStringSingleNode(compNode, nameSpace); verifyCommonPartAOfXml(compNode, "", nameSpace); } + private void verifyNullAndEmptyStringSingleNode(CompositeNode compNode, String nameSpace) { + assertEquals("cont", compNode.getNodeType().getLocalName()); + + SimpleNode lf2 = null; + SimpleNode lf3 = null; + int found = 0; + for (Node child : compNode.getChildren()) { + if (found == 0x3) + break; + if (child instanceof SimpleNode) { + SimpleNode childSimple = (SimpleNode) child; + if (childSimple.getNodeType().getLocalName().equals("lf3")) { + lf3 = childSimple; + found = found | (1 << 0); + } else if (childSimple.getNodeType().getLocalName().equals("lf2")) { + lf2 = childSimple; + found = found | (1 << 1); + } + } + assertEquals(nameSpace, child.getNodeType().getNamespace().toString()); + } + + assertEquals("", lf2.getValue()); + assertEquals(null, lf3.getValue()); + } + @Test public void testXmlDataList() { CompositeNode compNode = compositeContainerFromXml("/xml-to-composite-node/data-list.xml", false); @@ -111,7 +138,7 @@ public class FromXmlToCompositeNodeTest { SimpleNode cont11_lf111 = (SimpleNode) cont11.getChildren().get(0); assertEquals(nameSpaceCont, cont11_lf111.getNodeType().getNamespace().toString()); assertEquals("lf111", cont11_lf111.getNodeType().getLocalName()); - assertEquals("100", cont11_lf111.getValue()); + assertEquals((short) 100, cont11_lf111.getValue()); // :lst1_2 } @@ -224,7 +251,7 @@ public class FromXmlToCompositeNodeTest { SimpleNode cont1_lf11 = (SimpleNode) cont1suf.getChildren().get(0); assertEquals(nameSpace, cont1_lf11.getNodeType().getNamespace().toString()); assertEquals("lf11" + suf, cont1_lf11.getNodeType().getLocalName()); - assertEquals("100", cont1_lf11.getValue()); + assertEquals((short) 100, cont1_lf11.getValue()); } private CompositeNode compositeContainerFromXml(String xmlPath, boolean dummyNamespaces) { @@ -235,7 +262,7 @@ public class FromXmlToCompositeNodeTest { if (dummyNamespaces) { try { TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) compositeNode); - return ((CompositeNodeWrapper) compositeNode).unwrap(null); + return ((CompositeNodeWrapper) compositeNode).unwrap(); } catch (URISyntaxException e) { LOG.error(e.getMessage()); assertTrue(e.getMessage(), false);