View Javadoc

1   package org.apache.maven.shared.release.phase;
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 static org.mockito.Matchers.eq;
23  import static org.mockito.Matchers.isA;
24  import static org.mockito.Matchers.isNull;
25  import static org.mockito.Mockito.doThrow;
26  import static org.mockito.Mockito.mock;
27  import static org.mockito.Mockito.verify;
28  import static org.mockito.Mockito.verifyNoMoreInteractions;
29  
30  import java.io.File;
31  import java.util.List;
32  
33  import org.apache.maven.project.MavenProject;
34  import org.apache.maven.settings.Settings;
35  import org.apache.maven.shared.release.ReleaseExecutionException;
36  import org.apache.maven.shared.release.ReleaseResult;
37  import org.apache.maven.shared.release.config.ReleaseDescriptor;
38  import org.apache.maven.shared.release.env.ReleaseEnvironment;
39  import org.apache.maven.shared.release.exec.MavenExecutor;
40  import org.apache.maven.shared.release.exec.MavenExecutorException;
41  import org.codehaus.plexus.PlexusTestCase;
42  
43  /**
44   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
45   * @version $Id: RunPerformGoalsPhaseTest.java 1338367 2012-05-14 19:45:51Z rfscholte $
46   */
47  public class RunPerformGoalsPhaseTest
48      extends PlexusTestCase
49  {
50      private RunPerformGoalsPhase phase;
51  
52      protected void setUp()
53          throws Exception
54      {
55          super.setUp();
56  
57          phase = (RunPerformGoalsPhase) lookup( ReleasePhase.ROLE, "run-perform-goals" );
58      }
59  
60      public void testExecuteException()
61          throws Exception
62      {
63          // prepare
64          File testFile = getTestFile( "target/checkout-directory" );
65  
66          ReleaseDescriptor config = new ReleaseDescriptor();
67          config.setPerformGoals( "goal1 goal2" );
68          config.setCheckoutDirectory( testFile.getAbsolutePath() );
69  
70          MavenExecutor mock = mock( MavenExecutor.class );
71  
72          doThrow( new MavenExecutorException( "...", new Exception() ) ).when( mock ).executeGoals( eq( testFile ),
73                                                                                                     eq( "goal1 goal2" ),
74                                                                                                     isA( ReleaseEnvironment.class ),
75                                                                                                     eq( true ),
76                                                                                                     eq( "-DperformRelease=true -f pom.xml" ),
77                                                                                                     isNull( String.class ),
78                                                                                                     isA( ReleaseResult.class ) );
79  
80          phase.setMavenExecutor(ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
81  
82          // execute
83          try
84          {
85              phase.execute( config, (Settings) null, (List<MavenProject>) null );
86  
87              fail( "Should have thrown an exception" );
88          }
89          catch ( ReleaseExecutionException e )
90          {
91              assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() );
92          }
93          
94          //verify
95          verify( mock ).executeGoals( eq( testFile ),
96                                       eq( "goal1 goal2" ),
97                                       isA( ReleaseEnvironment.class ),
98                                       eq( true ),
99                                       eq( "-DperformRelease=true -f pom.xml" ),
100                                      isNull( String.class ),
101                                      isA( ReleaseResult.class ) );
102         verifyNoMoreInteractions( mock );
103     }
104 
105     public void testCustomPomFile() throws Exception
106     {
107         //prepare
108         File testFile = getTestFile( "target/checkout-directory" );
109         ReleaseDescriptor config = new ReleaseDescriptor();
110         config.setPerformGoals( "goal1 goal2" );
111         config.setPomFileName( "pom1.xml" );
112         config.setCheckoutDirectory( testFile.getAbsolutePath() );
113         
114         MavenExecutor mock = mock( MavenExecutor.class );
115         
116         phase.setMavenExecutor(ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
117         
118         phase.execute( config, (Settings) null, (List<MavenProject>) null );
119         
120         verify( mock ).executeGoals( eq( testFile ),
121                                      eq( "goal1 goal2" ),
122                                      isA( ReleaseEnvironment.class ),
123                                      eq( true ),
124                                      eq( "-DperformRelease=true -f pom1.xml" ),
125                                      eq( "pom1.xml" ),
126                                      isA( ReleaseResult.class ) );
127         
128         verifyNoMoreInteractions( mock );
129     }
130 }