]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Introduce examples modules
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
index 7e7ae68b7a65cefe539ab9c9339436744ad5ea1e..3e365afe0822c6f28b51f3f835d89189a6fd7328 100644 (file)
@@ -9,9 +9,7 @@ import java.util.Vector;
 \r
 import org.apache.commons.logging.Log;\r
 import org.apache.commons.logging.LogFactory;\r
-\r
 import org.argeo.slc.core.SlcException;\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
@@ -34,27 +32,32 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
 \r
        private TreeSPath currentPath;\r
        private TestRun currentTestRun;\r
-       \r
-       private Map<String, String> rootTags = new TreeMap<String, String>();\r
 \r
        private Date closeDate;\r
 \r
-       private boolean isClosed = false;\r
+       private Boolean isClosed = false;\r
+\r
+       private Boolean warnIfAlreadyClosed = true;\r
 \r
        private String uuid;\r
 \r
        private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
        private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
 \r
+       private Map<String, String> attributes = new TreeMap<String, String>();\r
+\r
        /** Sets the list of listeners. */\r
        public void setListeners(List<TestResultListener<TreeTestResult>> listeners) {\r
                this.listeners = listeners;\r
        }\r
 \r
        public void addResultPart(TestResultPart part) {\r
-               if (currentPath == null) {\r
+               if (isClosed)\r
+                       throw new SlcException("Cannot result parts to a closed result");\r
+\r
+               if (currentPath == null)\r
                        throw new SlcException("No current path set.");\r
-               }\r
+\r
                PartSubList subList = resultParts.get(currentPath);\r
                if (subList == null) {\r
                        subList = new PartSubList();\r
@@ -80,13 +83,6 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                                if (!elements.containsKey(p)) {\r
                                        StructureElement elem = registry.getElement(p);\r
                                        if (elem != null) {\r
-                                               \r
-                                               if(elements.size()==0 && (elem instanceof SimpleSElement)){\r
-                                                       SimpleSElement sElem = ((SimpleSElement)elem).clone();\r
-                                                       sElem.getTags().putAll(rootTags);\r
-                                                       elem = sElem;\r
-                                               }\r
-                                               \r
                                                elements.put(p, elem);\r
                                        }\r
                                } else {\r
@@ -98,7 +94,7 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                        }\r
                }\r
 \r
-               currentPath = (TreeSPath) path;\r
+               currentPath = path;\r
        }\r
 \r
        /** Gets the current path. */\r
@@ -117,10 +113,20 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
        }\r
 \r
        public void close() {\r
+               if (resultParts.size() == 0) {\r
+                       if (log.isTraceEnabled())\r
+                               log.trace("Test Result #" + getUuid()\r
+                                               + " contains no results, no need to close it.");\r
+                       return;\r
+               }\r
+\r
                if (isClosed) {\r
-                       throw new SlcException("Test Result #" + getUuid()\r
-                                       + " alredy closed.");\r
+                       if (warnIfAlreadyClosed)\r
+                               log.warn("Test Result #" + getUuid()\r
+                                               + " already closed. Doing nothing.");\r
+                       return;\r
                }\r
+\r
                closeDate = new Date();\r
 \r
                synchronized (listeners) {\r
@@ -131,7 +137,8 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                }\r
                isClosed = true;\r
 \r
-               log.info("Test Result #" + getUuid() + " closed.");\r
+               if (log.isTraceEnabled())\r
+                       log.trace("Test Result " + getUuid() + " closed.");\r
        }\r
 \r
        public Date getCloseDate() {\r
@@ -165,6 +172,11 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
 \r
        public SortedMap<TreeSPath, StructureElement> getRelatedElements(\r
                        TreeSPath path) {\r
+               if (path == null)\r
+                       throw new SlcException(\r
+                                       "Cannot retrieve element for a null path in result #"\r
+                                                       + uuid);\r
+\r
                SortedMap<TreeSPath, StructureElement> relatedElements = new TreeMap<TreeSPath, StructureElement>();\r
                List<TreeSPath> hierarchy = path.getHierarchyAsList();\r
                for (TreeSPath currPath : elements.keySet()) {\r
@@ -192,12 +204,16 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                }\r
        }\r
 \r
-       public Map<String, String> getRootTags() {\r
-               return rootTags;\r
+       public Map<String, String> getAttributes() {\r
+               return attributes;\r
+       }\r
+\r
+       public void setAttributes(Map<String, String> attributes) {\r
+               this.attributes = attributes;\r
        }\r
 \r
-       public void setRootTags(Map<String, String> rootTags) {\r
-               this.rootTags = rootTags;\r
+       public void setWarnIfAlreadyClosed(Boolean warnIfAlreadyClosed) {\r
+               this.warnIfAlreadyClosed = warnIfAlreadyClosed;\r
        }\r
 \r
 }\r