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=3e365afe0822c6f28b51f3f835d89189a6fd7328;hb=c4e9c29266eb8656d0573a3aff8b6b2a713861d7;hp=328d5981a19499fa0f01ace14a849b4a87f43084;hpb=bebd4282811d302d4c3f48f2efe9c3ee2df03231;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 328d5981a..3e365afe0 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,13 +2,13 @@ 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; import org.apache.commons.logging.Log; 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.StructureElement; @@ -24,7 +24,8 @@ 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,Comparable { +public class TreeTestResult implements TestResult, StructureAware, + Comparable { private Log log = LogFactory.getLog(TreeTestResult.class); private List> listeners = new Vector>(); @@ -34,22 +35,29 @@ public class TreeTestResult implements TestResult, StructureAware,Com private Date closeDate; - private boolean isClosed = false; + private Boolean isClosed = false; + + private Boolean warnIfAlreadyClosed = true; private String uuid; private SortedMap resultParts = new TreeMap(); private SortedMap elements = new TreeMap(); + private Map attributes = new TreeMap(); + /** Sets the list of listeners. */ public void setListeners(List> listeners) { this.listeners = listeners; } public void addResultPart(TestResultPart part) { - if (currentPath == null) { + if (isClosed) + throw new SlcException("Cannot result parts to a closed result"); + + if (currentPath == null) throw new SlcException("No current path set."); - } + PartSubList subList = resultParts.get(currentPath); if (subList == null) { subList = new PartSubList(); @@ -86,7 +94,7 @@ public class TreeTestResult implements TestResult, StructureAware,Com } } - currentPath = (TreeSPath) path; + currentPath = path; } /** Gets the current path. */ @@ -105,10 +113,20 @@ public class TreeTestResult implements TestResult, StructureAware,Com } public void close() { + if (resultParts.size() == 0) { + if (log.isTraceEnabled()) + log.trace("Test Result #" + getUuid() + + " contains no results, no need to close it."); + return; + } + if (isClosed) { - throw new SlcException("Test Result #" + getUuid() - + " alredy closed."); + if (warnIfAlreadyClosed) + log.warn("Test Result #" + getUuid() + + " already closed. Doing nothing."); + return; } + closeDate = new Date(); synchronized (listeners) { @@ -119,7 +137,8 @@ public class TreeTestResult implements TestResult, StructureAware,Com } isClosed = true; - log.info("Test Result #" + getUuid() + " closed."); + if (log.isTraceEnabled()) + log.trace("Test Result " + getUuid() + " closed."); } public Date getCloseDate() { @@ -153,6 +172,11 @@ public class TreeTestResult implements TestResult, StructureAware,Com public SortedMap getRelatedElements( TreeSPath path) { + if (path == null) + throw new SlcException( + "Cannot retrieve element for a null path in result #" + + uuid); + SortedMap relatedElements = new TreeMap(); List hierarchy = path.getHierarchyAsList(); for (TreeSPath currPath : elements.keySet()) { @@ -180,4 +204,16 @@ public class TreeTestResult implements TestResult, StructureAware,Com } } + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + public void setWarnIfAlreadyClosed(Boolean warnIfAlreadyClosed) { + this.warnIfAlreadyClosed = warnIfAlreadyClosed; + } + }