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