Fix for deviation list mapping in Restconf
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / utils / mapping / RestconfMappingNodeUtilTest.java
index c16ebd5396633319fa32b309116d9d78f6e00ed5..c08e40814c7a7ed5b49e332f3f5760e08da16fba 100644 (file)
@@ -116,6 +116,8 @@ public class RestconfMappingNodeUtilTest {
 
         // verify loaded modules
         verifyLoadedModules((ContainerNode) mods);
+        // verify deviations
+        verifyDeviations((ContainerNode) mods);
     }
 
     @Test
@@ -126,7 +128,7 @@ public class RestconfMappingNodeUtilTest {
         assertNotNull(normNode);
         final List<Object> listOfValues = new ArrayList<>();
 
-        for (final DataContainerChild<? extends PathArgument, ?> child : ((ContainerNode) normNode).getValue()) {
+        for (final DataContainerChild<? extends PathArgument, ?> child : normNode.getValue()) {
             if (child.getNodeType().equals(MonitoringModule.CONT_CAPABILITES_QNAME)) {
                 for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : ((ContainerNode) child)
                         .getValue()) {
@@ -204,6 +206,30 @@ public class RestconfMappingNodeUtilTest {
         }
     }
 
+    /**
+     * Verify whether the loaded modules contain any deviations.
+     *
+     * @param containerNode
+     *             modules
+     */
+    private static void verifyDeviations(final ContainerNode containerNode) {
+        int deviationsFound = 0;
+        for (final DataContainerChild child : containerNode.getValue()) {
+            if (child instanceof MapNode) {
+                for (final MapEntryNode mapEntryNode : ((MapNode) child).getValue()) {
+                    for (final DataContainerChild dataContainerChild : mapEntryNode
+                            .getValue()) {
+                        if (dataContainerChild.getNodeType()
+                                .equals(IetfYangLibrary.SPECIFIC_MODULE_DEVIATION_LIST_QNAME)) {
+                            deviationsFound++;
+                        }
+                    }
+                }
+            }
+        }
+        Assert.assertTrue(deviationsFound > 0);
+    }
+
     /**
      * Verify loaded modules.
      *
@@ -216,10 +242,10 @@ public class RestconfMappingNodeUtilTest {
 
         for (final DataContainerChild<? extends PathArgument, ?> child : containerNode.getValue()) {
             if (child instanceof LeafNode) {
-                assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, ((LeafNode<?>) child).getNodeType());
+                assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, child.getNodeType());
             }
             if (child instanceof MapNode) {
-                assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, ((MapNode) child).getNodeType());
+                assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, child.getNodeType());
                 for (final MapEntryNode mapEntryNode : ((MapNode) child).getValue()) {
                     String name = "";
                     String revision = "";
@@ -227,10 +253,10 @@ public class RestconfMappingNodeUtilTest {
                             .getValue()) {
                         switch (dataContainerChild.getNodeType().getLocalName()) {
                             case IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF:
-                                name = String.valueOf(((LeafNode<?>) dataContainerChild).getValue());
+                                name = String.valueOf(dataContainerChild.getValue());
                                 break;
                             case IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF:
-                                revision = String.valueOf(((LeafNode<?>) dataContainerChild).getValue());
+                                revision = String.valueOf(dataContainerChild.getValue());
                                 break;
                             default :
                                 LOG.info("Unknown local name '{}' of node.",