]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java
Various changes
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / TreeTestResult.java
index 36233e9942a2d321cb73b39d5d86842638adb275..9b807c904be55023d0ab614273c3a442c51e629d 100644 (file)
@@ -10,61 +10,36 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;\r
 \r
 import org.argeo.slc.core.SlcException;\r
-import org.argeo.slc.core.process.SlcExecution;\r
-import org.argeo.slc.core.process.SlcExecutionAware;\r
-import org.argeo.slc.core.process.SlcExecutionStep;\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
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.NumericTRId;\r
 import org.argeo.slc.core.test.TestResult;\r
-import org.argeo.slc.core.test.TestResultId;\r
 import org.argeo.slc.core.test.TestResultListener;\r
 import org.argeo.slc.core.test.TestResultPart;\r
+import org.argeo.slc.core.test.TestRun;\r
+import org.argeo.slc.core.test.TestRunAware;\r
 \r
 /**\r
  * Complex implementation of a test result compatible with a tree based\r
  * structure.\r
  */\r
-public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,\r
-               SlcExecutionAware {\r
+public class TreeTestResult implements TestResult, StructureAware<TreeSPath> {\r
        private Log log = LogFactory.getLog(TreeTestResult.class);\r
-       /** For ORM */\r
-       private Long tid;\r
 \r
-       private NumericTRId testResultId;\r
        private List<TestResultListener> listeners = new Vector<TestResultListener>();\r
 \r
        private TreeSPath currentPath;\r
-       private String currentSlcExecutionUuid;\r
-       private String currentSlcExecutionStepUuid;\r
+       private TestRun currentTestRun;\r
 \r
        private Date closeDate;\r
 \r
        private boolean isClosed = false;\r
 \r
-       private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
-       private SortedMap<TreeSPath, String> pathNames = new TreeMap<TreeSPath, String>();\r
-\r
-       private StructureRegistry<TreeSPath> registry;\r
-\r
-       public TestResultId getTestResultId() {\r
-               return testResultId;\r
-       }\r
+       private String uuid;\r
 \r
-       /**\r
-        * Use of a <code>NumericTRId</code> is required by Hibernate. <b>It may\r
-        * change in the future.</b>\r
-        */\r
-       public NumericTRId getNumericResultId() {\r
-               return testResultId;\r
-       }\r
-\r
-       /** Sets the test result id as a numeric test result id. */\r
-       public void setNumericResultId(NumericTRId testResultId) {\r
-               this.testResultId = testResultId;\r
-       }\r
+       private SortedMap<TreeSPath, PartSubList> resultParts = new TreeMap<TreeSPath, PartSubList>();\r
+       private SortedMap<TreeSPath, StructureElement> elements = new TreeMap<TreeSPath, StructureElement>();\r
 \r
        /** Sets the list of listeners. */\r
        public void setListeners(List<TestResultListener> listeners) {\r
@@ -78,10 +53,11 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                PartSubList subList = resultParts.get(currentPath);\r
                if (subList == null) {\r
                        subList = new PartSubList();\r
-                       subList.setSlcExecutionUuid(currentSlcExecutionUuid);\r
-                       subList.setSlcExecutionStepUuid(currentSlcExecutionStepUuid);\r
                        resultParts.put(currentPath, subList);\r
                }\r
+               if (part instanceof TestRunAware && currentTestRun != null) {\r
+                       ((TestRunAware) part).notifyTestRun(currentTestRun);\r
+               }\r
                subList.getParts().add(part);\r
 \r
                // notify listeners\r
@@ -96,17 +72,21 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                        TreeSPath path) {\r
                if (registry != null) {\r
                        for (TreeSPath p : path.getHierarchyAsList()) {\r
-                               if (!pathNames.containsKey(p)) {\r
+                               if (!elements.containsKey(p)) {\r
                                        StructureElement elem = registry.getElement(p);\r
                                        if (elem != null) {\r
-                                               pathNames.put(p, elem.getLabel());\r
+                                               elements.put(p, elem);\r
                                        }\r
+                               } else {\r
+                                       if (log.isTraceEnabled())\r
+                                               log.trace("An element is already registered for path "\r
+                                                               + p + " and was not updated");\r
                                }\r
+\r
                        }\r
                }\r
 \r
                currentPath = (TreeSPath) path;\r
-               this.registry = registry;\r
        }\r
 \r
        /** Gets the current path. */\r
@@ -126,7 +106,7 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
 \r
        public void close() {\r
                if (isClosed) {\r
-                       throw new SlcException("Test Result #" + getTestResultId()\r
+                       throw new SlcException("Test Result #" + getUuid()\r
                                        + " alredy closed.");\r
                }\r
                closeDate = new Date();\r
@@ -139,49 +119,53 @@ public class TreeTestResult implements TestResult, StructureAware<TreeSPath>,
                }\r
                isClosed = true;\r
 \r
-               log.info("Test Result #" + getTestResultId() + " closed.");\r
+               log.info("Test Result #" + getUuid() + " closed.");\r
        }\r
 \r
-       Long getTid() {\r
-               return tid;\r
+       public Date getCloseDate() {\r
+               return closeDate;\r
        }\r
 \r
-       void setTid(Long tid) {\r
-               this.tid = tid;\r
+       /** Sets the close date (for ORM) */\r
+       public void setCloseDate(Date closeDate) {\r
+               this.closeDate = closeDate;\r
        }\r
 \r
-       /** Gets the related registry (can be null). */\r
-       public StructureRegistry<TreeSPath> getRegistry() {\r
-               return registry;\r
+       public void notifyTestRun(TestRun testRun) {\r
+               currentTestRun = testRun;\r
        }\r
 \r
-       /** Sets the related registry. */\r
-       // public void setRegistry(StructureRegistry<TreeSPath> registry) {\r
-       // this.registry = registry;\r
-       // }\r
-       public Date getCloseDate() {\r
-               return closeDate;\r
+       public SortedMap<TreeSPath, StructureElement> getElements() {\r
+               return elements;\r
        }\r
 \r
-       /** Sets the close date (for ORM) */\r
-       public void setCloseDate(Date closeDate) {\r
-               this.closeDate = closeDate;\r
+       public void setElements(SortedMap<TreeSPath, StructureElement> pathNames) {\r
+               this.elements = pathNames;\r
        }\r
 \r
-       public void notifySlcExecution(SlcExecution slcExecution) {\r
-               currentSlcExecutionUuid = slcExecution.getUuid();\r
-               SlcExecutionStep step = slcExecution.currentStep();\r
-               if (step != null) {\r
-                       currentSlcExecutionStepUuid = step.getUuid();\r
-               }\r
+       public String getUuid() {\r
+               return uuid;\r
        }\r
 \r
-       public SortedMap<TreeSPath, String> getPathNames() {\r
-               return pathNames;\r
+       public void setUuid(String uuid) {\r
+               this.uuid = uuid;\r
        }\r
 \r
-       public void setPathNames(SortedMap<TreeSPath, String> pathNames) {\r
-               this.pathNames = pathNames;\r
+       public SortedMap<TreeSPath, StructureElement> getRelatedElements(\r
+                       TreeSPath path) {\r
+               SortedMap<TreeSPath, StructureElement> relatedElements = new TreeMap<TreeSPath, StructureElement>();\r
+               List<TreeSPath> hierarchy = path.getHierarchyAsList();\r
+               for (TreeSPath currPath : elements.keySet()) {\r
+                       if (hierarchy.contains(currPath)) {\r
+                               relatedElements.put(currPath, elements.get(currPath));\r
+                       }\r
+               }\r
+               return relatedElements;\r
        }\r
 \r
+       public TestRun getCurrentTestRun() {\r
+               return currentTestRun;\r
+       }\r
+       \r
+       \r
 }\r