]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
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 Comparable
<TreeTestResult
> {
29 private Log log
= LogFactory
.getLog(TreeTestResult
.class);
31 private List
<TestResultListener
<TreeTestResult
>> listeners
= new Vector
<TestResultListener
<TreeTestResult
>>();
33 private TreeSPath currentPath
;
34 private TestRun currentTestRun
;
36 private Date closeDate
;
38 private boolean isClosed
= false;
42 private SortedMap
<TreeSPath
, PartSubList
> resultParts
= new TreeMap
<TreeSPath
, PartSubList
>();
43 private SortedMap
<TreeSPath
, StructureElement
> elements
= new TreeMap
<TreeSPath
, StructureElement
>();
45 /** Sets the list of listeners. */
46 public void setListeners(List
<TestResultListener
<TreeTestResult
>> listeners
) {
47 this.listeners
= listeners
;
50 public void addResultPart(TestResultPart part
) {
51 if (currentPath
== null) {
52 throw new SlcException("No current path set.");
54 PartSubList subList
= resultParts
.get(currentPath
);
55 if (subList
== null) {
56 subList
= new PartSubList();
57 resultParts
.put(currentPath
, subList
);
59 if (part
instanceof TestRunAware
&& currentTestRun
!= null) {
60 ((TestRunAware
) part
).notifyTestRun(currentTestRun
);
62 subList
.getParts().add(part
);
65 synchronized (listeners
) {
66 for (TestResultListener
<TreeTestResult
> listener
: listeners
) {
67 listener
.resultPartAdded(this, part
);
72 public void notifyCurrentPath(StructureRegistry
<TreeSPath
> registry
,
74 if (registry
!= null) {
75 for (TreeSPath p
: path
.getHierarchyAsList()) {
76 if (!elements
.containsKey(p
)) {
77 StructureElement elem
= registry
.getElement(p
);
79 elements
.put(p
, elem
);
82 if (log
.isTraceEnabled())
83 log
.trace("An element is already registered for path "
84 + p
+ " and was not updated");
90 currentPath
= (TreeSPath
) path
;
93 /** Gets the current path. */
94 public TreeSPath
getCurrentPath() {
98 /** Gets all the results structured as a map of <code>PartSubList<code>s. */
99 public SortedMap
<TreeSPath
, PartSubList
> getResultParts() {
103 /** Used by ORM systems. */
104 void setResultParts(SortedMap
<TreeSPath
, PartSubList
> resultParts
) {
105 this.resultParts
= resultParts
;
108 public void close() {
110 throw new SlcException("Test Result #" + getUuid()
111 + " alredy closed.");
113 closeDate
= new Date();
115 synchronized (listeners
) {
116 for (TestResultListener
<TreeTestResult
> listener
: listeners
) {
117 listener
.close(this);
123 log
.info("Test Result #" + getUuid() + " closed.");
126 public Date
getCloseDate() {
130 /** Sets the close date (for ORM) */
131 public void setCloseDate(Date closeDate
) {
132 this.closeDate
= closeDate
;
135 public void notifyTestRun(TestRun testRun
) {
136 currentTestRun
= testRun
;
139 public SortedMap
<TreeSPath
, StructureElement
> getElements() {
143 public void setElements(SortedMap
<TreeSPath
, StructureElement
> pathNames
) {
144 this.elements
= pathNames
;
147 public String
getUuid() {
151 public void setUuid(String uuid
) {
155 public SortedMap
<TreeSPath
, StructureElement
> getRelatedElements(
157 SortedMap
<TreeSPath
, StructureElement
> relatedElements
= new TreeMap
<TreeSPath
, StructureElement
>();
158 List
<TreeSPath
> hierarchy
= path
.getHierarchyAsList();
159 for (TreeSPath currPath
: elements
.keySet()) {
160 if (hierarchy
.contains(currPath
)) {
161 relatedElements
.put(currPath
, elements
.get(currPath
));
164 return relatedElements
;
167 public TestRun
getCurrentTestRun() {
168 return currentTestRun
;
171 public int compareTo(TreeTestResult ttr2
) {
172 TreeTestResult ttr1
= this;
173 if (ttr1
.getCloseDate() != null && ttr2
.getCloseDate() != null) {
174 return -ttr1
.getCloseDate().compareTo(ttr2
.getCloseDate());
175 } else if (ttr1
.getCloseDate() != null && ttr2
.getCloseDate() == null) {
177 } else if (ttr1
.getCloseDate() == null && ttr2
.getCloseDate() != null) {
180 return ttr1
.getUuid().compareTo(ttr2
.getUuid());