This project has retired. For details please refer to its
Attic page.
CoreHtmlReport xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.tck.report;
20
21 import java.io.IOException;
22 import java.io.PrintWriter;
23 import java.io.StringWriter;
24 import java.io.Writer;
25 import java.util.Date;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.TreeMap;
29
30 import org.apache.chemistry.opencmis.commons.SessionParameter;
31 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
32 import org.apache.chemistry.opencmis.tck.CmisTest;
33 import org.apache.chemistry.opencmis.tck.CmisTestGroup;
34 import org.apache.chemistry.opencmis.tck.CmisTestResult;
35 import org.apache.chemistry.opencmis.tck.CmisTestResultStatus;
36
37
38
39
40 public class CoreHtmlReport extends AbstractCmisTestReport {
41 public CoreHtmlReport() {
42 }
43
44 @Override
45 public void createReport(Map<String, String> parameters, List<CmisTestGroup> groups, Writer writer)
46 throws IOException {
47 writer.write("<h1>OpenCMIS TCK Report</h1>\n");
48 writer.write((new Date()) + "\n");
49
50 writer.write("\n<h2>Parameters</h2>\n");
51
52 if (parameters != null) {
53 writer.write("<table>\n");
54 for (Map.Entry<String, String> p : (new TreeMap<String, String>(parameters)).entrySet()) {
55 String value = p.getValue();
56 if (SessionParameter.PASSWORD.endsWith(p.getKey())) {
57 value = "*****";
58 }
59
60 writer.write("<tr><td>" + escape(p.getKey()) + "</td><td>" + escape(value) + "</td></tr>\n");
61 }
62 writer.write("</table>\n");
63 }
64
65 writer.write("\n<h2>Groups</h2>\n");
66
67 if (groups != null) {
68 for (CmisTestGroup group : groups) {
69 printGroupResults(group, writer);
70 }
71 }
72
73 writer.flush();
74 }
75
76 public static void printStyle(Writer writer) throws IOException {
77 writer.write("<style TYPE=\"text/css\">\n");
78 writer.write(".tckResultINFO { margin-left: 5px; margin-right: 5px; }\n");
79 writer.write(".tckResultSKIPPED { margin-left: 5px; margin-right: 5px; background-color: #FFFFFF; }\n");
80 writer.write(".tckResultOK { margin-left: 5px; margin-right: 5px; background-color: #00FF00; }\n");
81 writer.write(".tckResultWARNING { margin-left: 5px; margin-right: 5px; background-color: #FFFF00; }\n");
82 writer.write(".tckResultFAILURE { margin-left: 5px; margin-right: 5px; background-color: #FF6000; }\n");
83 writer.write(".tckResultUNEXPECTED_EXCEPTION { margin-left: 5px; margin-right: 5px; background-color: #FF0000; }\n");
84 writer.write("</style>");
85 }
86
87 private void printGroupResults(CmisTestGroup group, Writer writer) throws IOException {
88 if (!group.isEnabled()) {
89 return;
90 }
91
92 writer.write("\n<hr>\n<h3>" + escape(group.getName()) + "</h3>\n");
93
94 if (group.getDescription() != null) {
95 writer.write("\n<p><i>" + escape(group.getDescription()) + "</i></p>\n");
96 }
97
98 if (group.getTests() != null) {
99 for (CmisTest test : group.getTests()) {
100 printTestResults(test, writer);
101 }
102 }
103 }
104
105 private void printTestResults(CmisTest test, Writer writer) throws IOException {
106 if (!test.isEnabled()) {
107 return;
108 }
109
110 writer.write("\n<h4>" + escape(test.getName()) + " (" + test.getTime() + " ms)</h4>\n");
111
112 if (test.getDescription() != null) {
113 writer.write("\n<p><i>" + escape(test.getDescription()) + "</i></p>\n");
114 }
115
116 if (test.getResults() != null) {
117 for (CmisTestResult result : test.getResults()) {
118 writer.write("<div style=\"padding: 5px;\">\n");
119 printResult(result, writer);
120 writer.write("</div>\n");
121 }
122 }
123 }
124
125 private void printResult(CmisTestResult result, Writer writer) throws IOException {
126 writer.write("<div class=\"tckResult" + result.getStatus().name() + "\">\n");
127
128 writer.write("<b>" + result.getStatus() + "</b>: " + escape(result.getMessage()));
129
130 if ((result.getStackTrace() != null) && (result.getStackTrace().length > 0)) {
131 writer.write(" (" + escape(result.getStackTrace()[0].getFileName()) + ":"
132 + result.getStackTrace()[0].getLineNumber() + ")");
133 }
134
135 writer.write("<br/>\n");
136
137 if (result.getStatus() == CmisTestResultStatus.UNEXPECTED_EXCEPTION && result.getException() != null) {
138 final Writer sw = new StringWriter();
139 final PrintWriter pw = new PrintWriter(sw);
140 result.getException().printStackTrace(pw);
141
142 writer.write("\n<!--\nStacktrace:\n\n" + escape(sw.toString()) + "-->\n");
143
144 if (result.getException() instanceof CmisBaseException) {
145 CmisBaseException cbe = (CmisBaseException) result.getException();
146 if (cbe.getErrorContent() != null) {
147 writer.write("\n<!--\nError Content:\n\n" + escape(cbe.getErrorContent()) + "-->\n");
148 }
149 }
150 }
151
152 for (CmisTestResult child : result.getChildren()) {
153 printResult(child, writer);
154 }
155
156 writer.write("</div>\n");
157 }
158
159 protected String escape(String s) {
160 if (s == null) {
161 return "";
162 }
163
164 StringBuilder sb = new StringBuilder();
165
166 for (int i = 0; i < s.length(); i++) {
167 char c = s.charAt(i);
168 switch (c) {
169 case '\"':
170 sb.append(""");
171 break;
172 case '&':
173 sb.append("&");
174 break;
175 case '<':
176 sb.append("<");
177 break;
178 case '>':
179 sb.append("<");
180 break;
181 default:
182 sb.append(c);
183 }
184 }
185
186 return sb.toString();
187 }
188 }