]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Improve web services
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
index a012c4451b065a3e26926f710d4712cd5dc04068..ecd6cad52ac1921190d06a36a1f438bc41f59d60 100644 (file)
@@ -2,14 +2,15 @@ package org.argeo.slc.core.test.tree;
 \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
 \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
@@ -24,7 +25,8 @@ import org.argeo.slc.core.test.TestRunAware;
  * Complex implementation of a test result compatible with a tree based\r
  * structure.\r
  */\r
-public class TreeTestResult implements TestResult, StructureAware<TreeSPath> {\r
+public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
+               Comparable<TreeTestResult> {\r
        private Log log = LogFactory.getLog(TreeTestResult.class);\r
 \r
        private List<TestResultListener<TreeTestResult>> listeners = new Vector<TestResultListener<TreeTestResult>>();\r
@@ -32,6 +34,8 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath> {
        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
@@ -75,6 +79,15 @@ 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\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
                                        }\r
                                } else {\r
@@ -86,7 +99,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
@@ -119,7 +132,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
@@ -153,6 +167,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
@@ -167,4 +186,25 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath> {
                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