]>
git.argeo.org Git - gpl/argeo-slc.git/blob - TreeTestResult.java
ecd6cad52ac1921190d06a36a1f438bc41f59d60
1 package org
.argeo
.slc
.core
.test
.tree
;
6 import java
.util
.SortedMap
;
7 import java
.util
.TreeMap
;
8 import java
.util
.Vector
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.slc
.core
.SlcException
;
13 import org
.argeo
.slc
.core
.structure
.SimpleSElement
;
14 import org
.argeo
.slc
.core
.structure
.StructureAware
;
15 import org
.argeo
.slc
.core
.structure
.StructureElement
;
16 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
17 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
18 import org
.argeo
.slc
.core
.test
.TestResult
;
19 import org
.argeo
.slc
.core
.test
.TestResultListener
;
20 import org
.argeo
.slc
.core
.test
.TestResultPart
;
21 import org
.argeo
.slc
.core
.test
.TestRun
;
22 import org
.argeo
.slc
.core
.test
.TestRunAware
;
25 * Complex implementation of a test result compatible with a tree based
28 public class TreeTestResult
implements TestResult
, StructureAware
<TreeSPath
>,
29 Comparable
<TreeTestResult
> {
30 private Log log
= LogFactory
.getLog(TreeTestResult
.class);
32 private List
<TestResultListener
<TreeTestResult
>> listeners
= new Vector
<TestResultListener
<TreeTestResult
>>();
34 private TreeSPath currentPath
;
35 private TestRun currentTestRun
;
37 private Map
<String
, String
> rootTags
= new TreeMap
<String
, String
>();
39 private Date closeDate
;
41 private boolean isClosed
= false;
45 private SortedMap
<TreeSPath
, PartSubList
> resultParts
= new TreeMap
<TreeSPath
, PartSubList
>();
46 private SortedMap
<TreeSPath
, StructureElement
> elements
= new TreeMap
<TreeSPath
, StructureElement
>();
48 /** Sets the list of listeners. */
49 public void setListeners(List
<TestResultListener
<TreeTestResult
>> listeners
) {
50 this.listeners
= listeners
;
53 public void addResultPart(TestResultPart part
) {
54 if (currentPath
== null) {
55 throw new SlcException("No current path set.");
57 PartSubList subList
= resultParts
.get(currentPath
);
58 if (subList
== null) {
59 subList
= new PartSubList();
60 resultParts
.put(currentPath
, subList
);
62 if (part
instanceof TestRunAware
&& currentTestRun
!= null) {
63 ((TestRunAware
) part
).notifyTestRun(currentTestRun
);
65 subList
.getParts().add(part
);
68 synchronized (listeners
) {
69 for (TestResultListener
<TreeTestResult
> listener
: listeners
) {
70 listener
.resultPartAdded(this, part
);
75 public void notifyCurrentPath(StructureRegistry
<TreeSPath
> registry
,
77 if (registry
!= null) {
78 for (TreeSPath p
: path
.getHierarchyAsList()) {
79 if (!elements
.containsKey(p
)) {
80 StructureElement elem
= registry
.getElement(p
);
83 if (elements
.size() == 0
84 && (elem
instanceof SimpleSElement
)) {
85 SimpleSElement sElem
= ((SimpleSElement
) elem
)
87 sElem
.getTags().putAll(rootTags
);
91 elements
.put(p
, elem
);
94 if (log
.isTraceEnabled())
95 log
.trace("An element is already registered for path "
96 + p
+ " and was not updated");
105 /** Gets the current path. */
106 public TreeSPath
getCurrentPath() {
110 /** Gets all the results structured as a map of <code>PartSubList<code>s. */
111 public SortedMap
<TreeSPath
, PartSubList
> getResultParts() {
115 /** Used by ORM systems. */
116 void setResultParts(SortedMap
<TreeSPath
, PartSubList
> resultParts
) {
117 this.resultParts
= resultParts
;
120 public void close() {
122 throw new SlcException("Test Result #" + getUuid()
123 + " alredy closed.");
125 closeDate
= new Date();
127 synchronized (listeners
) {
128 for (TestResultListener
<TreeTestResult
> listener
: listeners
) {
129 listener
.close(this);
135 if (log
.isTraceEnabled())
136 log
.trace("Test Result " + getUuid() + " closed.");
139 public Date
getCloseDate() {
143 /** Sets the close date (for ORM) */
144 public void setCloseDate(Date closeDate
) {
145 this.closeDate
= closeDate
;
148 public void notifyTestRun(TestRun testRun
) {
149 currentTestRun
= testRun
;
152 public SortedMap
<TreeSPath
, StructureElement
> getElements() {
156 public void setElements(SortedMap
<TreeSPath
, StructureElement
> pathNames
) {
157 this.elements
= pathNames
;
160 public String
getUuid() {
164 public void setUuid(String uuid
) {
168 public SortedMap
<TreeSPath
, StructureElement
> getRelatedElements(
171 throw new SlcException(
172 "Cannot retrieve element for a null path in result #"
175 SortedMap
<TreeSPath
, StructureElement
> relatedElements
= new TreeMap
<TreeSPath
, StructureElement
>();
176 List
<TreeSPath
> hierarchy
= path
.getHierarchyAsList();
177 for (TreeSPath currPath
: elements
.keySet()) {
178 if (hierarchy
.contains(currPath
)) {
179 relatedElements
.put(currPath
, elements
.get(currPath
));
182 return relatedElements
;
185 public TestRun
getCurrentTestRun() {
186 return currentTestRun
;
189 public int compareTo(TreeTestResult ttr2
) {
190 TreeTestResult ttr1
= this;
191 if (ttr1
.getCloseDate() != null && ttr2
.getCloseDate() != null) {
192 return -ttr1
.getCloseDate().compareTo(ttr2
.getCloseDate());
193 } else if (ttr1
.getCloseDate() != null && ttr2
.getCloseDate() == null) {
195 } else if (ttr1
.getCloseDate() == null && ttr2
.getCloseDate() != null) {
198 return ttr1
.getUuid().compareTo(ttr2
.getUuid());
202 public Map
<String
, String
> getRootTags() {
206 public void setRootTags(Map
<String
, String
> rootTags
) {
207 this.rootTags
= rootTags
;