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 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
20 import org.codehaus.plexus.util.FileUtils;
21
22 import java.io.File;
23
24 /**
25 * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
26 */
27 public class SurefireReportMojoTest
28 extends AbstractMojoTestCase
29 {
30 public void setUp()
31 throws Exception
32 {
33 super.setUp();
34 }
35
36 public void testBasicSurefireReport()
37 throws Exception
38 {
39 File testPom = new File( getBasedir(),
40 "target/test-classes/unit/basic-surefire-report-test/plugin-config.xml" );
41
42 SurefireReportMojo mojo = ( SurefireReportMojo ) lookupMojo( "report", testPom );
43
44 assertNotNull( mojo );
45
46 String outputDir = ( String ) getVariableValueFromObject( mojo, "outputDirectory" );
47
48 boolean showSuccess = ( ( Boolean ) getVariableValueFromObject( mojo, "showSuccess" ) ).booleanValue();
49
50 File reportsDir = ( File ) getVariableValueFromObject( mojo, "reportsDirectory" );
51
52 String outputName = ( String ) getVariableValueFromObject( mojo, "outputName" );
53
54 File xrefLocation = ( File ) getVariableValueFromObject( mojo, "xrefLocation" );
55
56 boolean linkXRef = ( ( Boolean ) getVariableValueFromObject( mojo, "linkXRef" ) ).booleanValue();
57
58 assertEquals( getBasedir() + "/target/site/unit/basic-surefire-report-test", outputDir );
59
60 assertTrue( showSuccess );
61
62 assertEquals( new File( getBasedir() + "/src/test/resources/unit/basic-surefire-report-test/surefire-reports" ).getAbsolutePath(), reportsDir.getAbsolutePath() );
63
64 assertEquals( "surefire-report", outputName );
65
66 assertEquals( new File( getBasedir() + "/target/site/unit/basic-surefire-report-test/xref-test" ).getAbsolutePath(), xrefLocation.getAbsolutePath() );
67
68 assertTrue( linkXRef );
69
70 mojo.execute();
71
72 File report = new File( getBasedir(), "target/site/unit/basic-surefire-report-test/surefire-report.html" );
73
74 assertTrue( report.exists() );
75
76 String htmlContent = FileUtils.fileRead( report );
77
78 int idx = htmlContent.indexOf( "images/icon_success_sml.gif" );
79
80 assertTrue( idx >= 0 );
81 }
82
83 public void testBasicSurefireReportIfShowSuccessIsFalse()
84 throws Exception
85 {
86 File testPom = new File( getBasedir(),
87 "target/test-classes/unit/basic-surefire-report-success-false/plugin-config.xml" );
88
89 SurefireReportMojo mojo = ( SurefireReportMojo ) lookupMojo( "report", testPom );
90
91 assertNotNull( mojo );
92
93 boolean showSuccess = ( ( Boolean ) getVariableValueFromObject( mojo, "showSuccess" ) ).booleanValue();
94
95 assertFalse( showSuccess );
96
97 mojo.execute();
98
99 File report = new File( getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire-report.html" );
100
101 assertTrue( report.exists() );
102
103 String htmlContent = FileUtils.fileRead( report );
104
105 int idx = htmlContent.indexOf( "images/icon_success_sml.gif" );
106
107 assertTrue( idx < 0 );
108 }
109
110 public void testBasicSurefireReportIfLinkXrefIsFalse()
111 throws Exception
112 {
113 File testPom = new File( getBasedir(),
114 "target/test-classes/unit/basic-surefire-report-linkxref-false/plugin-config.xml" );
115
116 SurefireReportMojo mojo = ( SurefireReportMojo ) lookupMojo( "report", testPom );
117
118 assertNotNull( mojo );
119
120 boolean linkXRef = ( ( Boolean ) getVariableValueFromObject( mojo, "linkXRef" ) ).booleanValue();
121
122 assertFalse( linkXRef );
123
124 mojo.execute();
125
126 File report = new File( getBasedir(), "target/site/unit/basic-surefire-report-success-false/surefire-report.html" );
127
128 assertTrue( report.exists() );
129
130 String htmlContent = FileUtils.fileRead( report );
131
132 int idx = htmlContent.indexOf( "./xref-test/com/shape/CircleTest.html#44" );
133
134 assertTrue( idx >= 0);
135 }
136
137 public void testBasicSurefireReportIfReportingIsNull()
138 throws Exception
139 {
140 File testPom = new File( getBasedir(),
141 "target/test-classes/unit/basic-surefire-report-reporting-null/plugin-config.xml" );
142
143 SurefireReportMojo mojo = ( SurefireReportMojo ) lookupMojo( "report", testPom );
144
145 assertNotNull( mojo );
146
147 mojo.execute();
148
149 File report = new File( getBasedir(), "target/site/unit/basic-surefire-report-reporting-null/surefire-report.html" );
150
151 assertTrue( report.exists() );
152
153 String htmlContent = FileUtils.fileRead( report );
154
155 int idx = htmlContent.indexOf( "./xref-test/com/shape/CircleTest.html#44" );
156
157 assertTrue( idx < 0);
158 }
159 }