View Javadoc
1   package org.apache.maven.it;
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 org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  
26  /**
27   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-95">MNG-95</a>.
28   *
29   * @author John Casey
30   *
31   */
32  public class MavenITmng0095ReactorFailureBehaviorTest
33      extends AbstractMavenIntegrationTestCase
34  {
35      public MavenITmng0095ReactorFailureBehaviorTest()
36      {
37          super( ALL_MAVEN_VERSIONS );
38      }
39  
40      /**
41       * Test fail-fast reactor behavior. Forces an exception to be thrown in
42       * the first module and checks that the second &amp; third module is not built and the overall build fails, too.
43       *
44       * @throws Exception in case of failure
45       */
46      public void testitFailFast()
47          throws Exception
48      {
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
50  
51          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
52          verifier.setAutoclean( false );
53          verifier.deleteDirectory( "target" );
54          verifier.deleteDirectory( "subproject1/target" );
55          verifier.deleteDirectory( "subproject2/target" );
56          verifier.deleteDirectory( "subproject3/target" );
57          verifier.addCliOption( "--fail-fast" );
58          verifier.setLogFileName( "log-ff.txt" );
59          try
60          {
61              verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
62              verifier.verifyErrorFreeLog();
63          }
64          catch ( VerificationException e )
65          {
66              // expected
67          }
68          verifier.resetStreams();
69  
70          verifier.assertFilePresent( "target/touch.txt" );
71          verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
72          verifier.assertFileNotPresent( "subproject2/target/touch.txt" );
73          verifier.assertFileNotPresent( "subproject3/target/touch.txt" );
74      }
75  
76      /**
77       * Test fail-never reactor behavior. Forces an exception to be thrown in
78       * the first module, but checks that the second &amp; third module is built and the overall build succeeds.
79       *
80       * @throws Exception in case of failure
81       */
82      public void testitFailNever()
83          throws Exception
84      {
85          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
86  
87          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
88          verifier.setAutoclean( false );
89          verifier.deleteDirectory( "target" );
90          verifier.deleteDirectory( "subproject1/target" );
91          verifier.deleteDirectory( "subproject2/target" );
92          verifier.deleteDirectory( "subproject3/target" );
93          verifier.addCliOption( "--fail-never" );
94          verifier.setLogFileName( "log-fn.txt" );
95          verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
96          verifier.resetStreams();
97  
98          verifier.assertFilePresent( "target/touch.txt" );
99          verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
100         verifier.assertFilePresent( "subproject2/target/touch.txt" );
101         verifier.assertFilePresent( "subproject3/target/touch.txt" );
102     }
103 
104     /**
105      * Test fail-at-end reactor behavior. Forces an exception to be thrown in
106      * the first module and checks that the second module is still built but the overall build finally fails
107      * and the third module (which depends on the failed module) is skipped.
108      *
109      * @throws Exception in case of failure
110      */
111     public void testitFailAtEnd()
112         throws Exception
113     {
114         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0095" );
115 
116         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
117         verifier.setAutoclean( false );
118         verifier.deleteDirectory( "target" );
119         verifier.deleteDirectory( "subproject1/target" );
120         verifier.deleteDirectory( "subproject2/target" );
121         verifier.deleteDirectory( "subproject3/target" );
122         verifier.addCliOption( "--fail-at-end" );
123         verifier.setLogFileName( "log-fae.txt" );
124         try
125         {
126             verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-touch:touch" );
127             verifier.verifyErrorFreeLog();
128         }
129         catch ( VerificationException e )
130         {
131             // expected
132         }
133         verifier.resetStreams();
134 
135         verifier.assertFilePresent( "target/touch.txt" );
136         verifier.assertFileNotPresent( "subproject1/target/touch.txt" );
137         verifier.assertFilePresent( "subproject2/target/touch.txt" );
138         verifier.assertFileNotPresent( "subproject3/target/touch.txt" );
139     }
140 
141 }