]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
a012c4451b065a3e26926f710d4712cd5dc04068
1 package org
.argeo
.slc
.core
.test
.tree
;
5 import java
.util
.SortedMap
;
6 import java
.util
.TreeMap
;
7 import java
.util
.Vector
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.slc
.core
.SlcException
;
13 import org
.argeo
.slc
.core
.structure
.StructureAware
;
14 import org
.argeo
.slc
.core
.structure
.StructureElement
;
15 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
16 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
17 import org
.argeo
.slc
.core
.test
.TestResult
;
18 import org
.argeo
.slc
.core
.test
.TestResultListener
;
19 import org
.argeo
.slc
.core
.test
.TestResultPart
;
20 import org
.argeo
.slc
.core
.test
.TestRun
;
21 import org
.argeo
.slc
.core
.test
.TestRunAware
;
24 * Complex implementation of a test result compatible with a tree based
27 public class TreeTestResult
implements TestResult
, StructureAware
<TreeSPath
> {
28 private Log log
= LogFactory
.getLog(TreeTestResult
.class);
30 private List
<TestResultListener
<TreeTestResult
>> listeners
= new Vector
<TestResultListener
<TreeTestResult
>>();
32 private TreeSPath currentPath
;
33 private TestRun currentTestRun
;
35 private Date closeDate
;
37 private boolean isClosed
= false;
41 private SortedMap
<TreeSPath
, PartSubList
> resultParts
= new TreeMap
<TreeSPath
, PartSubList
>();
42 private SortedMap
<TreeSPath
, StructureElement
> elements
= new TreeMap
<TreeSPath
, StructureElement
>();
44 /** Sets the list of listeners. */
45 public void setListeners(List
<TestResultListener
<TreeTestResult
>> listeners
) {
46 this.listeners
= listeners
;
49 public void addResultPart(TestResultPart part
) {
50 if (currentPath
== null) {
51 throw new SlcException("No current path set.");
53 PartSubList subList
= resultParts
.get(currentPath
);
54 if (subList
== null) {
55 subList
= new PartSubList();
56 resultParts
.put(currentPath
, subList
);
58 if (part
instanceof TestRunAware
&& currentTestRun
!= null) {
59 ((TestRunAware
) part
).notifyTestRun(currentTestRun
);
61 subList
.getParts().add(part
);
64 synchronized (listeners
) {
65 for (TestResultListener
<TreeTestResult
> listener
: listeners
) {
66 listener
.resultPartAdded(this, part
);
71 public void notifyCurrentPath(StructureRegistry
<TreeSPath
> registry
,
73 if (registry
!= null) {
74 for (TreeSPath p
: path
.getHierarchyAsList()) {
75 if (!elements
.containsKey(p
)) {
76 StructureElement elem
= registry
.getElement(p
);
78 elements
.put(p
, elem
);
81 if (log
.isTraceEnabled())
82 log
.trace("An element is already registered for path "
83 + p
+ " and was not updated");
89 currentPath
= (TreeSPath
) path
;
92 /** Gets the current path. */
93 public TreeSPath
getCurrentPath() {
97 /** Gets all the results structured as a map of <code>PartSubList<code>s. */
98 public SortedMap
<TreeSPath
, PartSubList
> getResultParts() {
102 /** Used by ORM systems. */
103 void setResultParts(SortedMap
<TreeSPath
, PartSubList
> resultParts
) {
104 this.resultParts
= resultParts
;
107 public void close() {
109 throw new SlcException("Test Result #" + getUuid()
110 + " alredy closed.");
112 closeDate
= new Date();
114 synchronized (listeners
) {
115 for (TestResultListener
<TreeTestResult
> listener
: listeners
) {
116 listener
.close(this);
122 log
.info("Test Result #" + getUuid() + " closed.");
125 public Date
getCloseDate() {
129 /** Sets the close date (for ORM) */
130 public void setCloseDate(Date closeDate
) {
131 this.closeDate
= closeDate
;
134 public void notifyTestRun(TestRun testRun
) {
135 currentTestRun
= testRun
;
138 public SortedMap
<TreeSPath
, StructureElement
> getElements() {
142 public void setElements(SortedMap
<TreeSPath
, StructureElement
> pathNames
) {
143 this.elements
= pathNames
;
146 public String
getUuid() {
150 public void setUuid(String uuid
) {
154 public SortedMap
<TreeSPath
, StructureElement
> getRelatedElements(
156 SortedMap
<TreeSPath
, StructureElement
> relatedElements
= new TreeMap
<TreeSPath
, StructureElement
>();
157 List
<TreeSPath
> hierarchy
= path
.getHierarchyAsList();
158 for (TreeSPath currPath
: elements
.keySet()) {
159 if (hierarchy
.contains(currPath
)) {
160 relatedElements
.put(currPath
, elements
.get(currPath
));
163 return relatedElements
;
166 public TestRun
getCurrentTestRun() {
167 return currentTestRun
;