+++ /dev/null
-package org.argeo.slc.core.test.tree.htmlreport;\r
-\r
-import java.io.File;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-import java.util.SortedSet;\r
-import java.util.TreeSet;\r
-\r
-import org.apache.commons.io.IOUtils;\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.StructureAware;\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.TestReport;\r
-import org.argeo.slc.core.test.TestResult;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
-import org.argeo.slc.dao.test.TestResultDao;\r
-\r
-/**\r
- * Basic implementation of TestReport generating static HTML pages. If a\r
- * <code>TestResultDao</code> is passed, all the data is dumped, otherwise\r
- * only the passed <code>TestResult</code>.\r
- */\r
-public class FullHtmlTreeReport implements TestReport, StructureAware {\r
- private static final Log log = LogFactory.getLog(FullHtmlTreeReport.class);\r
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");\r
-\r
- private TestResultDao testResultDao;\r
- private TreeSRegistryDao treeSRegistryDao;\r
- private File reportDir;\r
-\r
- private StructureRegistry localRegistry;\r
-\r
- public void generateTestReport(TestResult testResult) {\r
-\r
- if (testResultDao == null) {\r
- if (testResult == null)\r
- throw new SlcException(\r
- "Cannot generate report without DAO or result instance.");\r
-\r
- TreeTestResult result = (TreeTestResult) testResult;\r
- ResultPage page = new ResultPage(this, result);\r
- page.generate(getRegistry(result));\r
- } else {\r
- if (reportDir.exists()) {\r
- // clean\r
- for (File file : reportDir.listFiles()) {\r
- file.delete();\r
- }\r
- }\r
- reportDir.mkdirs();\r
-\r
- resourceToFile("index.html");\r
-\r
- ResultsList index = new ResultsList(this);\r
- List<TestResult> list = testResultDao.listTestResults();\r
- SortedSet<TestResult> sortedSet = new TreeSet<TestResult>(\r
- new Comparator<TestResult>() {\r
-\r
- public int compare(TestResult o1, TestResult o2) {\r
- if (o1.getCloseDate() == null\r
- || o2.getCloseDate() == null)\r
- return 0;\r
- // inverse date order (last first)\r
- return o2.getCloseDate().compareTo(\r
- o1.getCloseDate());\r
- }\r
-\r
- });\r
- sortedSet.addAll(list);\r
- for (TestResult testRes : sortedSet) {\r
- TreeTestResult result = (TreeTestResult) testRes;\r
-\r
- index.addTestResult(result);\r
- ResultPage page = new ResultPage(this, result);\r
- page.generate(getRegistry(result));\r
- }\r
- index.close();\r
- }\r
- log.info("Generated HTML test result report to " + reportDir);\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 + "slc-result-"\r
- + result.getUuid() + ".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 StructureRegistry getRegistry(TreeTestResult result) {\r
- StructureRegistry registry = null;\r
- if (treeSRegistryDao != null) {\r
- TreeSPath path = result.getResultParts().firstKey();\r
- registry = treeSRegistryDao.getActiveTreeSRegistry();\r
- }\r
- if (registry == null) {\r
- registry = localRegistry;\r
- }\r
- if (registry == null) {\r
- throw new SlcException("No structure registry available");\r
- }\r
- return registry;\r
- }\r
-\r
- public void notifyCurrentPath(StructureRegistry registry, StructurePath path) {\r
- this.localRegistry = registry;\r
- }\r
-\r
- File getReportDir() {\r
- return reportDir;\r
- }\r
-\r
- void addStyles(StringBuffer buf) {\r
- try {\r
- buf.append("<style type=\"text/css\">\n");\r
- InputStream in = FullHtmlTreeReport.class\r
- .getResourceAsStream("style.css");\r
- String styles = IOUtils.toString(in);\r
- IOUtils.closeQuietly(in);\r
- buf.append(styles);\r
- buf.append("\n</style>\n");\r
- } catch (IOException e) {\r
- throw new SlcException("Cannot load styles", e);\r
- }\r
- }\r
-\r
- private void resourceToFile(String resourceName) {\r
- try {\r
- File file = new File(getReportDir() + File.separator + resourceName);\r
- InputStream in = FullHtmlTreeReport.class\r
- .getResourceAsStream(resourceName);\r
- FileOutputStream out = new FileOutputStream(file);\r
- IOUtils.copy(in, out);\r
- IOUtils.closeQuietly(in);\r
- IOUtils.closeQuietly(out);\r
- } catch (Exception e) {\r
- throw new SlcException("Cannot load resource", e);\r
- }\r
-\r
- }\r
-\r
-}\r
+++ /dev/null
-package org.argeo.slc.core.test.tree.htmlreport;\r
-\r
-import java.io.IOException;\r
-import java.util.Date;\r
-import java.util.SortedMap;\r
-import java.util.TreeMap;\r
-\r
-import org.apache.commons.io.FileUtils;\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\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
- ResultPage(FullHtmlTreeReport report, TreeTestResult result) {\r
- this.report = report;\r
- this.result = result;\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 generate(StructureRegistry<TreeSPath> registry) {\r
- StringBuffer buf = new StringBuffer("");\r
- buf.append("<html>\n");\r
- buf.append("<header>");\r
- buf.append("<title>Result #").append(result.getUuid());\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.getUuid()).append("</h1>\n");\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
-\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
- private void generateToc(StringBuffer buf,\r
- StructureRegistry<TreeSPath> 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
- 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.getDepth();\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(element.getLabel());\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,\r
- StructureRegistry<TreeSPath> 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
- 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
- buf.append("Related Test Run Id:").append(\r
- sPart.getTestRunUuid()).append("<br/>\n");\r
- String clss = "";\r
- if (sPart.getStatus().equals(TestStatus.PASSED)) {\r
- clss = "passed";\r
- } else {\r
- clss = "failed";\r
- }\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
- if (sPart.getStatus().equals(TestStatus.ERROR)) {\r
- buf\r
- .append("<p><b>An unexpected error prevented the test to run properly.</b>");\r
- buf.append(sPart.getExceptionMessage());\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
- 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
- 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 void describedPath(TreeSPath path,\r
- StructureRegistry<TreeSPath> registry, 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.getLabel();\r
- }\r
- }\r
- buf.append('/').append(description);\r
- }\r
-}\r
+++ /dev/null
-package org.argeo.slc.core.test.tree.htmlreport;\r
-\r
-import java.io.File;\r
-import java.io.FileWriter;\r
-import java.io.IOException;\r
-import java.util.Date;\r
-\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-\r
-class ResultsList {\r
- private final FullHtmlTreeReport report;\r
- private final StringBuffer buf = new StringBuffer("");\r
-\r
- ResultsList(FullHtmlTreeReport report) {\r
- this.report = report;\r
-\r
- buf.append("<html><header><title>Results</title></header><body>");\r
- buf.append("<header>");\r
- buf.append("<title>Results</title>\n");\r
- report.addStyles(buf);\r
- buf.append("</header>\n");\r
- buf.append("<body>\n");\r
-\r
- buf.append("<h1>Results</h1>\n");\r
- buf.append("<table border=\"0\" cellspacing=\"1\">\n");\r
- buf.append("<tr><th>Date</th><th>Result Id</th></tr>\n");\r
- }\r
-\r
- void addTestResult(TreeTestResult result) {\r
- buf.append("<tr>\n");\r
- // Date\r
- buf.append("<td>");\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
- buf.append("</td>\n");\r
- // Id and link\r
- buf.append("<td><a class=\"nav\" href=\"");\r
- buf.append(report.getResultFile(result).getName());\r
- buf.append("\" target=\"main\">#");\r
- buf.append(result.getUuid()).append("</a></td>\n");\r
-\r
- buf.append("</tr>\n");\r
- }\r
-\r
- void close() {\r
- buf.append("</table>\n</body></html>");\r
-\r
- try {\r
- FileWriter writer = new FileWriter(report.getReportDir().getPath()\r
- + File.separator + "slc-resultsList.html");\r
- writer.write(buf.toString());\r
- writer.close();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- }\r
-\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-Static HTML report for tree based test results.\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-package org.argeo.slc.dao.structure;\r
-\r
-public interface SimpleSElementDao {\r
-\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-DAOs for the core structure objects.\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-package org.argeo.slc.dao.structure.tree;\r
-\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-\r
-public interface TreeSPathDao {\r
- public void create(TreeSPath path);\r
-\r
- public TreeSPath getTreeSPath(String pathString);\r
-\r
- public TreeSPath getOrCreate(TreeSPath pathTransient);\r
-}\r
+++ /dev/null
-package org.argeo.slc.dao.structure.tree;\r
-\r
-import org.argeo.slc.core.structure.StructureRegistry;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
-\r
-/**\r
- * DAO for tree-base structure registry.\r
- * \r
- * @see TreeSRegistry\r
- */\r
-public interface TreeSRegistryDao {\r
- /** Gets the TreeSRegistry which has the same root path as the provided path. */\r
- public TreeSRegistry getActiveTreeSRegistry();\r
-\r
- /** Creates a new registry. */\r
- public void create(TreeSRegistry registry);\r
-\r
- /** Updates an existing registry. */\r
- public void update(TreeSRegistry registry);\r
-\r
- /** Sync with local registry */\r
- public void syncPath(TreeSRegistry registry,\r
- StructureRegistry<TreeSPath> localRegistry, TreeSPath path);\r
-}\r
+++ /dev/null
-<html>\r
-<head></head>\r
-<body>\r
-DAOs for the tree-based structure objects.\r
-</body>\r
-</html>
\ No newline at end of file