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.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
45
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
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
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
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
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 }