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=9b807c904be55023d0ab614273c3a442c51e629d;hb=62e442adb36b006627b17061864dfa4edde0a99a;hp=3124b055fcb3339c3aff75c241faa58cd6dfcd91;hpb=faf680e212bf3e18837c4f798587856e061273b3;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 3124b055f..9b807c904 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 @@ -11,53 +11,35 @@ import org.apache.commons.logging.LogFactory; import org.argeo.slc.core.SlcException; import org.argeo.slc.core.structure.StructureAware; -import org.argeo.slc.core.structure.StructurePath; +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 { +public class TreeTestResult implements TestResult, StructureAware { private Log log = LogFactory.getLog(TreeTestResult.class); - /** For ORM */ - private Long tid; - private NumericTRId testResultId; private List listeners = new Vector(); private TreeSPath currentPath; + private TestRun currentTestRun; private Date closeDate; private boolean isClosed = false; - private SortedMap resultParts = new TreeMap(); - - private StructureRegistry registry; - - public TestResultId getTestResultId() { - return testResultId; - } + private String uuid; - /** - * 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; - } + private SortedMap resultParts = new TreeMap(); + private SortedMap elements = new TreeMap(); /** Sets the list of listeners. */ public void setListeners(List listeners) { @@ -73,6 +55,9 @@ public class TreeTestResult implements TestResult, StructureAware { subList = new PartSubList(); resultParts.put(currentPath, subList); } + if (part instanceof TestRunAware && currentTestRun != null) { + ((TestRunAware) part).notifyTestRun(currentTestRun); + } subList.getParts().add(part); // notify listeners @@ -83,9 +68,25 @@ public class TreeTestResult implements TestResult, StructureAware { } } - public void notifyCurrentPath(StructureRegistry registry, StructurePath path) { + public void notifyCurrentPath(StructureRegistry registry, + TreeSPath path) { + if (registry != null) { + for (TreeSPath p : path.getHierarchyAsList()) { + if (!elements.containsKey(p)) { + StructureElement elem = registry.getElement(p); + if (elem != null) { + elements.put(p, elem); + } + } 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. */ @@ -105,7 +106,7 @@ public class TreeTestResult implements TestResult, StructureAware { public void close() { if (isClosed) { - throw new SlcException("Test Result #" + getTestResultId() + throw new SlcException("Test Result #" + getUuid() + " alredy closed."); } closeDate = new Date(); @@ -118,34 +119,53 @@ public class TreeTestResult implements TestResult, StructureAware { } isClosed = true; - log.info("Test Result #" + getTestResultId() + " closed."); + log.info("Test Result #" + getUuid() + " closed."); + } + + public Date getCloseDate() { + return closeDate; } - Long getTid() { - return tid; + /** Sets the close date (for ORM) */ + public void setCloseDate(Date closeDate) { + this.closeDate = closeDate; } - void setTid(Long tid) { - this.tid = tid; + public void notifyTestRun(TestRun testRun) { + currentTestRun = testRun; } - /** Gets the related registry (can be null). */ - public StructureRegistry getRegistry() { - return registry; + public SortedMap getElements() { + return elements; } - /** Sets the related registry. */ - public void setRegistry(StructureRegistry registry) { - this.registry = registry; + public void setElements(SortedMap pathNames) { + this.elements = pathNames; } - public Date getCloseDate() { - return closeDate; + public String getUuid() { + return uuid; } - /** Sets the close date (for ORM) */ - public void setCloseDate(Date closeDate) { - this.closeDate = closeDate; + public void setUuid(String uuid) { + 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; + } + + }