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
.process
.SlcExecution
;
14 import org
.argeo
.slc
.core
.process
.SlcExecutionAware
;
15 import org
.argeo
.slc
.core
.process
.SlcExecutionStep
;
16 import org
.argeo
.slc
.core
.structure
.StructureAware
;
17 import org
.argeo
.slc
.core
.structure
.StructureElement
;
18 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
19 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
20 import org
.argeo
.slc
.core
.test
.TestResult
;
21 import org
.argeo
.slc
.core
.test
.TestResultListener
;
22 import org
.argeo
.slc
.core
.test
.TestResultPart
;
25 * Complex implementation of a test result compatible with a tree based
28 public class TreeTestResult
implements TestResult
, StructureAware
<TreeSPath
>,
30 private Log log
= LogFactory
.getLog(TreeTestResult
.class);
32 private List
<TestResultListener
> listeners
= new Vector
<TestResultListener
>();
34 private TreeSPath currentPath
;
35 private String currentSlcExecutionUuid
;
36 private String currentSlcExecutionStepUuid
;
38 private Date closeDate
;
40 private boolean isClosed
= false;
44 private SortedMap
<TreeSPath
, PartSubList
> resultParts
= new TreeMap
<TreeSPath
, PartSubList
>();
45 private SortedMap
<TreeSPath
, StructureElement
> elements
= new TreeMap
<TreeSPath
, StructureElement
>();
47 /** Sets the list of listeners. */
48 public void setListeners(List
<TestResultListener
> listeners
) {
49 this.listeners
= listeners
;
52 public void addResultPart(TestResultPart part
) {
53 if (currentPath
== null) {
54 throw new SlcException("No current path set.");
56 PartSubList subList
= resultParts
.get(currentPath
);
57 if (subList
== null) {
58 subList
= new PartSubList();
59 subList
.setSlcExecutionUuid(currentSlcExecutionUuid
);
60 subList
.setSlcExecutionStepUuid(currentSlcExecutionStepUuid
);
61 resultParts
.put(currentPath
, subList
);
63 subList
.getParts().add(part
);
66 synchronized (listeners
) {
67 for (TestResultListener listener
: listeners
) {
68 listener
.resultPartAdded(this, part
);
73 public void notifyCurrentPath(StructureRegistry
<TreeSPath
> registry
,
75 if (registry
!= null) {
76 for (TreeSPath p
: path
.getHierarchyAsList()) {
77 if (!elements
.containsKey(p
)) {
78 StructureElement elem
= registry
.getElement(p
);
80 elements
.put(p
, elem
);
83 if (log
.isTraceEnabled())
84 log
.trace("An element is already registered for path "
85 + p
+ " and was not updated");
91 currentPath
= (TreeSPath
) path
;
94 /** Gets the current path. */
95 public TreeSPath
getCurrentPath() {
99 /** Gets all the results structured as a map of <code>PartSubList<code>s. */
100 public SortedMap
<TreeSPath
, PartSubList
> getResultParts() {
104 /** Used by ORM systems. */
105 void setResultParts(SortedMap
<TreeSPath
, PartSubList
> resultParts
) {
106 this.resultParts
= resultParts
;
109 public void close() {
111 throw new SlcException("Test Result #" + getUuid()
112 + " alredy closed.");
114 closeDate
= new Date();
116 synchronized (listeners
) {
117 for (TestResultListener listener
: listeners
) {
118 listener
.close(this);
124 log
.info("Test Result #" + getUuid() + " closed.");
127 public Date
getCloseDate() {
131 /** Sets the close date (for ORM) */
132 public void setCloseDate(Date closeDate
) {
133 this.closeDate
= closeDate
;
136 public void notifySlcExecution(SlcExecution slcExecution
) {
137 currentSlcExecutionUuid
= slcExecution
.getUuid();
138 SlcExecutionStep step
= slcExecution
.currentStep();
140 currentSlcExecutionStepUuid
= step
.getUuid();
144 public SortedMap
<TreeSPath
, StructureElement
> getElements() {
148 public void setElements(SortedMap
<TreeSPath
, StructureElement
> pathNames
) {
149 this.elements
= pathNames
;
152 public String
getUuid() {
156 public void setUuid(String uuid
) {