]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.runtime/src/org/argeo/slc/runtime/test/ContextUtils.java
Merge tag 'v2.3.15' into testing
[gpl/argeo-slc.git] / org.argeo.slc.runtime / src / org / argeo / slc / runtime / test / ContextUtils.java
index 97d7305c1e3ad774e16c707e29c7867cb0852730..f3c52fad4787335ef23aaf9718f10fc02ead2a04 100644 (file)
@@ -3,28 +3,22 @@ package org.argeo.slc.runtime.test;
 import java.util.Map;
 import java.util.TreeMap;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.test.TestResult;
-import org.argeo.slc.test.TestStatus;
-import org.argeo.slc.test.context.ContextAware;
-import org.argeo.slc.test.context.ParentContextAware;
+import org.argeo.api.slc.test.TestResult;
+import org.argeo.api.slc.test.TestStatus;
+import org.argeo.api.slc.test.context.ContextAware;
+import org.argeo.api.slc.test.context.ParentContextAware;
 
 /** Utilities for comparing and synchronising contexts. */
 public class ContextUtils {
-       private final static Log log = LogFactory.getLog(ContextUtils.class);
-
-       public static void compareReachedExpected(ContextAware contextAware,
-                       TestResult testResult) {
+       public static void compareReachedExpected(ContextAware contextAware, TestResult testResult) {
                for (String key : contextAware.getExpectedValues().keySet()) {
 
                        // Compare expected values with reached ones
                        Object expectedValue = contextAware.getExpectedValues().get(key);
 
-                       if (expectedValue.toString().equals(
-                                       contextAware.getContextSkipFlag())) {
-                               if (log.isDebugEnabled())
-                                       log.debug("Skipped check for key '" + key + "'");
+                       if (expectedValue.toString().equals(contextAware.getContextSkipFlag())) {
+//                             if (log.isDebugEnabled())
+//                                     log.debug("Skipped check for key '" + key + "'");
                                continue;
                        }
 
@@ -32,42 +26,35 @@ public class ContextUtils {
                                Object reachedValue = contextAware.getValues().get(key);
 
                                if (expectedValue.equals(contextAware.getContextAnyFlag())) {
-                                       testResult.addResultPart(new SimpleResultPart(
-                                                       TestStatus.PASSED, "Expected any value for key '"
-                                                                       + key + "'"));
+                                       testResult.addResultPart(
+                                                       new SimpleResultPart(TestStatus.PASSED, "Expected any value for key '" + key + "'"));
                                } else if (expectedValue.equals(reachedValue)) {
-                                       testResult.addResultPart(new SimpleResultPart(
-                                                       TestStatus.PASSED, "Values matched for key '" + key
-                                                                       + "'"));
+                                       testResult.addResultPart(
+                                                       new SimpleResultPart(TestStatus.PASSED, "Values matched for key '" + key + "'"));
                                } else {
-                                       testResult.addResultPart(new SimpleResultPart(
-                                                       TestStatus.FAILED, "Mismatch for key '" + key
-                                                                       + "': expected '" + expectedValue
-                                                                       + "' but reached '" + reachedValue + "'"));
+                                       testResult.addResultPart(new SimpleResultPart(TestStatus.FAILED, "Mismatch for key '" + key
+                                                       + "': expected '" + expectedValue + "' but reached '" + reachedValue + "'"));
                                }
                        } else {
-                               testResult.addResultPart(new SimpleResultPart(
-                                               TestStatus.FAILED, "No value reached for key '" + key
-                                                               + "'"));
+                               testResult.addResultPart(
+                                               new SimpleResultPart(TestStatus.FAILED, "No value reached for key '" + key + "'"));
                        }
                }
        }
 
        /**
-        * Makes sure that all children and sub-children of parent share the same
-        * maps for values and expected values.
+        * Makes sure that all children and sub-children of parent share the same maps
+        * for values and expected values.
         */
        public static void synchronize(ParentContextAware parent) {
-               Map<String, Object> expectedValuesCommon = new TreeMap<String, Object>(
-                               parent.getExpectedValues());
+               Map<String, Object> expectedValuesCommon = new TreeMap<String, Object>(parent.getExpectedValues());
                synchronize(parent, expectedValuesCommon);
-               if (log.isDebugEnabled())
-                       log.debug("Synchronized context " + parent);
+//             if (log.isDebugEnabled())
+//                     log.debug("Synchronized context " + parent);
 
        }
 
-       private static void synchronize(ParentContextAware parent,
-                       Map<String, Object> expectedValuesCommon) {
+       private static void synchronize(ParentContextAware parent, Map<String, Object> expectedValuesCommon) {
                for (ContextAware child : parent.getChildContexts()) {
                        // Values
                        putNotContained(parent.getValues(), child.getValues());
@@ -80,26 +67,22 @@ public class ContextUtils {
 
                        // Creates a new Map in order not to disturb other context using the
                        // same keys
-                       Map<String, Object> expectedValuesCommonChild = new TreeMap<String, Object>(
-                                       expectedValuesCommon);
-                       putNotContained(expectedValuesCommonChild,
-                                       child.getExpectedValues());
+                       Map<String, Object> expectedValuesCommonChild = new TreeMap<String, Object>(expectedValuesCommon);
+                       putNotContained(expectedValuesCommonChild, child.getExpectedValues());
 
                        if (child instanceof ParentContextAware) {
                                // Recursive sync
-                               synchronize((ParentContextAware) child,
-                                               expectedValuesCommonChild);
+                               synchronize((ParentContextAware) child, expectedValuesCommonChild);
                        }
                }
 
        }
 
        /**
-        * Put into common map the values from child map which are not already
-        * defined in common map.
+        * Put into common map the values from child map which are not already defined
+        * in common map.
         */
-       public static void putNotContained(Map<String, Object> commonMap,
-                       Map<String, Object> childMap) {
+       public static void putNotContained(Map<String, Object> commonMap, Map<String, Object> childMap) {
                for (String key : childMap.keySet()) {
                        if (!commonMap.containsKey(key)) {
                                commonMap.put(key, childMap.get(key));
@@ -108,8 +91,7 @@ public class ContextUtils {
        }
 
        /** Overrides child map values with the values already set in common map */
-       public static void overrideContained(Map<String, Object> commonMap,
-                       Map<String, Object> childMap) {
+       public static void overrideContained(Map<String, Object> commonMap, Map<String, Object> childMap) {
                for (String key : childMap.keySet()) {
                        if (commonMap.containsKey(key)) {
                                childMap.put(key, commonMap.get(key));