1 package com.github.jlgrock.javascriptframework.closuretestingreport;
2
3 import java.util.Set;
4
5 import org.apache.log4j.Logger;
6 import org.apache.maven.doxia.sink.Sink;
7 import org.apache.maven.reporting.AbstractMavenReportRenderer;
8
9 import com.github.jlgrock.javascriptframework.closuretesting.resultparsing.testingcomponents.TestCase;
10
11
12
13
14
15 public class ClosureTestingReportGenerator extends AbstractMavenReportRenderer {
16
17
18
19 static final int UPPERCASE_ASCII_LOWER_BOUND = 65;
20
21
22
23 static final int UPPERCASE_ASCII_UPPER_BOUND = 90;
24
25
26
27 static final int LOWERCASE_ASCII_LOWER_BOUND = 97;
28
29
30
31 static final int LOWERCASE_ASCII_UPPER_BOUND = 122;
32
33
34
35
36 private static final Logger LOGGER = Logger
37 .getLogger(ClosureTestingReportGenerator.class);
38
39
40
41
42 private final Set<TestCase> testCases;
43
44
45
46
47
48
49
50
51
52 public ClosureTestingReportGenerator(final Sink sink,
53 final Set<TestCase> testCasesIn) {
54 super(sink);
55 this.testCases = testCasesIn;
56 }
57
58 @Override
59 public final String getTitle() {
60 return "Google Closure Unit Testing";
61 }
62
63 @Override
64 protected final void renderBody() {
65
66 sink.body();
67
68
69 summarySection(sink);
70
71
72 linkSection(sink);
73
74
75 rawDumpSection(sink);
76
77 sink.body_();
78 sink.flush();
79 sink.close();
80 }
81
82
83
84
85
86
87
88 private void rawDumpSection(final Sink sink) {
89 sink.horizontalRule();
90 sink.lineBreak();
91 sink.section2();
92 sink.sectionTitle2();
93 sink.text("Closure Unit Testing Raw Dump");
94 sink.sectionTitle2_();
95 makeRawDump(sink);
96 sink.section2_();
97 }
98
99
100
101
102
103
104
105 private void linkSection(final Sink sink) {
106 sink.section2();
107 sink.lineBreak();
108 sink.sectionTitle2();
109 sink.text("Files");
110 sink.sectionTitle2_();
111 makeLinks(sink);
112 sink.section2_();
113 }
114
115
116
117
118
119
120
121 private void summarySection(final Sink sink) {
122 sink.section1();
123 sink.sectionTitle1();
124 sink.text("Google Closure Unit Testing");
125 sink.sectionTitle1_();
126
127 sink.text("List of executed Google Closure Library Unit Test results.");
128 sink.section1_();
129 }
130
131
132
133
134
135
136
137 private void makeRawDump(final Sink sink) {
138 for (TestCase testCase : testCases) {
139 LOGGER.debug("doing raw dump for test case: "
140 + testCase.getSummary().getRelativeLocation());
141 sink.paragraph();
142 sink.bold();
143 String pathAnchor = encodeAnchor(testCase.getSummary()
144 .getRelativeLocation());
145 sink.anchor(pathAnchor);
146 sink.text(testCase.getSummary().getRelativeLocation());
147 sink.anchor_();
148 sink.bold_();
149 sink.lineBreak();
150 sink.lineBreak();
151 for (String div : testCase.getRawDivs()) {
152 sink.text(div);
153 }
154 sink.paragraph_();
155 sink.horizontalRule();
156 }
157 }
158
159
160
161
162
163
164
165
166
167 private String encodeAnchor(final String relativeLocation) {
168 StringBuffer calcString = new StringBuffer();
169 calcString.append("fileref");
170 for (int i = 0; i < relativeLocation.length(); i++) {
171 int asciiVal = (int) relativeLocation.charAt(i);
172 if ((asciiVal >= UPPERCASE_ASCII_LOWER_BOUND && asciiVal <= UPPERCASE_ASCII_UPPER_BOUND)
173 || (asciiVal >= LOWERCASE_ASCII_LOWER_BOUND && asciiVal <= LOWERCASE_ASCII_UPPER_BOUND)) {
174 calcString.append((char) asciiVal);
175 } else {
176 calcString.append(Integer.toHexString(asciiVal));
177 }
178 }
179
180 return calcString.toString();
181 }
182
183
184
185
186
187
188
189 private void makeLinks(final Sink sink) {
190 sink.table();
191
192 sink.tableRow();
193 sink.tableHeaderCell();
194 sink.text("Relative Filename");
195 sink.tableHeaderCell_();
196
197 sink.tableHeaderCell();
198 sink.text("Number Passed");
199 sink.tableHeaderCell_();
200
201 sink.tableHeaderCell();
202 sink.text("Number Failed");
203 sink.tableHeaderCell_();
204
205 sink.tableRow_();
206 for (TestCase testCase : testCases) {
207
208 createRow(testCase, sink);
209 }
210 sink.table_();
211 }
212
213
214
215
216
217
218
219
220
221 private void createRow(final TestCase testCase, final Sink sink) {
222
223 sink.tableRow();
224
225 sink.tableCell();
226
227
228 sink.link("#"
229 + encodeAnchor(testCase.getSummary().getRelativeLocation()));
230 sink.text(testCase.getSummary().getRelativeLocation());
231 sink.link_();
232 sink.tableCell_();
233
234
235 sink.tableCell();
236 sink.text(String.valueOf(testCase.getFailureStatistic().getNumPassed()));
237 sink.link_();
238 sink.tableCell_();
239
240
241 sink.tableCell();
242 sink.text(String.valueOf(testCase.getFailureStatistic().getNumFailed()));
243 sink.link_();
244 sink.tableCell_();
245
246 sink.tableRow_();
247 }
248 }