\r
import java.util.Date;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.SortedMap;\r
import java.util.TreeMap;\r
import java.util.Vector;\r
import org.apache.commons.logging.LogFactory;\r
\r
import org.argeo.slc.core.SlcException;\r
-import org.argeo.slc.core.process.SlcExecution;\r
-import org.argeo.slc.core.process.SlcExecutionAware;\r
-import org.argeo.slc.core.process.SlcExecutionStep;\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
import org.argeo.slc.core.structure.StructureAware;\r
import org.argeo.slc.core.structure.StructureElement;\r
import org.argeo.slc.core.structure.StructureRegistry;\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.NumericTRId;\r
import org.argeo.slc.core.test.TestResult;\r
-import org.argeo.slc.core.test.TestResultId;\r
import org.argeo.slc.core.test.TestResultListener;\r
import org.argeo.slc.core.test.TestResultPart;\r
+import org.argeo.slc.core.test.TestRun;\r
+import org.argeo.slc.core.test.TestRunAware;\r
\r
/**\r
* Complex implementation of a test result compatible with a tree based\r
* structure.\r
*/\r
public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
- SlcExecutionAware {\r
+ Comparable<TreeTestResult> {\r
private Log log = LogFactory.getLog(TreeTestResult.class);\r
- /** For ORM */\r
- private Long tid;\r
\r
- //private NumericTRId testResultId;\r
- private List<TestResultListener> listeners = new Vector<TestResultListener>();\r
+ private List<TestResultListener<TreeTestResult>> listeners = new Vector<TestResultListener<TreeTestResult>>();\r
\r
private TreeSPath currentPath;\r
- private String currentSlcExecutionUuid;\r
- private String currentSlcExecutionStepUuid;\r
+ private TestRun currentTestRun;\r
+\r
+ private Map<String, String> rootTags = new TreeMap<String, String>();\r
\r
private Date closeDate;\r
\r
private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
\r
- private StructureRegistry<TreeSPath> registry;\r
-\r
-// public TestResultId getTestResultId() {\r
-// return testResultId;\r
-// }\r
-\r
- /**\r
- * Use of a <code>NumericTRId</code> is required by Hibernate. <b>It may\r
- * change in the future.</b>\r
- */\r
-// public NumericTRId getNumericResultId() {\r
-// return testResultId;\r
-// }\r
-\r
- /** Sets the test result id as a numeric test result id. */\r
-// public void setNumericResultId(NumericTRId testResultId) {\r
-// this.testResultId = testResultId;\r
-// }\r
-\r
/** Sets the list of listeners. */\r
- public void setListeners(List<TestResultListener> listeners) {\r
+ public void setListeners(List<TestResultListener<TreeTestResult>> listeners) {\r
this.listeners = listeners;\r
}\r
\r
PartSubList subList = resultParts.get(currentPath);\r
if (subList == null) {\r
subList = new PartSubList();\r
- subList.setSlcExecutionUuid(currentSlcExecutionUuid);\r
- subList.setSlcExecutionStepUuid(currentSlcExecutionStepUuid);\r
resultParts.put(currentPath, subList);\r
}\r
+ if (part instanceof TestRunAware && currentTestRun != null) {\r
+ ((TestRunAware) part).notifyTestRun(currentTestRun);\r
+ }\r
subList.getParts().add(part);\r
\r
// notify listeners\r
synchronized (listeners) {\r
- for (TestResultListener listener : listeners) {\r
+ for (TestResultListener<TreeTestResult> listener : listeners) {\r
listener.resultPartAdded(this, part);\r
}\r
}\r
if (!elements.containsKey(p)) {\r
StructureElement elem = registry.getElement(p);\r
if (elem != null) {\r
- // elements.put(p, elem.getLabel());\r
+\r
+ if (elements.size() == 0\r
+ && (elem instanceof SimpleSElement)) {\r
+ SimpleSElement sElem = ((SimpleSElement) elem)\r
+ .clone();\r
+ sElem.getTags().putAll(rootTags);\r
+ elem = sElem;\r
+ }\r
+\r
elements.put(p, elem);\r
- } else {\r
- log.warn("An element is already registered for path "\r
- + p);\r
}\r
+ } else {\r
+ if (log.isTraceEnabled())\r
+ log.trace("An element is already registered for path "\r
+ + p + " and was not updated");\r
}\r
+\r
}\r
}\r
\r
currentPath = (TreeSPath) path;\r
- this.registry = registry;\r
}\r
\r
/** Gets the current path. */\r
closeDate = new Date();\r
\r
synchronized (listeners) {\r
- for (TestResultListener listener : listeners) {\r
+ for (TestResultListener<TreeTestResult> listener : listeners) {\r
listener.close(this);\r
}\r
listeners.clear();\r
}\r
isClosed = true;\r
\r
- log.info("Test Result #" + getUuid() + " closed.");\r
- }\r
-\r
- Long getTid() {\r
- return tid;\r
- }\r
-\r
- void setTid(Long tid) {\r
- this.tid = tid;\r
- }\r
-\r
- /** Gets the related registry (can be null). */\r
- public StructureRegistry<TreeSPath> getRegistry() {\r
- return registry;\r
+ if (log.isTraceEnabled())\r
+ log.trace("Test Result " + getUuid() + " closed.");\r
}\r
\r
- /** Sets the related registry. */\r
- // public void setRegistry(StructureRegistry<TreeSPath> registry) {\r
- // this.registry = registry;\r
- // }\r
public Date getCloseDate() {\r
return closeDate;\r
}\r
this.closeDate = closeDate;\r
}\r
\r
- public void notifySlcExecution(SlcExecution slcExecution) {\r
- currentSlcExecutionUuid = slcExecution.getUuid();\r
- SlcExecutionStep step = slcExecution.currentStep();\r
- if (step != null) {\r
- currentSlcExecutionStepUuid = step.getUuid();\r
- }\r
+ public void notifyTestRun(TestRun testRun) {\r
+ currentTestRun = testRun;\r
}\r
\r
public SortedMap<TreeSPath, StructureElement> getElements() {\r
this.uuid = uuid;\r
}\r
\r
+ public SortedMap<TreeSPath, StructureElement> getRelatedElements(\r
+ TreeSPath path) {\r
+ SortedMap<TreeSPath, StructureElement> relatedElements = new TreeMap<TreeSPath, StructureElement>();\r
+ List<TreeSPath> hierarchy = path.getHierarchyAsList();\r
+ for (TreeSPath currPath : elements.keySet()) {\r
+ if (hierarchy.contains(currPath)) {\r
+ relatedElements.put(currPath, elements.get(currPath));\r
+ }\r
+ }\r
+ return relatedElements;\r
+ }\r
+\r
+ public TestRun getCurrentTestRun() {\r
+ return currentTestRun;\r
+ }\r
+\r
+ public int compareTo(TreeTestResult ttr2) {\r
+ TreeTestResult ttr1 = this;\r
+ if (ttr1.getCloseDate() != null && ttr2.getCloseDate() != null) {\r
+ return -ttr1.getCloseDate().compareTo(ttr2.getCloseDate());\r
+ } else if (ttr1.getCloseDate() != null && ttr2.getCloseDate() == null) {\r
+ return 1;\r
+ } else if (ttr1.getCloseDate() == null && ttr2.getCloseDate() != null) {\r
+ return -1;\r
+ } else {\r
+ return ttr1.getUuid().compareTo(ttr2.getUuid());\r
+ }\r
+ }\r
+\r
+ public Map<String, String> getRootTags() {\r
+ return rootTags;\r
+ }\r
+\r
+ public void setRootTags(Map<String, String> rootTags) {\r
+ this.rootTags = rootTags;\r
+ }\r
+\r
}\r