1 package org
.argeo
.slc
.core
.test
.tree
;
4 import java
.io
.FileWriter
;
5 import java
.io
.IOException
;
8 import org
.argeo
.slc
.core
.structure
.StructureAware
;
9 import org
.argeo
.slc
.core
.structure
.StructureElement
;
10 import org
.argeo
.slc
.core
.structure
.StructurePath
;
11 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
12 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
13 import org
.argeo
.slc
.core
.test
.SimpleResultPart
;
14 import org
.argeo
.slc
.core
.test
.TestReport
;
15 import org
.argeo
.slc
.core
.test
.TestResult
;
16 import org
.argeo
.slc
.core
.test
.TestResultPart
;
17 import org
.argeo
.slc
.dao
.test
.TestResultDao
;
19 public class FullHtmlTreeReport
implements TestReport
, StructureAware
{
20 private TestResultDao testResultDao
;
21 private File reportDir
;
23 private StructureRegistry registry
;
25 public void generateTestReport(TestResult testResult
) {
26 if (testResultDao
== null) {
27 TreeTestResult result
= (TreeTestResult
) testResult
;
28 generateResultPage(getResultFile(result
), result
);
30 if (reportDir
.exists()) {
32 for (File file
: reportDir
.listFiles()) {
38 StringBuffer index
= new StringBuffer("");
40 .append("<html><header><title>Results</title></header><body>\n<table border=1>\n");
42 List
<TestResult
> list
= testResultDao
.listTestResults();
43 for (TestResult testRes
: list
) {
44 TreeTestResult res
= (TreeTestResult
) testRes
;
46 File file
= getResultFile(res
);
47 index
.append("<tr><td><a href=\"").append(file
.getName())
49 index
.append(res
.getTestResultId()).append("</a></td></tr>\n");
50 generateResultPage(file
, res
);
53 index
.append("</table>\n</body></html>");
56 FileWriter writer
= new FileWriter(reportDir
.getPath()
57 + File
.separator
+ "index.html");
58 writer
.write(index
.toString());
60 } catch (IOException e
) {
67 protected void generateResultPage(File file
, TreeTestResult result
) {
68 StringBuffer buf
= new StringBuffer("");
69 buf
.append("<html>\n");
70 buf
.append("<header><title>Result #").append(result
.getTestResultId())
71 .append("</title></header>\n");
73 buf
.append("<body>\n");
75 buf
.append("<h1>Result #").append(result
.getTestResultId()).append(
78 buf
.append("<table border=1>\n");
79 for (TreeSPath path
: result
.getResultParts().keySet()) {
80 buf
.append("<tr><td>");
82 StructureElement element
= registry
.getElement(path
);
83 if (registry
!= null) {
84 if (element
!= null) {
85 buf
.append("<br/><b>");
86 buf
.append(element
.getDescription());
90 buf
.append("</td>\n");
92 PartSubList subList
= (PartSubList
) result
.getResultParts().get(
94 buf
.append("<table border=0>\n");
95 for (TestResultPart part
: subList
.getParts()) {
96 SimpleResultPart sPart
= (SimpleResultPart
) part
;
97 String color
= "yellow";
98 if (sPart
.getStatus() == SimpleResultPart
.PASSED
) {
103 buf
.append("<tr><td style=\"color:").append(color
)
106 buf
.append(sPart
.getMessage());
107 buf
.append("</td></tr>\n");
109 buf
.append("</table>\n");
111 buf
.append("</td></tr>\n");
113 buf
.append("</table>\n");
115 buf
.append("</body>");
116 buf
.append("</html>");
119 FileWriter writer
= new FileWriter(file
);
120 writer
.write(buf
.toString());
122 } catch (IOException e
) {
127 protected File
getResultFile(TreeTestResult result
) {
128 return new File(reportDir
.getPath() + File
.separator
129 + result
.getTestResultId() + ".html");
132 public void setTestResultDao(TestResultDao testResultDao
) {
133 this.testResultDao
= testResultDao
;
136 public void setReportDir(File reportDir
) {
137 this.reportDir
= reportDir
;
140 public void notifyCurrentPath(StructureRegistry registry
, StructurePath path
) {
141 this.registry
= registry
;