1 package org
.argeo
.slc
.core
.test
.context
;
3 import org
.apache
.commons
.logging
.Log
;
4 import org
.apache
.commons
.logging
.LogFactory
;
6 import org
.argeo
.slc
.core
.structure
.StructureAware
;
7 import org
.argeo
.slc
.core
.structure
.StructureElement
;
8 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
9 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
10 import org
.argeo
.slc
.core
.structure
.tree
.TreeSRelated
;
11 import org
.argeo
.slc
.core
.test
.SimpleResultPart
;
12 import org
.argeo
.slc
.core
.test
.TestResult
;
13 import org
.argeo
.slc
.core
.test
.TestStatus
;
15 public class ContextHelper
{
16 private final static Log log
= LogFactory
.getLog(ContextHelper
.class);
18 public static void compareReachedExpected(ContextAware contextAware
,
19 TestResult testResult
, TreeSRelated treeSRelated
) {
20 for (String key
: contextAware
.getExpectedValues().keySet()) {
22 // Register in structure
23 if (treeSRelated
!= null) {
24 if (treeSRelated
.getBasePath() != null) {
25 TreeSPath path
= treeSRelated
.getBasePath()
27 StructureRegistry
<TreeSPath
> registry
= treeSRelated
29 final StructureElement element
= treeSRelated
30 .getStructureElement(key
);
31 registry
.register(path
, element
);
32 if (testResult
instanceof StructureAware
)
33 ((StructureAware
<TreeSPath
>) testResult
)
34 .notifyCurrentPath(registry
, path
);
36 if (log
.isDebugEnabled())
37 log
.debug("Checking key " + key
+ " for path " + path
);
41 // Compare expected values with reached ones
42 Object expectedValue
= contextAware
.getExpectedValues().get(key
);
44 if (contextAware
.getValues().containsKey(key
)) {
45 Object reachedValue
= contextAware
.getValues().get(key
);
47 if (expectedValue
.equals(reachedValue
)) {
48 testResult
.addResultPart(new SimpleResultPart(
49 TestStatus
.PASSED
, "Values matched for key '" + key
52 testResult
.addResultPart(new SimpleResultPart(
53 TestStatus
.FAILED
, "Mismatch for key '" + key
54 + "': expected '" + expectedValue
55 + "' but reached '" + reachedValue
+ "'"));
58 testResult
.addResultPart(new SimpleResultPart(
59 TestStatus
.FAILED
, "No value reached for key '" + key
63 if (treeSRelated
!= null) {
64 if (treeSRelated
.getBasePath() != null) {
65 if (testResult
instanceof StructureAware
) {
66 ((StructureAware
<TreeSPath
>) testResult
)
67 .notifyCurrentPath(treeSRelated
.getRegistry(),
68 treeSRelated
.getBasePath());