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 java.io.File;
23  
24  import org.apache.maven.it.util.ResourceExtractor;
25  
26  /**
27   * IT that verifies that lifecycle participant
28   * methods are invoked even with various build failures/errors.
29   */
30  public class MavenITmng5640LifecycleParticipantAfterSessionEnd
31      extends AbstractMavenIntegrationTestCase
32  {
33      public MavenITmng5640LifecycleParticipantAfterSessionEnd()
34      {
35          super( "[3.2.2,)" );
36      }
37  
38      /**
39       * IT executing a Maven build that has UT failure.
40       *
41       * @throws Exception in case of failure
42       */
43      public void testBuildFailureUTFail()
44          throws Exception
45      {
46          File testDir =
47              ResourceExtractor.simpleExtractResources( getClass(), "/mng-5640-lifecycleParticipant-afterSession" );
48          File extensionDir = new File( testDir, "extension" );
49          File projectDir = new File( testDir, "buildfailure-utfail" );
50  
51          Verifier verifier;
52  
53          // install the test plugin
54          verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
55          verifier.executeGoal( "install" );
56          verifier.resetStreams();
57          verifier.verifyErrorFreeLog();
58  
59          // build the test project
60          verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
61          try
62          {
63              verifier.executeGoal( "package" );
64              fail( "The build should fail" );
65          }
66          catch (VerificationException e)
67          {
68              // expected, as the build will fail due to always failing UT
69          }
70          verifier.resetStreams();
71          verifier.verifyTextInLog("testApp(org.apache.maven.its.mng5640.FailingTest)");
72  
73          verifier.assertFilePresent( "target/afterProjectsRead.txt" );
74          // See https://issues.apache.org/jira/browse/MNG-5641
75          // verifier.assertFilePresent( "target/afterSessionStart.txt" );
76          verifier.assertFilePresent( "target/afterSessionEnd.txt" );
77      }
78  
79      /**
80       * IT executing a Maven build that has missing dependency.
81       *
82       * @throws Exception in case of failure
83       */
84      public void testBuildFailureMissingDependency()
85          throws Exception
86      {
87          File testDir =
88              ResourceExtractor.simpleExtractResources( getClass(), "/mng-5640-lifecycleParticipant-afterSession" );
89          File extensionDir = new File( testDir, "extension" );
90          File projectDir = new File( testDir, "buildfailure-depmissing" );
91  
92          Verifier verifier;
93  
94          // install the test plugin
95          verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
96          verifier.executeGoal( "install" );
97          verifier.resetStreams();
98          verifier.verifyErrorFreeLog();
99  
100         // build the test project
101         verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
102         try
103         {
104             verifier.executeGoal( "package" );
105             fail( "The build should fail" );
106         }
107         catch (VerificationException e)
108         {
109             // expected, as the build will fail due to always failing UT
110         }
111         verifier.resetStreams();
112 
113         verifier.assertFilePresent( "target/afterProjectsRead.txt" );
114         // See https://issues.apache.org/jira/browse/MNG-5641
115         // verifier.assertFilePresent( "target/afterSessionStart.txt" );
116         verifier.assertFilePresent( "target/afterSessionEnd.txt" );
117     }
118 
119     /**
120      * IT executing a Maven build that has failing Maven plugin.
121      *
122      * @throws Exception in case of failure
123      */
124     public void testBuildError()
125         throws Exception
126     {
127         File testDir =
128             ResourceExtractor.simpleExtractResources( getClass(), "/mng-5640-lifecycleParticipant-afterSession" );
129         File extensionDir = new File( testDir, "extension" );
130         File pluginDir = new File( testDir, "badplugin" );
131         File projectDir = new File( testDir, "builderror-mojoex" );
132 
133         Verifier verifier;
134 
135         // install the test plugin
136         verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
137         verifier.executeGoal( "install" );
138         verifier.resetStreams();
139         verifier.verifyErrorFreeLog();
140 
141         // install the bad plugin
142         verifier = newVerifier( pluginDir.getAbsolutePath(), "remote" );
143         verifier.executeGoal( "install" );
144         verifier.resetStreams();
145         verifier.verifyErrorFreeLog();
146 
147         // build the test project
148         verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
149         try
150         {
151             verifier.executeGoal( "package" );
152             fail( "The build should fail" );
153         }
154         catch ( VerificationException e )
155         {
156             // expected, as the build will fail due to always failing UT
157         }
158         verifier.resetStreams();
159 
160         verifier.assertFilePresent( "target/afterProjectsRead.txt" );
161         // See https://issues.apache.org/jira/browse/MNG-5641
162         // verifier.assertFilePresent( "target/afterSessionStart.txt" );
163         verifier.assertFilePresent( "target/afterSessionEnd.txt" );
164     }
165 
166     /**
167      * IT executing a Maven build that has failing Maven plugin throwing RuntimeException.
168      *
169      * @throws Exception in case of failure
170      */
171     public void testBuildErrorRt()
172         throws Exception
173     {
174         File testDir =
175             ResourceExtractor.simpleExtractResources( getClass(), "/mng-5640-lifecycleParticipant-afterSession" );
176         File extensionDir = new File( testDir, "extension" );
177         File pluginDir = new File( testDir, "badplugin" );
178         File projectDir = new File( testDir, "builderror-runtimeex" );
179 
180         Verifier verifier;
181 
182         // install the test plugin
183         verifier = newVerifier( extensionDir.getAbsolutePath(), "remote" );
184         verifier.executeGoal( "install" );
185         verifier.resetStreams();
186         verifier.verifyErrorFreeLog();
187 
188         // install the bad plugin
189         verifier = newVerifier( pluginDir.getAbsolutePath(), "remote" );
190         verifier.executeGoal( "install" );
191         verifier.resetStreams();
192         verifier.verifyErrorFreeLog();
193 
194         // build the test project
195         verifier = newVerifier( projectDir.getAbsolutePath(), "remote" );
196         try
197         {
198             verifier.executeGoal( "package" );
199             fail( "The build should fail" );
200         }
201         catch ( VerificationException e )
202         {
203             // expected, as the build will fail due to always failing UT
204         }
205         verifier.resetStreams();
206 
207         verifier.assertFilePresent( "target/afterProjectsRead.txt" );
208         // See https://issues.apache.org/jira/browse/MNG-5641
209         // verifier.assertFilePresent( "target/afterSessionStart.txt" );
210         verifier.assertFilePresent( "target/afterSessionEnd.txt" );
211     }
212 }