1 package org.apache.maven.scm.provider.accurev.command.checkout;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile;
23 import static org.hamcrest.Matchers.is;
24 import static org.hamcrest.Matchers.notNullValue;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
28
29 import java.io.File;
30 import java.util.Collections;
31 import java.util.List;
32
33 import org.apache.maven.scm.CommandParameter;
34 import org.apache.maven.scm.CommandParameters;
35 import org.apache.maven.scm.ScmException;
36 import org.apache.maven.scm.ScmFile;
37 import org.apache.maven.scm.ScmFileSet;
38 import org.apache.maven.scm.ScmFileStatus;
39 import org.apache.maven.scm.ScmRevision;
40 import org.apache.maven.scm.ScmTag;
41 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
42 import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
43 import org.junit.Test;
44
45
46
47
48
49
50
51
52
53
54 public class AccuRevCheckOutCommandTest
55 extends AbstractAccuRevCommandTest
56 {
57
58 @Test
59 public void testCheckout()
60 throws Exception
61 {
62
63 when( accurev.mkws( "myStream", AccuRevCheckOutCommand.getWorkSpaceName( basedir, "myStream" ), basedir ) ).thenReturn(
64 true );
65
66 List<File> updatedFiles = Collections.singletonList( new File( "updated/file" ) );
67 when( accurev.update( basedir, "now" ) ).thenReturn( updatedFiles );
68
69 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
70
71 CheckOutScmResult result = command.checkout( repo, new ScmFileSet( basedir ), new CommandParameters() );
72
73 assertThat( result.isSuccess(), is( true ) );
74 assertThat( result.getRelativePathProjectDirectory(), is( "/project/dir" ) );
75 List<ScmFile> checkedOutFiles = result.getCheckedOutFiles();
76 assertThat( checkedOutFiles.size(), is( 1 ) );
77 assertHasScmFile( checkedOutFiles, "updated/file", ScmFileStatus.CHECKED_OUT );
78
79 }
80
81 @Test
82 public void testCheckoutFailure()
83 throws Exception
84 {
85
86 when( accurev.mkws( "myStream", AccuRevCheckOutCommand.getWorkSpaceName( basedir, "myStream" ), basedir ) ).thenReturn(
87 true );
88 when( accurev.update( basedir, "now" ) ).thenReturn( null );
89
90 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
91
92 CheckOutScmResult result = command.checkout( repo, new ScmFileSet( basedir ), new CommandParameters() );
93
94 assertThat( result.isSuccess(), is( false ) );
95 assertThat( result.getProviderMessage(), notNullValue() );
96
97 }
98
99 @Test
100 public void testReCheckoutExistingWorkspaceSameBasis()
101 throws Exception
102 {
103
104
105 info.setWorkSpace( "someOldStream_someUser" );
106 info.setBasis( "myStream" );
107 info.setTop( basedir.getAbsolutePath() );
108
109 List<File> emptyList = Collections.emptyList();
110
111 when( accurev.pop( basedir, null ) ).thenReturn( emptyList );
112
113 List<File> updatedFiles = Collections.singletonList( new File( "updated/file" ) );
114 when( accurev.update( basedir, null ) ).thenReturn( updatedFiles );
115
116 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
117
118 CheckOutScmResult result = command.checkout( repo, new ScmFileSet( basedir ), new CommandParameters() );
119
120 verify( accurev ).pop( basedir, null );
121
122 assertThat( result.isSuccess(), is( true ) );
123 assertThat( result.getRelativePathProjectDirectory(), is( "/project/dir" ) );
124
125 }
126
127 @Test
128 public void testReCheckoutExistingWorkspaceDifferentBasis()
129 throws Exception
130 {
131
132 info.setWorkSpace( "someOldStream_someUser" );
133 info.setBasis( "myStream" );
134 info.setTop( basedir.getAbsolutePath() );
135
136 when( accurev.chws( basedir, "someOldStream_someUser", "mySnapShot" ) ).thenReturn( true );
137
138 List<File> emptyPop = Collections.emptyList();
139 when( accurev.popExternal( basedir, null, null, null ) ).thenReturn( emptyPop );
140
141 List<File> updatedFiles = Collections.singletonList( new File( "updated/file" ) );
142 when( accurev.update( basedir, null ) ).thenReturn( updatedFiles );
143
144 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
145
146 CommandParameters params = new CommandParameters();
147 params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot" ) );
148
149 CheckOutScmResult result = command.checkout( repo, new ScmFileSet( basedir ), params );
150
151 verify( accurev ).chws( basedir, "someOldStream_someUser", "mySnapShot" );
152
153 assertThat( result.isSuccess(), is( true ) );
154 assertThat( result.getRelativePathProjectDirectory(), is( "/project/dir" ) );
155
156 }
157
158 @Test( expected = ScmException.class )
159 public void testReCheckoutSubdirectoryOfExistingWorkspaceThrowsException()
160 throws Exception
161 {
162
163 info.setWorkSpace( "someOldStream_someUser" );
164 info.setBasis( "myStream" );
165 info.setTop( basedir.getParentFile().getAbsolutePath() );
166
167 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
168
169 CommandParameters params = new CommandParameters();
170 params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot" ) );
171
172 command.checkout( repo, new ScmFileSet( basedir ), params );
173 fail( "Expected exception" );
174
175 }
176
177 @Test
178 public void testCheckoutToVersionNewWorkspace()
179 throws Exception
180 {
181
182 when( accurev.mkws( "anotherStream", AccuRevCheckOutCommand.getWorkSpaceName( basedir, "anotherStream" ), basedir ) ).thenReturn(
183 true );
184
185 List<File> updatedFiles = Collections.singletonList( new File( "updated/file" ) );
186 when( accurev.update( basedir, "now" ) ).thenReturn( updatedFiles );
187
188 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
189
190 CommandParameters parameters = new CommandParameters();
191 parameters.setScmVersion( CommandParameter.SCM_VERSION, new ScmRevision( "anotherStream/12" ) );
192
193 CheckOutScmResult result = command.checkout( repo, new ScmFileSet( basedir ), parameters );
194
195 assertThat( result.isSuccess(), is( true ) );
196 assertThat( result.getCheckedOutFiles().size(), is( 1 ) );
197
198 }
199
200 @Test
201 public void testCheckoutToVersionExistingWorkspace()
202 throws Exception
203 {
204
205
206 info.setWorkSpace( "someOldStream_someUser" );
207 info.setBasis( "myStream" );
208 info.setTop( basedir.getAbsolutePath() );
209
210 List<File> emptyList = Collections.emptyList();
211
212 when( accurev.pop( basedir, null ) ).thenReturn( emptyList );
213
214 List<File> updatedFiles = Collections.singletonList( new File( "updated/file" ) );
215 when( accurev.update( basedir, "12" ) ).thenReturn( updatedFiles );
216
217 AccuRevCheckOutCommand command = new AccuRevCheckOutCommand( getLogger() );
218
219 CommandParameters parameters = new CommandParameters();
220 parameters.setScmVersion( CommandParameter.SCM_VERSION, new ScmRevision( "myStream/12" ) );
221 CheckOutScmResult result = command.checkout( repo, new ScmFileSet( basedir ), parameters );
222
223 verify( accurev ).pop( basedir, null );
224
225 assertThat( result.isSuccess(), is( true ) );
226 assertThat( result.getCheckedOutFiles().size(), is( 1 ) );
227
228 }
229
230 }