1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.util.ResourceExtractor;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.util.List;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class MavenITmng5760ResumeFeatureTest extends AbstractMavenIntegrationTestCase {
43 private final File parentDependentTestDir;
44 private final File parentIndependentTestDir;
45 private final File noProjectTestDir;
46 private final File fourModulesTestDir;
47
48 public MavenITmng5760ResumeFeatureTest() throws IOException {
49 super( "[4.0.0-alpha-1,)" );
50 this.parentDependentTestDir = ResourceExtractor.simpleExtractResources( getClass(),
51 "/mng-5760-resume-feature/parent-dependent" );
52 this.parentIndependentTestDir = ResourceExtractor.simpleExtractResources( getClass(),
53 "/mng-5760-resume-feature/parent-independent" );
54 this.noProjectTestDir = ResourceExtractor.simpleExtractResources( getClass(),
55 "/mng-5760-resume-feature/no-project" );
56 this.fourModulesTestDir = ResourceExtractor.simpleExtractResources( getClass(),
57 "/mng-5760-resume-feature/four-modules" );
58 }
59
60
61
62
63
64
65 public void testShouldSuggestToResumeWithoutArgs() throws Exception
66 {
67 Verifier verifier = newVerifier( parentDependentTestDir.getAbsolutePath() );
68 verifier.addCliOption( "-Dmodule-b.fail=true" );
69
70 try
71 {
72 verifier.executeGoal( "test" );
73 fail( "Expected this invocation to fail" );
74 }
75 catch ( final VerificationException ve )
76 {
77 verifier.verifyTextInLog( "mvn [args] -r" );
78 verifyTextNotInLog( verifier, "mvn [args] -rf :module-b" );
79 }
80 finally
81 {
82 verifier.resetStreams();
83 }
84
85
86 verifier = newVerifier( parentDependentTestDir.getAbsolutePath() );
87 verifier.addCliOption( "-r" );
88 verifier.executeGoal( "test" );
89 verifyTextNotInLog( verifier, "Building module-a 1.0" );
90 verifier.verifyTextInLog( "Building module-b 1.0" );
91 verifier.verifyTextInLog( "Building module-c 1.0" );
92 verifier.resetStreams();
93 }
94
95 public void testShouldSkipSuccessfulProjects() throws Exception
96 {
97 Verifier verifier = newVerifier( parentDependentTestDir.getAbsolutePath() );
98 verifier.addCliOption( "-Dmodule-a.fail=true" );
99 verifier.addCliOption( "--fail-at-end");
100
101 try
102 {
103 verifier.executeGoal( "test" );
104 fail( "Expected this invocation to fail" );
105 }
106 catch ( final VerificationException ve )
107 {
108
109 }
110 finally
111 {
112 verifier.resetStreams();
113 }
114
115
116 verifier = newVerifier( parentDependentTestDir.getAbsolutePath() );
117 verifier.addCliOption( "-Dmodule-b.fail=true" );
118 verifier.addCliOption( "-Dmodule-c.fail=true" );
119
120
121 verifier.addCliOption( "-r" );
122 try
123 {
124 verifier.executeGoal( "test" );
125 }
126 finally
127 {
128 verifier.resetStreams();
129 }
130 }
131
132 public void testShouldSkipSuccessfulModulesWhenTheFirstModuleFailed() throws Exception
133 {
134
135
136
137 Verifier verifier = newVerifier( parentIndependentTestDir.getAbsolutePath() );
138 verifier.addCliOption( "-Dmodule-a.fail=true" );
139 verifier.addCliOption( "--fail-at-end");
140
141 try
142 {
143 verifier.executeGoal( "test" );
144 fail( "Expected this invocation to fail" );
145 }
146 catch ( final VerificationException ve )
147 {
148 verifier.verifyTextInLog( "mvn [args] -r" );
149 }
150 finally
151 {
152 verifier.resetStreams();
153 }
154
155 verifier = newVerifier( parentIndependentTestDir.getAbsolutePath() );
156 verifier.addCliOption( "-r" );
157 verifier.executeGoal( "test" );
158 verifier.verifyTextInLog( "Building module-a 1.0" );
159 verifyTextNotInLog( verifier, "Building module-b 1.0" );
160 verifier.resetStreams();
161 }
162
163 public void testShouldNotCrashWithoutProject() throws Exception
164 {
165
166
167
168 final Verifier verifier = newVerifier( noProjectTestDir.getAbsolutePath() );
169 try
170 {
171 verifier.executeGoal( "resources:resources" );
172 }
173 catch ( final VerificationException ve )
174 {
175 verifier.verifyTextInLog( "Goal requires a project to execute but there is no POM in this directory" );
176 }
177 finally
178 {
179 verifier.resetStreams();
180 }
181 }
182
183 public void testFailureWithParallelBuild() throws Exception
184 {
185
186
187
188
189
190
191
192
193
194
195 Verifier verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
196 verifier.addCliOption( "-T2" );
197 verifier.addCliOption( "-Dmodule-a.delay=1000" );
198 verifier.addCliOption( "-Dmodule-a.fail=true" );
199 verifier.addCliOption( "-Dmodule-c.fail=true" );
200 try
201 {
202 verifier.executeGoal( "verify" );
203 fail( "Expected this invocation to fail" );
204 }
205 catch ( final VerificationException ve )
206 {
207
208 }
209 finally
210 {
211 verifier.resetStreams();
212 }
213
214
215 verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
216 verifier.addCliOption( "-T2" );
217 verifier.addCliOption( "-Dmodule-b.fail=true" );
218
219
220 verifier.addCliOption( "-r" );
221
222
223
224
225 try
226 {
227 verifier.executeGoal( "verify" );
228 }
229 finally
230 {
231 verifier.resetStreams();
232 }
233 }
234
235 public void testFailureAfterSkipWithParallelBuild() throws Exception
236 {
237
238
239
240
241
242
243
244
245
246
247 Verifier verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
248 verifier.addCliOption( "-T2" );
249 verifier.addCliOption( "-Dmodule-b.delay=2000" );
250 verifier.addCliOption( "-Dmodule-d.fail=true" );
251 try
252 {
253 verifier.executeGoal( "verify" );
254 fail( "Expected this invocation to fail" );
255 }
256 catch ( final VerificationException ve )
257 {
258
259 }
260 finally
261 {
262 verifier.resetStreams();
263 }
264
265
266 verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
267 verifier.addCliOption( "-T2" );
268 verifier.addCliOption( "-Dmodule-a.fail=true" );
269 verifier.addCliOption( "-Dmodule-b.fail=true" );
270
271
272 verifier.addCliOption( "-r" );
273 try
274 {
275
276
277
278 verifier.executeGoal( "verify" );
279 }
280 finally
281 {
282 verifier.resetStreams();
283 }
284 }
285
286
287
288
289
290
291
292
293 private void verifyTextNotInLog( Verifier verifier, String text )
294 throws VerificationException
295 {
296 List<String> lines = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
297
298 for ( String line : lines )
299 {
300 if ( Verifier.stripAnsi( line ).contains( text ) )
301 {
302 throw new VerificationException( "Text found in log: " + text );
303 }
304 }
305 }
306 }