1 package org.apache.maven.shared.release.phase;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.ReleaseFailureException;
37 import org.apache.maven.shared.release.ReleaseResult;
38 import org.apache.maven.shared.release.config.ReleaseDescriptor;
39 import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
40 import org.apache.maven.shared.release.env.ReleaseEnvironment;
41 import org.apache.maven.shared.release.exec.MavenExecutor;
42 import org.apache.maven.shared.release.exec.MavenExecutorException;
43 import org.codehaus.plexus.PlexusTestCase;
44
45
46
47
48
49
50 public class RunCompleteGoalsPhaseTest
51 extends PlexusTestCase
52 {
53 private RunCompleteGoalsPhase phase;
54
55 protected void setUp()
56 throws Exception
57 {
58 super.setUp();
59
60 phase = (RunCompleteGoalsPhase) lookup( ReleasePhase.ROLE, "run-completion-goals" );
61 }
62
63 public void testExecute()
64 throws ReleaseExecutionException, ReleaseFailureException, MavenExecutorException
65 {
66
67 File testFile = getTestFile( "target/working-directory" );
68
69 ReleaseDescriptor config = new ReleaseDescriptor();
70 config.setCompletionGoals( "clean integration-test" );
71 config.setWorkingDirectory( testFile.getAbsolutePath() );
72
73 MavenExecutor mock = mock( MavenExecutor.class );
74
75 phase.setMavenExecutor(ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
76
77
78 phase.execute( config, (Settings) null, (List<MavenProject>) null );
79
80
81 verify( mock ).executeGoals( eq( testFile ),
82 eq( "clean integration-test" ),
83 isA( ReleaseEnvironment.class ),
84 eq( true ),
85 isNull( String.class ),
86 isNull( String.class ),
87 isA( ReleaseResult.class ) );
88 verifyNoMoreInteractions( mock );
89 }
90
91 public void testSimulate()
92 throws ReleaseExecutionException, MavenExecutorException
93 {
94
95 File testFile = getTestFile( "target/working-directory" );
96
97 ReleaseDescriptor config = new ReleaseDescriptor();
98 config.setCompletionGoals( "clean integration-test" );
99 config.setWorkingDirectory( testFile.getAbsolutePath() );
100
101 MavenExecutor mock = mock( MavenExecutor.class );
102
103 phase.setMavenExecutor( ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
104
105
106 phase.simulate( config, new DefaultReleaseEnvironment(), null );
107
108
109 verify( mock ).executeGoals( eq( testFile ),
110 eq( "clean integration-test" ),
111 isA( ReleaseEnvironment.class ),
112 eq( true ),
113 isNull( String.class ),
114 isNull( String.class ), isA( ReleaseResult.class ) );
115 verifyNoMoreInteractions( mock );
116 }
117
118 public void testExecuteException()
119 throws ReleaseFailureException, MavenExecutorException
120 {
121
122 File testFile = getTestFile( "target/working-directory" );
123
124 ReleaseDescriptor config = new ReleaseDescriptor();
125 config.setCompletionGoals( "clean integration-test" );
126 config.setWorkingDirectory( testFile.getAbsolutePath() );
127
128 MavenExecutor mock = mock( MavenExecutor.class );
129 doThrow( new MavenExecutorException( "...", new Exception() ) ).when( mock ).executeGoals( eq( testFile ),
130 eq( "clean integration-test" ),
131 isA( ReleaseEnvironment.class ),
132 eq( true ),
133 isNull( String.class ),
134 isNull( String.class ),
135 isA( ReleaseResult.class ) );
136
137 phase.setMavenExecutor(ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
138
139
140 try
141 {
142 phase.execute( config, (Settings) null, (List<MavenProject>) null );
143
144 fail( "Should have thrown an exception" );
145 }
146 catch ( ReleaseExecutionException e )
147 {
148 assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() );
149 }
150
151
152 verify( mock ).executeGoals( eq( testFile ),
153 eq( "clean integration-test" ),
154 isA( ReleaseEnvironment.class ),
155 eq( true ),
156 isNull( String.class ),
157 isNull( String.class ),
158 isA( ReleaseResult.class ) );
159 verifyNoMoreInteractions( mock );
160 }
161
162 public void testSimulateException() throws MavenExecutorException
163 {
164
165 File testFile = getTestFile( "target/working-directory" );
166
167 ReleaseDescriptor config = new ReleaseDescriptor();
168 config.setCompletionGoals( "clean integration-test" );
169 config.setWorkingDirectory( testFile.getAbsolutePath() );
170
171 MavenExecutor mock = mock( MavenExecutor.class );
172 doThrow( new MavenExecutorException( "...", new Exception() ) ).when( mock ).executeGoals( eq( testFile ),
173 eq( "clean integration-test" ),
174 isA( ReleaseEnvironment.class ),
175 eq( true ),
176 isNull( String.class ),
177 isNull( String.class ),
178 isA( ReleaseResult.class ) );
179
180
181 phase.setMavenExecutor( ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
182
183
184 try
185 {
186 phase.simulate( config, new DefaultReleaseEnvironment(), null );
187
188 fail( "Should have thrown an exception" );
189 }
190 catch ( ReleaseExecutionException e )
191 {
192 assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() );
193 }
194
195
196 verify( mock ).executeGoals( eq( testFile ),
197 eq( "clean integration-test" ),
198 isA( ReleaseEnvironment.class ),
199 eq( true ),
200 isNull( String.class ),
201 isNull( String.class ),
202 isA( ReleaseResult.class ) );
203 verifyNoMoreInteractions( mock );
204 }
205
206 public void testEmptyGoals()
207 throws Exception
208 {
209
210 File testFile = getTestFile( "target/working-directory" );
211
212 ReleaseDescriptor config = new ReleaseDescriptor();
213 config.setCompletionGoals( "" );
214 config.setWorkingDirectory( testFile.getAbsolutePath() );
215
216 MavenExecutor mock = mock( MavenExecutor.class );
217
218 phase.setMavenExecutor(ReleaseEnvironment.DEFAULT_MAVEN_EXECUTOR_ID, mock );
219
220
221 phase.execute( config, (Settings) null, (List<MavenProject>) null );
222
223
224
225 verifyNoMoreInteractions( mock );
226 }
227 }