1 package org.apache.maven.plugins.surefire.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.UnsupportedEncodingException;
25 import java.io.Writer;
26 import java.net.URL;
27 import java.net.URLDecoder;
28 import java.util.Locale;
29
30 import org.apache.maven.doxia.site.decoration.DecorationModel;
31 import org.apache.maven.doxia.siterenderer.Renderer;
32 import org.apache.maven.doxia.siterenderer.RendererException;
33 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
34 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
35 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
36 import org.apache.maven.shared.utils.WriterFactory;
37 import org.apache.maven.shared.utils.io.FileUtils;
38 import org.apache.maven.shared.utils.io.IOUtil;
39
40 import static org.hamcrest.MatcherAssert.assertThat;
41 import static org.hamcrest.CoreMatchers.containsString;
42 import static org.apache.maven.plugins.surefire.report.Utils.toSystemNewLine;
43
44
45
46
47 public class SurefireReportMojoTest
48 extends AbstractMojoTestCase
49 {
50 private Renderer renderer;
51
52 @Override
53 protected void setUp()
54 throws Exception
55 {
56 super.setUp();
57 renderer = (Renderer) lookup( Renderer.ROLE );
58 }
59
60 public void testBasicSurefireReport()
61 throws Exception
62 {
63 File testPom = new File( getUnitBaseDir(), "basic-surefire-report-test/plugin-config.xml" );
64
65 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
66
67 assertNotNull( mojo );
68
69 File outputDir = (File) getVariableValueFromObject( mojo, "outputDirectory" );
70
71 boolean showSuccess = (Boolean) getVariableValueFromObject( mojo, "showSuccess" );
72
73 File reportsDir = (File) getVariableValueFromObject( mojo, "reportsDirectory" );
74
75 String outputName = (String) getVariableValueFromObject( mojo, "outputName" );
76
77 File xrefLocation = (File) getVariableValueFromObject( mojo, "xrefLocation" );
78
79 boolean linkXRef = (Boolean) getVariableValueFromObject( mojo, "linkXRef" );
80
81 assertEquals( new File( getBasedir() + "/target/site/unit/basic-surefire-report-test" ), outputDir );
82
83 assertTrue( showSuccess );
84
85 assertEquals( new File(
86 getBasedir() + "/src/test/resources/unit/basic-surefire-report-test/surefire-reports" ).getAbsolutePath(),
87 reportsDir.getAbsolutePath() );
88
89 assertEquals( "surefire-report", outputName );
90 assertEquals(
91 new File( getBasedir() + "/target/site/unit/basic-surefire-report-test/xref-test" ).getAbsolutePath(),
92 xrefLocation.getAbsolutePath() );
93
94 assertTrue( linkXRef );
95
96 mojo.execute();
97
98 File report = new File( getBasedir(), "target/site/unit/basic-surefire-report-test/surefire-report.html" );
99
100 renderer( mojo, report );
101
102 assertTrue( report.exists() );
103
104 String htmlContent = FileUtils.fileRead( report );
105
106 int idx = htmlContent.indexOf( "images/icon_success_sml.gif" );
107
108 assertTrue( idx >= 0 );
109 }
110
111 private File getUnitBaseDir()
112 throws UnsupportedEncodingException
113 {
114 URL resource = getClass().getResource( "/unit" );
115
116 return new File( URLDecoder.decode( resource.getPath(), "UTF-8" ) ).getAbsoluteFile();
117 }
118
119 public void testBasicSurefireReportIfShowSuccessIsFalse()
120 throws Exception
121 {
122 File testPom = new File( getUnitBaseDir(), "basic-surefire-report-success-false/plugin-config.xml" );
123
124 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
125
126 assertNotNull( mojo );
127
128 boolean showSuccess = (Boolean) getVariableValueFromObject( mojo, "showSuccess" );
129
130 assertFalse( showSuccess );
131
132 mojo.execute();
133
134 File report =
135 new File( getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire-report.html" );
136
137 renderer( mojo, report );
138
139 assertTrue( report.exists() );
140
141 String htmlContent = FileUtils.fileRead( report );
142
143 int idx = htmlContent.indexOf( "images/icon_success_sml.gif" );
144
145 assertTrue( idx < 0 );
146 }
147
148 public void testBasicSurefireReportIfLinkXrefIsFalse()
149 throws Exception
150 {
151 File testPom = new File( getUnitBaseDir(), "basic-surefire-report-linkxref-false/plugin-config.xml" );
152
153 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
154
155 assertNotNull( mojo );
156
157 boolean linkXRef = (Boolean) getVariableValueFromObject( mojo, "linkXRef" );
158
159 assertFalse( linkXRef );
160
161 mojo.execute();
162
163 File report =
164 new File( getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire-report.html" );
165
166 renderer( mojo, report );
167
168 assertTrue( report.exists() );
169
170 String htmlContent = FileUtils.fileRead( report );
171
172 int idx = htmlContent.indexOf( "./xref-test/com/shape/CircleTest.html#44" );
173
174 assertTrue( idx == -1 );
175 }
176
177 public void testBasicSurefireReportIfReportingIsNull()
178 throws Exception
179 {
180 File testPom = new File( getUnitBaseDir(), "basic-surefire-report-reporting-null/plugin-config.xml" );
181
182 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
183
184 assertNotNull( mojo );
185
186 mojo.execute();
187
188 File report =
189 new File( getBasedir(), "target/site/unit/basic-surefire-report-reporting-null/surefire-report.html" );
190
191 renderer( mojo, report );
192
193 assertTrue( report.exists() );
194
195 String htmlContent = FileUtils.fileRead( report );
196
197 int idx = htmlContent.indexOf( "./xref-test/com/shape/CircleTest.html#44" );
198
199 assertTrue( idx < 0 );
200 }
201
202 public void testBasicSurefireReport_AnchorTestCases()
203 throws Exception
204 {
205 File testPom = new File( getUnitBaseDir(), "basic-surefire-report-anchor-test-cases/plugin-config.xml" );
206
207 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
208
209 assertNotNull( mojo );
210
211 mojo.execute();
212
213 File report = new File( getBasedir(),
214 "target/site/unit/basic-surefire-report-anchor-test-cases/surefire-report.html" );
215
216 renderer( mojo, report );
217
218 assertTrue( report.exists() );
219
220 String htmlContent = FileUtils.fileRead( report );
221
222 int idx = htmlContent.indexOf( "<td><a name=\"TC_com.shape.CircleTest.testX\"></a>testX</td>" );
223 assertTrue( idx > 0 );
224
225 idx = htmlContent.indexOf( "<td><a name=\"TC_com.shape.CircleTest.testRadius\"></a>"
226 + "<a href=\"#com.shape.CircleTest.testRadius\">testRadius</a>" );
227 assertTrue( idx > 0 );
228 }
229
230 public void testSurefireReportSingleError()
231 throws Exception
232 {
233 File testPom = new File( getUnitBaseDir(), "surefire-report-single-error/plugin-config.xml" );
234 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
235 assertNotNull( mojo );
236 mojo.execute();
237 File report = new File( getBasedir(), "target/site/unit/surefire-report-single-error/surefire-report.html" );
238 renderer( mojo, report );
239 assertTrue( report.exists() );
240 String htmlContent = FileUtils.fileRead( report );
241
242 assertThat( htmlContent,
243 containsString( toSystemNewLine( "<tr class=\"b\">\n"
244 + "<td>1</td>\n"
245 + "<td>1</td>\n"
246 + "<td>0</td>\n"
247 + "<td>0</td>\n"
248 + "<td>0%</td>\n"
249 + "<td>0</td>" ) ) );
250
251 assertThat( htmlContent,
252 containsString( toSystemNewLine( "<tr class=\"b\">\n"
253 + "<td><a href=\"#surefire\">surefire</a></td>\n"
254 + "<td>1</td>\n"
255 + "<td>1</td>\n"
256 + "<td>0</td>\n"
257 + "<td>0</td>\n"
258 + "<td>0%</td>\n"
259 + "<td>0</td></tr>" ) ) );
260 assertThat( htmlContent,
261 containsString( toSystemNewLine( "<tr class=\"b\">\n"
262 + "<td>"
263 + "<a href=\"#surefire.MyTest\">"
264 + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
265 + "</a>"
266 + "</td>\n"
267 + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
268 + "<td>1</td>\n"
269 + "<td>1</td>\n"
270 + "<td>0</td>\n"
271 + "<td>0</td>\n"
272 + "<td>0%</td>\n"
273 + "<td>0</td></tr>" ) ) );
274
275 assertThat( htmlContent, containsString( ">surefire.MyTest:13</a>" ) );
276
277 assertThat( htmlContent, containsString( "./xref-test/surefire/MyTest.html#13" ) );
278
279 assertThat( htmlContent, containsString( toSystemNewLine( "<pre>"
280 + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
281 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
282 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
283 + "\tat surefire.MyTest.test(MyTest.java:13)\n"
284 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
285 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
286 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
287 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
288 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
289 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
290 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
291 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
292 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
293 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
294 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
295 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
296 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
297 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
298 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
299 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
300 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
301 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
302 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
303 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
304 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
305 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
306 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
307 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
308 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
309 + "\tat surefire.MyTest.failure(MyTest.java:33)\n" + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
310 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
311 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
312 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" + "</pre>" ) ) );
313 }
314
315 public void testSurefireReportNestedClassTrimStackTrace()
316 throws Exception
317 {
318 File testPom = new File( getUnitBaseDir(), "surefire-report-nestedClass-trimStackTrace/plugin-config.xml" );
319 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
320 assertNotNull( mojo );
321 mojo.execute();
322 File report = new File( getBasedir(), "target/site/unit/surefire-report-nestedClass-trimStackTrace/surefire-report.html" );
323 renderer( mojo, report );
324 assertTrue( report.exists() );
325 String htmlContent = FileUtils.fileRead( report );
326
327 assertThat( htmlContent,
328 containsString( toSystemNewLine( "<tr class=\"b\">\n"
329 + "<td>1</td>\n"
330 + "<td>1</td>\n"
331 + "<td>0</td>\n"
332 + "<td>0</td>\n"
333 + "<td>0%</td>\n"
334 + "<td>0</td>" ) ) );
335
336 assertThat( htmlContent,
337 containsString( toSystemNewLine( "<tr class=\"b\">\n"
338 + "<td><a href=\"#surefire\">surefire</a></td>\n"
339 + "<td>1</td>\n"
340 + "<td>1</td>\n"
341 + "<td>0</td>\n"
342 + "<td>0</td>\n"
343 + "<td>0%</td>\n"
344 + "<td>0</td></tr>" ) ) );
345 assertThat( htmlContent,
346 containsString( toSystemNewLine( "<tr class=\"b\">\n"
347 + "<td>"
348 + "<a href=\"#surefire.MyTest\">"
349 + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
350 + "</a>"
351 + "</td>\n"
352 + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
353 + "<td>1</td>\n"
354 + "<td>1</td>\n"
355 + "<td>0</td>\n"
356 + "<td>0</td>\n"
357 + "<td>0%</td>\n"
358 + "<td>0</td></tr>" ) ) );
359 assertThat( htmlContent,
360 containsString( ">surefire.MyTest:13</a>" ) );
361
362 assertThat( htmlContent, containsString( "./xref-test/surefire/MyTest.html#13" ) );
363
364 assertThat( htmlContent, containsString( toSystemNewLine( "<pre>"
365 + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
366 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
367 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
368 + "\tat surefire.MyTest.test(MyTest.java:13)\n"
369 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
370 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
371 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
372 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
373 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
374 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)"
375 + "</pre>" ) ) );
376 }
377
378 public void testSurefireReportNestedClass()
379 throws Exception
380 {
381 File testPom = new File( getUnitBaseDir(), "surefire-report-nestedClass/plugin-config.xml" );
382 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
383 assertNotNull( mojo );
384 mojo.execute();
385 File report = new File( getBasedir(), "target/site/unit/surefire-report-nestedClass/surefire-report.html" );
386 renderer( mojo, report );
387 assertTrue( report.exists() );
388 String htmlContent = FileUtils.fileRead( report );
389
390 assertThat( htmlContent,
391 containsString( toSystemNewLine( "<tr class=\"b\">\n"
392 + "<td>1</td>\n"
393 + "<td>1</td>\n"
394 + "<td>0</td>\n"
395 + "<td>0</td>\n"
396 + "<td>0%</td>\n"
397 + "<td>0</td>" ) ) );
398
399 assertThat( htmlContent,
400 containsString( toSystemNewLine( "<tr class=\"b\">\n"
401 + "<td><a href=\"#surefire\">surefire</a></td>\n"
402 + "<td>1</td>\n"
403 + "<td>1</td>\n"
404 + "<td>0</td>\n"
405 + "<td>0</td>\n"
406 + "<td>0%</td>\n"
407 + "<td>0</td></tr>" ) ) );
408 assertThat( htmlContent,
409 containsString( toSystemNewLine( "<tr class=\"b\">\n"
410 + "<td>"
411 + "<a href=\"#surefire.MyTest\">"
412 + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
413 + "</a>"
414 + "</td>\n"
415 + "<td><a href=\"#surefire.MyTest\">MyTest</a></td>\n"
416 + "<td>1</td>\n"
417 + "<td>1</td>\n"
418 + "<td>0</td>\n"
419 + "<td>0</td>\n"
420 + "<td>0%</td>\n"
421 + "<td>0</td></tr>" ) ) );
422 assertThat( htmlContent,
423 containsString( ">surefire.MyTest:13</a>" ) );
424
425 assertThat( htmlContent, containsString( "./xref-test/surefire/MyTest.html#13" ) );
426
427 assertThat( htmlContent, containsString( toSystemNewLine( "<pre>"
428 + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
429 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
430 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
431 + "\tat surefire.MyTest.test(MyTest.java:13)\n"
432 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
433 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
434 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
435 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
436 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
437 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
438 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
439 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
440 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
441 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
442 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
443 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
444 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
445 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
446 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
447 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
448 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
449 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
450 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
451 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
452 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
453 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
454 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
455 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
456 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
457 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
458 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
459 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
460 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
461 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)"
462 + "</pre>" ) ) );
463 }
464
465 public void testSurefireReportEnclosedTrimStackTrace()
466 throws Exception
467 {
468 File testPom = new File( getUnitBaseDir(), "surefire-report-enclosed-trimStackTrace/plugin-config.xml" );
469 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
470 assertNotNull( mojo );
471 mojo.execute();
472 File report = new File( getBasedir(), "target/site/unit/surefire-report-enclosed-trimStackTrace/surefire-report.html" );
473 renderer( mojo, report );
474 assertTrue( report.exists() );
475 String htmlContent = FileUtils.fileRead( report );
476
477 assertThat( htmlContent,
478 containsString( toSystemNewLine( "<tr class=\"b\">\n"
479 + "<td>1</td>\n"
480 + "<td>1</td>\n"
481 + "<td>0</td>\n"
482 + "<td>0</td>\n"
483 + "<td>0%</td>\n"
484 + "<td>0</td>" ) ) );
485
486 assertThat( htmlContent,
487 containsString( toSystemNewLine( "<tr class=\"b\">\n"
488 + "<td><a href=\"#surefire\">surefire</a></td>\n"
489 + "<td>1</td>\n"
490 + "<td>1</td>\n"
491 + "<td>0</td>\n"
492 + "<td>0</td>\n"
493 + "<td>0%</td>\n"
494 + "<td>0</td></tr>" ) ) );
495 assertThat( htmlContent,
496 containsString( toSystemNewLine( "<tr class=\"b\">\n"
497 + "<td>"
498 + "<a href=\"#surefire.MyTest$A\">"
499 + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
500 + "</a>"
501 + "</td>\n"
502 + "<td><a href=\"#surefire.MyTest$A\">MyTest$A</a></td>\n"
503 + "<td>1</td>\n"
504 + "<td>1</td>\n"
505 + "<td>0</td>\n"
506 + "<td>0</td>\n"
507 + "<td>0%</td>\n"
508 + "<td>0</td></tr>" ) ) );
509
510 assertThat( htmlContent, containsString( ">surefire.MyTest$A:45</a>" ) );
511
512 assertThat( htmlContent, containsString( "./xref-test/surefire/MyTest$A.html#45" ) );
513
514 assertThat( htmlContent, containsString( toSystemNewLine( "<pre>"
515 + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
516 + "\tat surefire.MyTest.failure(MyTest.java:33)\n"
517 + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
518 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
519 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
520 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)\n"
521 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
522 + "\tat surefire.MyTest.access$200(MyTest.java:9)\n"
523 + "\tat surefire.MyTest$A.t(MyTest.java:45)"
524 + "</pre>" ) ) );
525 }
526
527 public void testSurefireReportEnclosed()
528 throws Exception
529 {
530 File testPom = new File( getUnitBaseDir(), "surefire-report-enclosed/plugin-config.xml" );
531 SurefireReportMojo mojo = (SurefireReportMojo) lookupMojo( "report", testPom );
532 assertNotNull( mojo );
533 mojo.execute();
534 File report = new File( getBasedir(), "target/site/unit/surefire-report-enclosed/surefire-report.html" );
535 renderer( mojo, report );
536 assertTrue( report.exists() );
537 String htmlContent = FileUtils.fileRead( report );
538
539 assertThat( htmlContent,
540 containsString( toSystemNewLine( "<tr class=\"b\">\n"
541 + "<td>1</td>\n"
542 + "<td>1</td>\n"
543 + "<td>0</td>\n"
544 + "<td>0</td>\n"
545 + "<td>0%</td>\n"
546 + "<td>0</td>" ) ) );
547
548 assertThat( htmlContent,
549 containsString( toSystemNewLine( "<tr class=\"b\">\n"
550 + "<td><a href=\"#surefire\">surefire</a></td>\n"
551 + "<td>1</td>\n"
552 + "<td>1</td>\n"
553 + "<td>0</td>\n"
554 + "<td>0</td>\n"
555 + "<td>0%</td>\n"
556 + "<td>0</td></tr>" ) ) );
557 assertThat( htmlContent,
558 containsString( toSystemNewLine( "<tr class=\"b\">\n"
559 + "<td>"
560 + "<a href=\"#surefire.MyTest$A\">"
561 + "<img src=\"images/icon_error_sml.gif\" alt=\"\" />"
562 + "</a>"
563 + "</td>\n"
564 + "<td><a href=\"#surefire.MyTest$A\">MyTest$A</a></td>\n"
565 + "<td>1</td>\n"
566 + "<td>1</td>\n"
567 + "<td>0</td>\n"
568 + "<td>0</td>\n"
569 + "<td>0%</td>\n"
570 + "<td>0</td></tr>" ) ) );
571
572 assertThat( htmlContent, containsString( ">surefire.MyTest$A:45</a>" ) );
573
574 assertThat( htmlContent, containsString( "./xref-test/surefire/MyTest$A.html#45" ) );
575
576 assertThat( htmlContent, containsString( toSystemNewLine(
577 "<pre>" + "java.lang.RuntimeException: java.lang.IndexOutOfBoundsException\n"
578 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:24)\n"
579 + "\tat surefire.MyTest.newRethrownDelegate(MyTest.java:17)\n"
580 + "\tat surefire.MyTest.access$200(MyTest.java:9)\n" + "\tat surefire.MyTest$A.t(MyTest.java:45)\n"
581 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n"
582 + "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\n"
583 + "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n"
584 + "\tat java.lang.reflect.Method.invoke(Method.java:606)\n"
585 + "\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)\n"
586 + "\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\n"
587 + "\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)\n"
588 + "\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\n"
589 + "\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)\n"
590 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)\n"
591 + "\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)\n"
592 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
593 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
594 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
595 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
596 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
597 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
598 + "\tat org.junit.runners.Suite.runChild(Suite.java:128)\n"
599 + "\tat org.junit.runners.Suite.runChild(Suite.java:27)\n"
600 + "\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)\n"
601 + "\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)\n"
602 + "\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)\n"
603 + "\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)\n"
604 + "\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)\n"
605 + "\tat org.junit.runners.ParentRunner.run(ParentRunner.java:363)\n"
606 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:272)\n"
607 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:167)\n"
608 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:147)\n"
609 + "\tat org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:130)\n"
610 + "\tat org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:211)\n"
611 + "\tat org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:163)\n"
612 + "\tat org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:105)\n"
613 + "\tCaused by: java.lang.IndexOutOfBoundsException\n"
614 + "\tat surefire.MyTest.failure(MyTest.java:33)\n" + "\tat surefire.MyTest.access$100(MyTest.java:9)\n"
615 + "\tat surefire.MyTest$Nested.run(MyTest.java:38)\n"
616 + "\tat surefire.MyTest.delegate(MyTest.java:29)\n"
617 + "\tat surefire.MyTest.rethrownDelegate(MyTest.java:22)" + "</pre>" ) ) );
618 }
619
620
621
622
623
624
625
626
627
628 private void renderer( SurefireReportMojo mojo, File outputHtml )
629 throws RendererException, IOException
630 {
631 Writer writer = null;
632 SiteRenderingContext context = new SiteRenderingContext();
633 context.setDecoration( new DecorationModel() );
634 context.setTemplateName( "org/apache/maven/doxia/siterenderer/resources/default-site.vm" );
635 context.setLocale( Locale.ENGLISH );
636
637 try
638 {
639 outputHtml.getParentFile().mkdirs();
640 writer = WriterFactory.newXmlWriter( outputHtml );
641
642 renderer.generateDocument( writer, (SiteRendererSink) mojo.getSink(), context );
643 }
644 finally
645 {
646 IOUtil.close( writer );
647 }
648 }
649 }