1 package org
.argeo
.slc
.core
.test
.tree
.htmlreport
;
3 import java
.io
.IOException
;
5 import java
.util
.SortedMap
;
6 import java
.util
.TreeMap
;
8 import org
.apache
.commons
.io
.FileUtils
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.slc
.core
.structure
.StructureElement
;
12 import org
.argeo
.slc
.core
.structure
.StructureRegistry
;
13 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
14 import org
.argeo
.slc
.core
.test
.SimpleResultPart
;
15 import org
.argeo
.slc
.core
.test
.TestResultPart
;
16 import org
.argeo
.slc
.core
.test
.TestStatus
;
17 import org
.argeo
.slc
.core
.test
.tree
.PartSubList
;
18 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
21 private final static Log log
= LogFactory
.getLog(ResultPage
.class);
23 private final FullHtmlTreeReport report
;
24 private final TreeTestResult result
;
26 ResultPage(FullHtmlTreeReport report
, TreeTestResult result
) {
32 * Generates a result page for one test result
35 * file to which generate the HTML
39 protected void generate(StructureRegistry
<TreeSPath
> registry
) {
40 StringBuffer buf
= new StringBuffer("");
41 buf
.append("<html>\n");
42 buf
.append("<header>");
43 buf
.append("<title>Result #").append(result
.getUuid());
44 buf
.append("</title>\n");
45 report
.addStyles(buf
);
46 buf
.append("</header>\n");
48 buf
.append("<body>\n");
51 buf
.append("<a name=\"top\"/>\n");
52 buf
.append("<h1>Result #").append(result
.getUuid()).append("</h1>\n");
53 Date closeDate
= result
.getCloseDate();
54 if (closeDate
== null) {
55 buf
.append("[Not closed]");
57 buf
.append(report
.sdf
.format(closeDate
));
61 generateToc(buf
, registry
);
63 generatePartsList(buf
, registry
);
65 buf
.append("</body>");
66 buf
.append("</html>");
69 FileUtils
.writeStringToFile(report
.getResultFile(result
), buf
71 } catch (IOException e
) {
72 log
.error("Could not save result page.", e
);
76 private void generateToc(StringBuffer buf
,
77 StructureRegistry
<TreeSPath
> registry
) {
78 buf
.append("<h2>Overview</h2>\n");
79 SortedMap
<TreeSPath
, Integer
> toc
= new TreeMap
<TreeSPath
, Integer
>();
80 for (TreeSPath path
: result
.getResultParts().keySet()) {
81 PartSubList subList
= (PartSubList
) result
.getResultParts().get(
83 boolean isFailed
= false;
84 for (TestResultPart part
: subList
.getParts()) {
85 if (!part
.getStatus().equals(TestStatus
.PASSED
)) {
90 fillToc(toc
, path
, isFailed
);
93 buf
.append("<table border=\"0\">\n");
94 for (TreeSPath path
: toc
.keySet()) {
95 boolean inResult
= result
.getResultParts().containsKey(path
);
96 boolean isFailed
= !toc
.get(path
).equals(TestStatus
.PASSED
);
98 buf
.append("<tr><td class=\"").append(
99 isFailed ?
"failed" : "passed").append("\">");
100 int depth
= path
.getDepth();
101 for (int i
= 0; i
< depth
; i
++) {
102 buf
.append(" ");
106 buf
.append("<a href=\"#").append(anchor(path
)).append(
107 "\" class=\"").append(isFailed ?
"failed" : "passed")
110 if (registry
!= null) {
111 StructureElement element
= registry
.getElement(path
);
112 if (element
!= null) {
113 buf
.append(element
.getLabel());
115 buf
.append(path
.getName());
119 buf
.append("</b></a>");
121 buf
.append("</td></tr>\n");
123 buf
.append("</table>\n");
124 buf
.append("<hr/>\n");
127 private void generatePartsList(StringBuffer buf
,
128 StructureRegistry
<TreeSPath
> registry
) {
129 for (TreeSPath path
: result
.getResultParts().keySet()) {
131 buf
.append("<a name=\"").append(anchor(path
)).append("\"></a>");
133 describedPath(path
, registry
, buf
);
136 PartSubList subList
= (PartSubList
) result
.getResultParts().get(
138 buf
.append("<table border=0>\n");
139 int displayedIndex
= 1;// for display only
140 for (TestResultPart part
: subList
.getParts()) {
141 SimpleResultPart sPart
= (SimpleResultPart
) part
;
142 buf
.append("Related Test Run Id:").append(
143 sPart
.getTestRunUuid()).append("<br/>\n");
145 if (sPart
.getStatus().equals(TestStatus
.PASSED
)) {
151 buf
.append("<td><b>").append(displayedIndex
)
152 .append("</b></td>");
153 buf
.append("<td class=\"").append(clss
).append("\">");
155 buf
.append(sPart
.getMessage());
156 if (sPart
.getStatus().equals(TestStatus
.ERROR
)) {
158 .append("<p><b>An unexpected error prevented the test to run properly.</b>");
159 buf
.append(sPart
.getExceptionMessage());
163 buf
.append("</tr>\n");
167 buf
.append("</table>\n");
168 buf
.append("<a class=\"nav\" href=\"#top\">top</a>\n");
169 buf
.append("<hr/>\n");
173 private void fillToc(SortedMap
<TreeSPath
, Integer
> toc
, TreeSPath path
,
176 toc
.put(path
, TestStatus
.FAILED
);
178 if (!toc
.containsKey(path
)) {
179 toc
.put(path
, TestStatus
.PASSED
);
183 if (path
.getParent() != null) {
184 fillToc(toc
, path
.getParent(), isFailed
);
188 private String
anchor(TreeSPath path
) {
189 return path
.getAsUniqueString().replace(path
.getSeparator(), '_');
192 private void describedPath(TreeSPath path
,
193 StructureRegistry
<TreeSPath
> registry
, StringBuffer buf
) {
194 // StringBuffer buf = new StringBuffer("");
195 if (path
.getParent() != null) {
196 describedPath(path
.getParent(), registry
, buf
);
198 String description
= path
.getName();
199 if (registry
!= null) {
200 StructureElement element
= registry
.getElement(path
);
201 if (element
!= null) {
202 description
= element
.getLabel();
205 buf
.append('/').append(description
);