X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Ftest%2Fcontext%2FContextUtils.java;fp=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Ftest%2Fcontext%2FContextUtils.java;h=ccf34fdcd937064dcec734220fb4c8329ab366c7;hb=5cd89c0d086e1ed5999096ba358f8fc9352d322d;hp=f157ac78c17eacf2bfca95aebbc94c035d9ca7e9;hpb=7717aa5e3983a7f91e071671a2ef0b8a904e5913;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java index f157ac78c..ccf34fdcd 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/context/ContextUtils.java @@ -22,32 +22,27 @@ public class ContextUtils { TestResult testResult, TreeSRelated treeSRelated) { for (String key : contextAware.getExpectedValues().keySet()) { - // Register in structure - if (treeSRelated != null) { - if (treeSRelated.getBasePath() != null) { - TreeSPath path = treeSRelated.getBasePath() - .createChild(key); - StructureRegistry registry = treeSRelated - .getRegistry(); - final StructureElement element = treeSRelated - .getStructureElement(key); - registry.register(path, element); - if (testResult instanceof StructureAware) - ((StructureAware) testResult) - .notifyCurrentPath(registry, path); - - if (log.isDebugEnabled()) - log.debug("Checking key " + key + " for path " + path); - } - } - // 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 + "'"); + continue; + } + + // Register in structure + registerInStructure(testResult, treeSRelated, key); + if (contextAware.getValues().containsKey(key)) { Object reachedValue = contextAware.getValues().get(key); - if (expectedValue.equals(reachedValue)) { + if (expectedValue.equals(contextAware.getContextAnyFlag())) { + 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 + "'")); @@ -62,14 +57,38 @@ public class ContextUtils { TestStatus.FAILED, "No value reached for key '" + key + "'")); } + resetStructure(testResult, treeSRelated); + } + } + + private static void registerInStructure(TestResult testResult, + TreeSRelated treeSRelated, String key) { + if (treeSRelated != null) { + if (treeSRelated.getBasePath() != null) { + TreeSPath path = treeSRelated.getBasePath().createChild(key); + StructureRegistry registry = treeSRelated + .getRegistry(); + final StructureElement element = treeSRelated + .getStructureElement(key); + registry.register(path, element); + if (testResult instanceof StructureAware) + ((StructureAware) testResult).notifyCurrentPath( + registry, path); + + if (log.isDebugEnabled()) + log.debug("Checking key " + key + " for path " + path); + } + } + } - if (treeSRelated != null) { - if (treeSRelated.getBasePath() != null) { - if (testResult instanceof StructureAware) { - ((StructureAware) testResult) - .notifyCurrentPath(treeSRelated.getRegistry(), - treeSRelated.getBasePath()); - } + private static void resetStructure(TestResult testResult, + TreeSRelated treeSRelated) { + if (treeSRelated != null) { + if (treeSRelated.getBasePath() != null) { + if (testResult instanceof StructureAware) { + ((StructureAware) testResult).notifyCurrentPath( + treeSRelated.getRegistry(), treeSRelated + .getBasePath()); } } }