\r
TreeSPath path = treeSPathDao.getOrCreate(partStruct.path);\r
\r
+ StructureRegistry localRegistry = partStruct.result.getRegistry();\r
TreeSRegistry registry = getOrCreateTreeSRegistry(path);\r
- if (registry.getElement(path) == null) {\r
- StructureRegistry localRegistry = partStruct.result\r
- .getRegistry();\r
- if (localRegistry != null) {\r
- registry.register(path, localRegistry.getElement(path));\r
- } else {\r
- registry.register(path, new SimpleSElement(path.getName()));\r
- }\r
- treeSRegistryDao.update(registry);\r
- }\r
+ syncPath(registry, localRegistry, path);\r
+ treeSRegistryDao.update(registry);\r
\r
if (persistedResult == null) {\r
persistedResult = new TreeTestResult();\r
this.treeSRegistryDao = treeSRegistryDao;\r
}\r
\r
+ private void syncPath(TreeSRegistry registry,\r
+ StructureRegistry localRegistry, TreeSPath path) {\r
+ if (registry.getElement(path) == null) {\r
+ if (localRegistry != null) {\r
+ registry.register(path, localRegistry.getElement(path));\r
+ } else {\r
+ registry.register(path, new SimpleSElement(path.getName()));\r
+ }\r
+ }\r
+\r
+ if (path.getParent() != null) {\r
+ TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
+ syncPath(registry, localRegistry, parent);\r
+ }\r
+ }\r
}\r
package org.argeo.slc.core.test.tree.htmlreport;\r
\r
-import java.io.FileWriter;\r
import java.io.IOException;\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.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
\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.SimpleResultPart;\r
import org.argeo.slc.core.test.TestResultPart;\r
+import org.argeo.slc.core.test.TestStatus;\r
import org.argeo.slc.core.test.tree.PartSubList;\r
import org.argeo.slc.core.test.tree.TreeTestResult;\r
\r
class ResultPage {\r
+ private final static Log log = LogFactory.getLog(ResultPage.class);\r
+\r
private final FullHtmlTreeReport report;\r
private final TreeTestResult result;\r
\r
\r
buf.append("<body>\n");\r
\r
+ // Header\r
buf.append("<h1>Result #").append(result.getTestResultId()).append(\r
"</h1>\n");\r
+ buf.append(report.sdf.format(result.getCloseDate()));\r
+\r
+ // TOC\r
+ generateToc(buf, registry);\r
+\r
+ generatePartsList(buf, registry);\r
+\r
+ buf.append("</body>");\r
+ buf.append("</html>");\r
+\r
+ try {\r
+ FileUtils.writeStringToFile(report.getResultFile(result), buf\r
+ .toString());\r
+ } catch (IOException e) {\r
+ log.error("Could not save result page.", e);\r
+ }\r
+ }\r
\r
- buf.append("<table border=1>\n");\r
+ private void generateToc(StringBuffer buf, StructureRegistry registry) {\r
+ buf.append("<h2>Overview</h2>\n");\r
+ SortedMap<TreeSPath, Integer> toc = new TreeMap<TreeSPath, Integer>();\r
for (TreeSPath path : result.getResultParts().keySet()) {\r
- buf.append("<tr><td>");\r
- buf.append(path);\r
+ PartSubList subList = (PartSubList) result.getResultParts().get(\r
+ path);\r
+ boolean isFailed = false;\r
+ for (TestResultPart part : subList.getParts()) {\r
+ if (!part.getStatus().equals(TestStatus.PASSED)) {\r
+ isFailed = true;\r
+ break;\r
+ }\r
+ }\r
+ fillToc(toc, path, isFailed);\r
+ }\r
+\r
+ buf.append("<table border=\"0\">\n");\r
+ for (TreeSPath path : toc.keySet()) {\r
+ boolean inResult = result.getResultParts().containsKey(path);\r
+ boolean isFailed = !toc.get(path).equals(TestStatus.PASSED);\r
+\r
+ buf.append("<tr><td class=\"").append(\r
+ isFailed ? "failed" : "passed").append("\">");\r
+ int depth = path.depth();\r
+ for (int i = 0; i < depth; i++) {\r
+ buf.append(" ");\r
+ }\r
+\r
+ if (inResult) {\r
+ buf.append("<a href=\"#").append(anchor(path)).append(\r
+ "\" class=\"").append(isFailed ? "failed" : "passed")\r
+ .append("\"><b>");\r
+ }\r
if (registry != null) {\r
StructureElement element = registry.getElement(path);\r
if (element != null) {\r
- buf.append("<br/><b>");\r
buf.append(element.getDescription());\r
- buf.append("</b>");\r
+ } else {\r
+ buf.append(path.getName());\r
+ }\r
+ }\r
+ if (inResult) {\r
+ buf.append("</b></a>");\r
+ }\r
+ buf.append("</td></tr>\n");\r
+ }\r
+ buf.append("</table>\n");\r
+ buf.append("<hr/>\n");\r
+ }\r
+\r
+ private void generatePartsList(StringBuffer buf, StructureRegistry registry) {\r
+ for (TreeSPath path : result.getResultParts().keySet()) {\r
+ 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("</td>\n");\r
- buf.append("<td>");\r
+ buf.append(description);\r
+ buf.append("</h2>");\r
+\r
PartSubList subList = (PartSubList) result.getResultParts().get(\r
path);\r
buf.append("<table border=0>\n");\r
for (TestResultPart part : subList.getParts()) {\r
SimpleResultPart sPart = (SimpleResultPart) part;\r
- String color = "yellow";\r
+ String clss = "";\r
if (sPart.getStatus().equals(SimpleResultPart.PASSED)) {\r
- color = "green";\r
+ clss = "passed";\r
} else {\r
- color = "red";\r
+ clss = "failed";\r
}\r
- buf.append("<tr><td style=\"color:").append(color)\r
- .append("\">");\r
+ buf.append("<tr><td class=\"").append(clss).append("\">");\r
\r
buf.append(sPart.getMessage());\r
buf.append("</td></tr>\n");\r
}\r
buf.append("</table>\n");\r
-\r
- buf.append("</td></tr>\n");\r
}\r
- buf.append("</table>\n");\r
+ }\r
\r
- buf.append("</body>");\r
- buf.append("</html>");\r
+ private void fillToc(SortedMap<TreeSPath, Integer> toc, TreeSPath path,\r
+ boolean isFailed) {\r
+ if (isFailed) {\r
+ toc.put(path, TestStatus.FAILED);\r
+ } else {\r
+ if (!toc.containsKey(path)) {\r
+ toc.put(path, TestStatus.PASSED);\r
+ }\r
+ }\r
\r
- try {\r
- FileWriter writer = new FileWriter(report.getResultFile(result));\r
- writer.write(buf.toString());\r
- writer.close();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
+ if (path.getParent() != null) {\r
+ fillToc(toc, path.getParent(), isFailed);\r
}\r
}\r
\r
+ private String anchor(TreeSPath path) {\r
+ 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
+ }\r
}\r