]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/FullHtmlTreeReport.java
Improve comments
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / core / test / tree / FullHtmlTreeReport.java
index 9dd7610335181fee1e8341c5cee21be2515a1197..dd418477d9d661f8b0140044d4040561b7078568 100644 (file)
@@ -5,20 +5,36 @@ import java.io.FileWriter;
 import java.io.IOException;\r
 import java.util.List;\r
 \r
+import org.argeo.slc.core.SlcException;\r
+import org.argeo.slc.core.structure.StructureAware;\r
+import org.argeo.slc.core.structure.StructureElement;\r
+import org.argeo.slc.core.structure.StructurePath;\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.core.test.SimpleResultPart;\r
 import org.argeo.slc.core.test.TestReport;\r
 import org.argeo.slc.core.test.TestResult;\r
 import org.argeo.slc.core.test.TestResultPart;\r
+import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
 import org.argeo.slc.dao.test.TestResultDao;\r
 \r
-public class FullHtmlTreeReport implements TestReport {\r
+/**\r
+ * Basic implementation of TestReport generating static HTML pages. If a\r
+ * <code>TestResultDao</code> is passed, all the datas are dumped, otherwise\r
+ * only the passed <code>TestResult</code>.\r
+ */\r
+public class FullHtmlTreeReport implements TestReport, StructureAware {\r
        private TestResultDao testResultDao;\r
+       private TreeSRegistryDao treeSRegistryDao;\r
        private File reportDir;\r
 \r
+       private StructureRegistry registry;\r
+\r
        public void generateTestReport(TestResult testResult) {\r
+               \r
                if (testResultDao == null) {\r
                        TreeTestResult result = (TreeTestResult) testResult;\r
+                       initRegistry(result.getResultParts().firstKey());\r
                        generateResultPage(getResultFile(result), result);\r
                } else {\r
                        if (reportDir.exists()) {\r
@@ -35,13 +51,14 @@ public class FullHtmlTreeReport implements TestReport {
 \r
                        List<TestResult> list = testResultDao.listTestResults();\r
                        for (TestResult testRes : list) {\r
-                               TreeTestResult res = (TreeTestResult) testRes;\r
+                               TreeTestResult result = (TreeTestResult) testRes;\r
+                               initRegistry(result.getResultParts().firstKey());\r
 \r
-                               File file = getResultFile(res);\r
+                               File file = getResultFile(result);\r
                                index.append("<tr><td><a href=\"").append(file.getName())\r
                                                .append("\">");\r
-                               index.append(res.getTestResultId()).append("</a></td></tr>\n");\r
-                               generateResultPage(file, res);\r
+                               index.append(result.getTestResultId()).append("</a></td></tr>\n");\r
+                               generateResultPage(file, result);\r
                        }\r
 \r
                        index.append("</table>\n</body></html>");\r
@@ -58,6 +75,14 @@ public class FullHtmlTreeReport implements TestReport {
                }\r
        }\r
 \r
+       /**\r
+        * Generates a result page for one test result\r
+        * \r
+        * @param file\r
+        *            file to which generate the HTML\r
+        * @param result\r
+        *            the result to dump\r
+        */\r
        protected void generateResultPage(File file, TreeTestResult result) {\r
                StringBuffer buf = new StringBuffer("");\r
                buf.append("<html>\n");\r
@@ -71,7 +96,17 @@ public class FullHtmlTreeReport implements TestReport {
 \r
                buf.append("<table border=1>\n");\r
                for (TreeSPath path : result.getResultParts().keySet()) {\r
-                       buf.append("<tr><td>").append(path).append("</td>\n");\r
+                       buf.append("<tr><td>");\r
+                       buf.append(path);\r
+                       StructureElement element = registry.getElement(path);\r
+                       if (registry != null) {\r
+                               if (element != null) {\r
+                                       buf.append("<br/><b>");\r
+                                       buf.append(element.getDescription());\r
+                                       buf.append("</b>");\r
+                               }\r
+                       }\r
+                       buf.append("</td>\n");\r
                        buf.append("<td>");\r
                        PartSubList subList = (PartSubList) result.getResultParts().get(\r
                                        path);\r
@@ -79,7 +114,7 @@ public class FullHtmlTreeReport implements TestReport {
                        for (TestResultPart part : subList.getParts()) {\r
                                SimpleResultPart sPart = (SimpleResultPart) part;\r
                                String color = "yellow";\r
-                               if (sPart.getStatus() == SimpleResultPart.PASSED) {\r
+                               if (sPart.getStatus().equals(SimpleResultPart.PASSED)) {\r
                                        color = "green";\r
                                } else {\r
                                        color = "red";\r
@@ -108,17 +143,41 @@ public class FullHtmlTreeReport implements TestReport {
                }\r
        }\r
 \r
+       /**\r
+        * Generates a result file location based on the report dir and the id of\r
+        * the test result.\r
+        */\r
        protected File getResultFile(TreeTestResult result) {\r
                return new File(reportDir.getPath() + File.separator\r
                                + result.getTestResultId() + ".html");\r
        }\r
 \r
+       /** Sets the DAO to use to extract all data. */\r
        public void setTestResultDao(TestResultDao testResultDao) {\r
                this.testResultDao = testResultDao;\r
        }\r
 \r
+       /** Sets the tree structure registry DAO.*/\r
+       public void setTreeSRegistryDao(TreeSRegistryDao treeSRegistryDao) {\r
+               this.treeSRegistryDao = treeSRegistryDao;\r
+       }\r
+\r
+       /** Sets the directory where to generate all the data. */\r
        public void setReportDir(File reportDir) {\r
                this.reportDir = reportDir;\r
        }\r
 \r
+       private void initRegistry(TreeSPath path){\r
+               if(treeSRegistryDao != null){\r
+                       registry = treeSRegistryDao.getTreeSRegistry(path);\r
+               }\r
+               if(registry==null){\r
+                       throw new SlcException("No structure registry available");\r
+               }\r
+       }\r
+       \r
+       public void notifyCurrentPath(StructureRegistry registry, StructurePath path) {\r
+               this.registry = registry;\r
+       }\r
+\r
 }\r