X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Ftest%2Ftree%2FTreeTestResult.java;h=f34561a9e3b33881d2bd9c425f2d7990b2795132;hb=7ffec52c590ce511b476f55be4ad123418268aa0;hp=6d39d210e9c27f17e00c22cd7f8ce76d5532be2d;hpb=0a985ad4d014b575429384ca8f5247d6c7ad7d40;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java index 6d39d210e..f34561a9e 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java @@ -2,6 +2,7 @@ package org.argeo.slc.core.test.tree; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import java.util.Vector; @@ -10,35 +11,31 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.core.SlcException; -import org.argeo.slc.core.process.SlcExecution; -import org.argeo.slc.core.process.SlcExecutionAware; -import org.argeo.slc.core.process.SlcExecutionStep; +import org.argeo.slc.core.structure.SimpleSElement; import org.argeo.slc.core.structure.StructureAware; import org.argeo.slc.core.structure.StructureElement; import org.argeo.slc.core.structure.StructureRegistry; import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.test.NumericTRId; import org.argeo.slc.core.test.TestResult; -import org.argeo.slc.core.test.TestResultId; import org.argeo.slc.core.test.TestResultListener; import org.argeo.slc.core.test.TestResultPart; +import org.argeo.slc.core.test.TestRun; +import org.argeo.slc.core.test.TestRunAware; /** * Complex implementation of a test result compatible with a tree based * structure. */ public class TreeTestResult implements TestResult, StructureAware, - SlcExecutionAware { + Comparable { private Log log = LogFactory.getLog(TreeTestResult.class); - /** For ORM */ - private Long tid; - //private NumericTRId testResultId; - private List listeners = new Vector(); + private List> listeners = new Vector>(); private TreeSPath currentPath; - private String currentSlcExecutionUuid; - private String currentSlcExecutionStepUuid; + private TestRun currentTestRun; + + private Map rootTags = new TreeMap(); private Date closeDate; @@ -49,27 +46,8 @@ public class TreeTestResult implements TestResult, StructureAware, private SortedMap resultParts = new TreeMap(); private SortedMap elements = new TreeMap(); - private StructureRegistry registry; - -// public TestResultId getTestResultId() { -// return testResultId; -// } - - /** - * Use of a NumericTRId is required by Hibernate. It may - * change in the future. - */ -// public NumericTRId getNumericResultId() { -// return testResultId; -// } - - /** Sets the test result id as a numeric test result id. */ -// public void setNumericResultId(NumericTRId testResultId) { -// this.testResultId = testResultId; -// } - /** Sets the list of listeners. */ - public void setListeners(List listeners) { + public void setListeners(List> listeners) { this.listeners = listeners; } @@ -80,15 +58,16 @@ public class TreeTestResult implements TestResult, StructureAware, PartSubList subList = resultParts.get(currentPath); if (subList == null) { subList = new PartSubList(); - subList.setSlcExecutionUuid(currentSlcExecutionUuid); - subList.setSlcExecutionStepUuid(currentSlcExecutionStepUuid); resultParts.put(currentPath, subList); } + if (part instanceof TestRunAware && currentTestRun != null) { + ((TestRunAware) part).notifyTestRun(currentTestRun); + } subList.getParts().add(part); // notify listeners synchronized (listeners) { - for (TestResultListener listener : listeners) { + for (TestResultListener listener : listeners) { listener.resultPartAdded(this, part); } } @@ -101,18 +80,27 @@ public class TreeTestResult implements TestResult, StructureAware, if (!elements.containsKey(p)) { StructureElement elem = registry.getElement(p); if (elem != null) { - // elements.put(p, elem.getLabel()); + + if (elements.size() == 0 + && (elem instanceof SimpleSElement)) { + SimpleSElement sElem = ((SimpleSElement) elem) + .clone(); + sElem.getTags().putAll(rootTags); + elem = sElem; + } + elements.put(p, elem); - } else { - log.warn("An element is already registered for path " - + p); } + } else { + if (log.isTraceEnabled()) + log.trace("An element is already registered for path " + + p + " and was not updated"); } + } } currentPath = (TreeSPath) path; - this.registry = registry; } /** Gets the current path. */ @@ -138,33 +126,17 @@ public class TreeTestResult implements TestResult, StructureAware, closeDate = new Date(); synchronized (listeners) { - for (TestResultListener listener : listeners) { + for (TestResultListener listener : listeners) { listener.close(this); } listeners.clear(); } isClosed = true; - log.info("Test Result #" + getUuid() + " closed."); - } - - Long getTid() { - return tid; - } - - void setTid(Long tid) { - this.tid = tid; - } - - /** Gets the related registry (can be null). */ - public StructureRegistry getRegistry() { - return registry; + if (log.isTraceEnabled()) + log.trace("Test Result " + getUuid() + " closed."); } - /** Sets the related registry. */ - // public void setRegistry(StructureRegistry registry) { - // this.registry = registry; - // } public Date getCloseDate() { return closeDate; } @@ -174,12 +146,8 @@ public class TreeTestResult implements TestResult, StructureAware, this.closeDate = closeDate; } - public void notifySlcExecution(SlcExecution slcExecution) { - currentSlcExecutionUuid = slcExecution.getUuid(); - SlcExecutionStep step = slcExecution.currentStep(); - if (step != null) { - currentSlcExecutionStepUuid = step.getUuid(); - } + public void notifyTestRun(TestRun testRun) { + currentTestRun = testRun; } public SortedMap getElements() { @@ -198,4 +166,41 @@ public class TreeTestResult implements TestResult, StructureAware, this.uuid = uuid; } + public SortedMap getRelatedElements( + TreeSPath path) { + SortedMap relatedElements = new TreeMap(); + List hierarchy = path.getHierarchyAsList(); + for (TreeSPath currPath : elements.keySet()) { + if (hierarchy.contains(currPath)) { + relatedElements.put(currPath, elements.get(currPath)); + } + } + return relatedElements; + } + + public TestRun getCurrentTestRun() { + return currentTestRun; + } + + public int compareTo(TreeTestResult ttr2) { + TreeTestResult ttr1 = this; + if (ttr1.getCloseDate() != null && ttr2.getCloseDate() != null) { + return -ttr1.getCloseDate().compareTo(ttr2.getCloseDate()); + } else if (ttr1.getCloseDate() != null && ttr2.getCloseDate() == null) { + return 1; + } else if (ttr1.getCloseDate() == null && ttr2.getCloseDate() != null) { + return -1; + } else { + return ttr1.getUuid().compareTo(ttr2.getUuid()); + } + } + + public Map getRootTags() { + return rootTags; + } + + public void setRootTags(Map rootTags) { + this.rootTags = rootTags; + } + }