]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java
Introduce Context Unit Tests.
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / context / ContextUtils.java
index f157ac78c17eacf2bfca95aebbc94c035d9ca7e9..ccf34fdcd937064dcec734220fb4c8329ab366c7 100644 (file)
@@ -22,32 +22,27 @@ public class ContextUtils {
                        TestResult testResult, TreeSRelated treeSRelated) {\r
                for (String key : contextAware.getExpectedValues().keySet()) {\r
 \r
-                       // Register in structure\r
-                       if (treeSRelated != null) {\r
-                               if (treeSRelated.getBasePath() != null) {\r
-                                       TreeSPath path = treeSRelated.getBasePath()\r
-                                                       .createChild(key);\r
-                                       StructureRegistry<TreeSPath> registry = treeSRelated\r
-                                                       .getRegistry();\r
-                                       final StructureElement element = treeSRelated\r
-                                                       .getStructureElement(key);\r
-                                       registry.register(path, element);\r
-                                       if (testResult instanceof StructureAware)\r
-                                               ((StructureAware<TreeSPath>) testResult)\r
-                                                               .notifyCurrentPath(registry, path);\r
-\r
-                                       if (log.isDebugEnabled())\r
-                                               log.debug("Checking key " + key + " for path " + path);\r
-                               }\r
-                       }\r
-\r
                        // Compare expected values with reached ones\r
                        Object expectedValue = contextAware.getExpectedValues().get(key);\r
 \r
+                       if (expectedValue.toString().equals(\r
+                                       contextAware.getContextSkipFlag())) {\r
+                               if (log.isDebugEnabled())\r
+                                       log.debug("Skipped check for key '" + key + "'");\r
+                               continue;\r
+                       }\r
+\r
+                       // Register in structure\r
+                       registerInStructure(testResult, treeSRelated, key);\r
+\r
                        if (contextAware.getValues().containsKey(key)) {\r
                                Object reachedValue = contextAware.getValues().get(key);\r
 \r
-                               if (expectedValue.equals(reachedValue)) {\r
+                               if (expectedValue.equals(contextAware.getContextAnyFlag())) {\r
+                                       testResult.addResultPart(new SimpleResultPart(\r
+                                                       TestStatus.PASSED, "Expected any value for key '"\r
+                                                                       + key + "'"));\r
+                               } else if (expectedValue.equals(reachedValue)) {\r
                                        testResult.addResultPart(new SimpleResultPart(\r
                                                        TestStatus.PASSED, "Values matched for key '" + key\r
                                                                        + "'"));\r
@@ -62,14 +57,38 @@ public class ContextUtils {
                                                TestStatus.FAILED, "No value reached for key '" + key\r
                                                                + "'"));\r
                        }\r
+                       resetStructure(testResult, treeSRelated);\r
+               }\r
+       }\r
+\r
+       private static void registerInStructure(TestResult testResult,\r
+                       TreeSRelated treeSRelated, String key) {\r
+               if (treeSRelated != null) {\r
+                       if (treeSRelated.getBasePath() != null) {\r
+                               TreeSPath path = treeSRelated.getBasePath().createChild(key);\r
+                               StructureRegistry<TreeSPath> registry = treeSRelated\r
+                                               .getRegistry();\r
+                               final StructureElement element = treeSRelated\r
+                                               .getStructureElement(key);\r
+                               registry.register(path, element);\r
+                               if (testResult instanceof StructureAware)\r
+                                       ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(\r
+                                                       registry, path);\r
+\r
+                               if (log.isDebugEnabled())\r
+                                       log.debug("Checking key " + key + " for path " + path);\r
+                       }\r
+               }\r
+       }\r
 \r
-                       if (treeSRelated != null) {\r
-                               if (treeSRelated.getBasePath() != null) {\r
-                                       if (testResult instanceof StructureAware) {\r
-                                               ((StructureAware<TreeSPath>) testResult)\r
-                                                               .notifyCurrentPath(treeSRelated.getRegistry(),\r
-                                                                               treeSRelated.getBasePath());\r
-                                       }\r
+       private static void resetStructure(TestResult testResult,\r
+                       TreeSRelated treeSRelated) {\r
+               if (treeSRelated != null) {\r
+                       if (treeSRelated.getBasePath() != null) {\r
+                               if (testResult instanceof StructureAware) {\r
+                                       ((StructureAware<TreeSPath>) testResult).notifyCurrentPath(\r
+                                                       treeSRelated.getRegistry(), treeSRelated\r
+                                                                       .getBasePath());\r
                                }\r
                        }\r
                }\r