Merge "BUG-1281: use SchemaContext lookups"
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / xml / to / cnsn / test / XmlLeafrefToCnSnTest.java
index e5b0bf507d03212bf2efedaaa18cc2f28f734567..1c62b7fbdb8e9013a38cd124d1df4e1c481bf3e5 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 import java.util.Set;
-
 import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
@@ -30,13 +29,15 @@ public class XmlLeafrefToCnSnTest {
     private static final Logger LOG = LoggerFactory.getLogger(XmlLeafrefToCnSnTest.class);
 
     /**
-     * top level element represents container. second level element is list with
-     * two elements.
+     * top level element represents container. second level element is list with two elements.
      */
     @Test
     public void testXmlDataContainer() {
-        CompositeNode compNode = TestUtils.readInputToCnSn("/xml-to-cnsn/data-container.xml", false,
+        Node<?> node = TestUtils.readInputToCnSn("/xml-to-cnsn/data-container.xml", false,
                 XmlToCompositeNodeProvider.INSTANCE);
+        assertTrue(node instanceof CompositeNode);
+        CompositeNode compNode = (CompositeNode)node;
+
         assertNotNull(compNode);
         Set<Module> modules = TestUtils.loadModulesFrom("/xml-to-cnsn/data-container-yang");
 
@@ -78,9 +79,11 @@ public class XmlLeafrefToCnSnTest {
 
     @Test
     public void testXmlDataList() {
-        CompositeNode compNode = TestUtils.readInputToCnSn("/xml-to-cnsn/data-list.xml", false,
+        Node<?> node = TestUtils.readInputToCnSn("/xml-to-cnsn/data-list.xml", false,
                 XmlToCompositeNodeProvider.INSTANCE);
-        assertNotNull(compNode);
+        assertTrue(node instanceof CompositeNode);
+        CompositeNode compNode = (CompositeNode)node;
+
 
         Set<Module> modules = TestUtils.loadModulesFrom("/xml-to-cnsn/data-list-yang");
         assertNotNull(modules);
@@ -95,22 +98,22 @@ public class XmlLeafrefToCnSnTest {
         CompositeNode lst1_1 = null;
         CompositeNode lst1_2 = null;
         int loopCount = 0;
-        for (Node<?> node : compNode.getValue()) {
-            if (node.getNodeType().getLocalName().equals("lf1")) {
-                assertEquals(nameSpaceList, node.getNodeType().getNamespace().toString());
-                assertTrue(node instanceof SimpleNode<?>);
-                assertEquals("lf1", node.getValue());
+        for (Node<?> nd : compNode.getValue()) {
+            if (nd.getNodeType().getLocalName().equals("lf1")) {
+                assertEquals(nameSpaceList, nd.getNodeType().getNamespace().toString());
+                assertTrue(nd instanceof SimpleNode<?>);
+                assertEquals("lf1", nd.getValue());
             } else {
-                assertTrue(node instanceof CompositeNode);
+                assertTrue(nd instanceof CompositeNode);
                 switch (loopCount++) {
                 case 0:
-                    lst1_1 = (CompositeNode) node;
+                    lst1_1 = (CompositeNode) nd;
                     break;
                 case 1:
-                    lst1_2 = (CompositeNode) node;
+                    lst1_2 = (CompositeNode) nd;
                     break;
                 }
-                assertEquals(nameSpaceCont, node.getNodeType().getNamespace().toString());
+                assertEquals(nameSpaceCont, nd.getNodeType().getNamespace().toString());
             }
         }
         // lst1_1
@@ -120,15 +123,15 @@ public class XmlLeafrefToCnSnTest {
         // lst1_2
         SimpleNode<?> lflst11 = null;
         CompositeNode cont11 = null;
-        for (Node<?> node : lst1_2.getValue()) {
-            String nodeName = node.getNodeType().getLocalName();
+        for (Node<?> nd : lst1_2.getValue()) {
+            String nodeName = nd.getNodeType().getLocalName();
             if (nodeName.equals("lflst11")) {
-                assertTrue(node instanceof SimpleNode<?>);
-                lflst11 = (SimpleNode<?>) node;
+                assertTrue(nd instanceof SimpleNode<?>);
+                lflst11 = (SimpleNode<?>) nd;
 
             } else if (nodeName.equals("cont11")) {
-                assertTrue(node instanceof CompositeNode);
-                cont11 = (CompositeNode) node;
+                assertTrue(nd instanceof CompositeNode);
+                cont11 = (CompositeNode) nd;
             }
             assertEquals(nameSpaceCont, compNode.getNodeType().getNamespace().toString());
         }
@@ -146,32 +149,35 @@ public class XmlLeafrefToCnSnTest {
 
     @Test
     public void testXmlEmptyData() {
-        CompositeNode compNode = TestUtils.readInputToCnSn("/xml-to-cnsn/empty-data.xml", true,
+        Node<?> node = TestUtils.readInputToCnSn("/xml-to-cnsn/empty-data.xml", true,
                 XmlToCompositeNodeProvider.INSTANCE);
+        assertTrue(node instanceof CompositeNode);
+        CompositeNode compNode = (CompositeNode)node;
+
         assertEquals("cont", compNode.getNodeType().getLocalName());
         SimpleNode<?> lf1 = null;
         SimpleNode<?> lflst1_1 = null;
         SimpleNode<?> lflst1_2 = null;
         CompositeNode lst1 = null;
         int lflst1Count = 0;
-        for (Node<?> node : compNode.getValue()) {
-            if (node.getNodeType().getLocalName().equals("lf1")) {
-                assertTrue(node instanceof SimpleNode<?>);
-                lf1 = (SimpleNode<?>) node;
-            } else if (node.getNodeType().getLocalName().equals("lflst1")) {
-                assertTrue(node instanceof SimpleNode<?>);
+        for (Node<?> nd : compNode.getValue()) {
+            if (nd.getNodeType().getLocalName().equals("lf1")) {
+                assertTrue(nd instanceof SimpleNode<?>);
+                lf1 = (SimpleNode<?>) nd;
+            } else if (nd.getNodeType().getLocalName().equals("lflst1")) {
+                assertTrue(nd instanceof SimpleNode<?>);
 
                 switch (lflst1Count++) {
                 case 0:
-                    lflst1_1 = (SimpleNode<?>) node;
+                    lflst1_1 = (SimpleNode<?>) nd;
                     break;
                 case 1:
-                    lflst1_2 = (SimpleNode<?>) node;
+                    lflst1_2 = (SimpleNode<?>) nd;
                     break;
                 }
-            } else if (node.getNodeType().getLocalName().equals("lst1")) {
-                assertTrue(node instanceof CompositeNode);
-                lst1 = (CompositeNode) node;
+            } else if (nd.getNodeType().getLocalName().equals("lst1")) {
+                assertTrue(nd instanceof CompositeNode);
+                lst1 = (CompositeNode) nd;
             }
         }
 
@@ -202,8 +208,7 @@ public class XmlLeafrefToCnSnTest {
 
     /**
      *
-     * Test case like <lf11 xmlns="namespace1"
-     * xmlns:x="namespace">identity</lf11>
+     * Test case like <lf11 xmlns="namespace1" xmlns:x="namespace">identity</lf11>
      */
 
     @Test
@@ -214,8 +219,7 @@ public class XmlLeafrefToCnSnTest {
 
     /**
      *
-     * Test case like <cont1 xmlns="namespace1"> <lf11
-     * xmlns:x="namespace">identity</lf11> </cont1>
+     * Test case like <cont1 xmlns="namespace1"> <lf11 xmlns:x="namespace">identity</lf11> </cont1>
      */
     @Test
     public void testIdentityrefDefaultNmspcInParrentElement() {
@@ -225,8 +229,7 @@ public class XmlLeafrefToCnSnTest {
 
     /**
      *
-     * Test case like <cont1 xmlns="namespace1" xmlns:x="namespace">
-     * <lf11>x:identity</lf11> </cont1>
+     * Test case like <cont1 xmlns="namespace1" xmlns:x="namespace"> <lf11>x:identity</lf11> </cont1>
      */
     @Ignore
     @Test
@@ -237,8 +240,7 @@ public class XmlLeafrefToCnSnTest {
 
     /**
      *
-     * Test case like (without namespace in xml) <cont1> <lf11>x:identity</lf11>
-     * </cont1>
+     * Test case like (without namespace in xml) <cont1> <lf11>x:identity</lf11> </cont1>
      */
     @Test
     public void testIdentityrefNoNmspcValueWithPrefix() {
@@ -248,8 +250,7 @@ public class XmlLeafrefToCnSnTest {
 
     /**
      *
-     * Test case like (without namespace in xml) <cont1> <lf11>identity</lf11>
-     * </cont1>
+     * Test case like (without namespace in xml) <cont1> <lf11>identity</lf11> </cont1>
      */
     @Test
     public void testIdentityrefNoNmspcValueWithoutPrefix() {
@@ -322,10 +323,12 @@ public class XmlLeafrefToCnSnTest {
         assertEquals((short) 100, cont1_lf11.getValue());
     }
 
-    private void testIdentityrefToCnSn(final String xmlPath, final String yangPath, final String moduleName, final String schemaName,
-            final int moduleCount, final String resultLocalName, final String resultNamespace) {
-        CompositeNode compositeNode = TestUtils.readInputToCnSn(xmlPath, false, XmlToCompositeNodeProvider.INSTANCE);
-        assertNotNull(compositeNode);
+    private void testIdentityrefToCnSn(final String xmlPath, final String yangPath, final String moduleName,
+            final String schemaName, final int moduleCount, final String resultLocalName, final String resultNamespace) {
+        Node<?> node = TestUtils.readInputToCnSn(xmlPath, false, XmlToCompositeNodeProvider.INSTANCE);
+        assertTrue(node instanceof CompositeNode);
+        CompositeNode compositeNode = (CompositeNode)node;
+
 
         Set<Module> modules = TestUtils.loadModulesFrom(yangPath);
         assertEquals(moduleCount, modules.size());