]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/htmlreport/ResultPage.java
Manage with Maven
[gpl/argeo-slc.git] / org.argeo.slc / src / main / java / org / argeo / slc / core / test / tree / htmlreport / ResultPage.java
index 06bf7c30d3cffe37dcccb48d7dc7d1b91eba8f30..22fa7a39c879f7f0d546f17f367116a32b31b656 100644 (file)
@@ -1,12 +1,14 @@
 package org.argeo.slc.core.test.tree.htmlreport;\r
 \r
 import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.io.StringWriter;\r
+import java.util.Date;\r
 import java.util.SortedMap;\r
 import java.util.TreeMap;\r
 \r
-import javax.swing.tree.TreePath;\r
-\r
 import org.apache.commons.io.FileUtils;\r
+import org.apache.commons.io.IOUtils;\r
 import org.apache.commons.logging.Log;\r
 import org.apache.commons.logging.LogFactory;\r
 \r
@@ -42,18 +44,23 @@ class ResultPage {
                StringBuffer buf = new StringBuffer("");\r
                buf.append("<html>\n");\r
                buf.append("<header>");\r
-               buf.append("<title>Result #").append(result.getTestResultId()).append(\r
-                               "</title>\n");\r
-               buf\r
-                               .append("<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\"/>");\r
+               buf.append("<title>Result #").append(result.getTestResultId());\r
+               buf.append("</title>\n");\r
+               report.addStyles(buf);\r
                buf.append("</header>\n");\r
 \r
                buf.append("<body>\n");\r
 \r
                // Header\r
+               buf.append("<a name=\"top\"/>\n");\r
                buf.append("<h1>Result #").append(result.getTestResultId()).append(\r
                                "</h1>\n");\r
-               buf.append(report.sdf.format(result.getCloseDate()));\r
+               Date closeDate = result.getCloseDate();\r
+               if (closeDate == null) {\r
+                       buf.append("[Not closed]");\r
+               } else {\r
+                       buf.append(report.sdf.format(closeDate));\r
+               }\r
 \r
                // TOC\r
                generateToc(buf, registry);\r
@@ -126,33 +133,49 @@ class ResultPage {
                        buf.append("<p>\n");\r
                        buf.append("<a name=\"").append(anchor(path)).append("\"></a>");\r
                        buf.append("<h2>");\r
-                       String description = path.getName();\r
-                       if (registry != null) {\r
-                               StructureElement element = registry.getElement(path);\r
-                               if (element != null) {\r
-                                       description = element.getDescription();\r
-                               }\r
-                       }\r
-                       buf.append(description);\r
+                       describedPath(path, registry, buf);\r
                        buf.append("</h2>");\r
 \r
                        PartSubList subList = (PartSubList) result.getResultParts().get(\r
                                        path);\r
                        buf.append("<table border=0>\n");\r
+                       int displayedIndex = 1;// for display only\r
                        for (TestResultPart part : subList.getParts()) {\r
                                SimpleResultPart sPart = (SimpleResultPart) part;\r
                                String clss = "";\r
-                               if (sPart.getStatus().equals(SimpleResultPart.PASSED)) {\r
+                               if (sPart.getStatus().equals(TestStatus.PASSED)) {\r
                                        clss = "passed";\r
                                } else {\r
                                        clss = "failed";\r
                                }\r
-                               buf.append("<tr><td class=\"").append(clss).append("\">");\r
+                               buf.append("<tr>");\r
+                               buf.append("<td><b>").append(displayedIndex)\r
+                                               .append("</b></td>");\r
+                               buf.append("<td class=\"").append(clss).append("\">");\r
 \r
                                buf.append(sPart.getMessage());\r
-                               buf.append("</td></tr>\n");\r
+                               if (sPart.getStatus().equals(TestStatus.ERROR)) {\r
+                                       buf\r
+                                                       .append("<p><b>An unexpected error prevented the test to run properly.</b>");\r
+                                       Throwable exception = sPart.getException();\r
+                                       if (exception != null) {\r
+                                               StringWriter writer = new StringWriter();\r
+                                               exception.printStackTrace(new PrintWriter(writer));\r
+                                               buf.append("<br/><pre>");\r
+                                               buf.append(writer.toString());\r
+                                               buf.append("</pre>");\r
+                                               IOUtils.closeQuietly(writer);\r
+                                       }\r
+                                       buf.append("</p>");\r
+                               }\r
+                               buf.append("</td>");\r
+                               buf.append("</tr>\n");\r
+\r
+                               displayedIndex++;\r
                        }\r
                        buf.append("</table>\n");\r
+                       buf.append("<a class=\"nav\" href=\"#top\">top</a>\n");\r
+                       buf.append("<hr/>\n");\r
                }\r
        }\r
 \r
@@ -175,8 +198,19 @@ class ResultPage {
                return path.getAsUniqueString().replace(path.getSeparator(), '_');\r
        }\r
 \r
-       private String describedPath(TreePath path, StructureRegistry registry) {\r
-               StringBuffer buf = new StringBuffer("");\r
-               return buf.toString();\r
+       private void describedPath(TreeSPath path, StructureRegistry registry,\r
+                       StringBuffer buf) {\r
+               // StringBuffer buf = new StringBuffer("");\r
+               if (path.getParent() != null) {\r
+                       describedPath(path.getParent(), registry, buf);\r
+               }\r
+               String description = path.getName();\r
+               if (registry != null) {\r
+                       StructureElement element = registry.getElement(path);\r
+                       if (element != null) {\r
+                               description = element.getDescription();\r
+                       }\r
+               }\r
+               buf.append('/').append(description);\r
        }\r
 }\r