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