Merge "Fixed Group and meter id bugs"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / FromXmlToCompositeNodeTest.java
index 6249d2a5b0d3a475fa6435714a24fc57d901a554..a72bd60d30eff23139841513505e02b5801d2ac5 100644 (file)
@@ -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);