Update MRI projects for Aluminium
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / utils / mapping / RestconfMappingNodeUtilTest.java
index c16ebd5396633319fa32b309116d9d78f6e00ed5..9e089035416a1ea76d850d14cecd5a8540fa47ab 100644 (file)
@@ -21,7 +21,6 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -49,10 +48,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -74,11 +73,11 @@ public class RestconfMappingNodeUtilTest {
     @Mock private LeafSchemaNode leafReplayLog;
     @Mock private LeafSchemaNode leafEvents;
 
-    private static Set<Module> modules;
-    private static SchemaContext schemaContext;
-    private static SchemaContext schemaContextMonitoring;
+    private static Collection<? extends Module> modules;
+    private static EffectiveModelContext schemaContext;
+    private static EffectiveModelContext schemaContextMonitoring;
 
-    private static Set<Module> modulesRest;
+    private static Collection<? extends Module> modulesRest;
 
     @BeforeClass
     public static void loadTestSchemaContextAndModules() throws Exception {
@@ -116,6 +115,8 @@ public class RestconfMappingNodeUtilTest {
 
         // verify loaded modules
         verifyLoadedModules((ContainerNode) mods);
+        // verify deviations
+        verifyDeviations((ContainerNode) mods);
     }
 
     @Test
@@ -126,7 +127,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 +205,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 +241,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 +252,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.",
@@ -252,7 +277,7 @@ public class RestconfMappingNodeUtilTest {
      * @param expectedModules Modules from <code>SchemaContext</code>
      * @param loadedModules Loaded modules into Restconf module
      */
-    private static void verifyLoadedModules(final Set<Module> expectedModules,
+    private static void verifyLoadedModules(final Collection<? extends Module> expectedModules,
             final Map<String, String> loadedModules) {
         assertEquals("Number of loaded modules is not as expected", expectedModules.size(), loadedModules.size());
         for (final Module m : expectedModules) {