View Javadoc

1   package org.apache.maven.scm.provider.accurev.command.export;
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.apache.maven.scm.ScmFileMatcher.assertHasScmFile;
23  import static org.hamcrest.Matchers.hasItem;
24  import static org.hamcrest.Matchers.is;
25  import static org.hamcrest.Matchers.notNullValue;
26  import static org.junit.Assert.assertThat;
27  import static org.mockito.Matchers.argThat;
28  import static org.mockito.Matchers.eq;
29  import static org.mockito.Mockito.verify;
30  import static org.mockito.Mockito.when;
31  
32  import java.io.File;
33  import java.util.Collection;
34  import java.util.Collections;
35  import java.util.List;
36  
37  import org.apache.maven.scm.CommandParameter;
38  import org.apache.maven.scm.CommandParameters;
39  import org.apache.maven.scm.ScmException;
40  import org.apache.maven.scm.ScmFileSet;
41  import org.apache.maven.scm.ScmFileStatus;
42  import org.apache.maven.scm.ScmTag;
43  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
44  import org.apache.maven.scm.command.export.ExportScmResult;
45  import org.apache.maven.scm.provider.accurev.AccuRevException;
46  import org.apache.maven.scm.provider.accurev.AccuRevScmProvider;
47  import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest;
48  import org.apache.maven.scm.repository.ScmRepository;
49  import org.junit.Test;
50  
51  public class AccuRevExportCommandTest
52      extends AbstractAccuRevCommandTest
53  {
54  
55      @Test
56      public void testExportToVersionPre490()
57          throws Exception
58      {
59       // info defaults to no workspace...
60          info.setWorkSpace( null );
61  
62          when( accurev.info( basedir ) ).thenReturn( info );
63          
64          // A version that does not support pop -t
65          when( accurev.getClientVersion()).thenReturn( "4.7.4b" );
66  
67          List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) );
68          when(
69                accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq( "now" ),
70                                     (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn(
71                                                                                                                           poppedFiles );
72  
73          AccuRevExportCommand command = new AccuRevExportCommand( getLogger() );
74  
75          CommandParameters params = new CommandParameters();
76          params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot/676" ) );
77  
78          ExportScmResult result = command.export( repo, new ScmFileSet( basedir ), params );
79  
80          assertTrue( result.isSuccess() );
81          assertHasScmFile( result.getExportedFiles(), "exported/file", ScmFileStatus.CHECKED_OUT );
82  
83      }
84      
85      @Test
86      public void testExportToVersion490()
87          throws Exception
88      {
89       // info defaults to no workspace...
90          info.setWorkSpace( null );
91  
92          when( accurev.info( basedir ) ).thenReturn( info );
93          
94          // A version that does not support pop -t
95          when( accurev.getClientVersion()).thenReturn( "4.9.0" );
96  
97          List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) );
98          when(
99                accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq( "676" ),
100                                    (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn(
101                                                                                                                          poppedFiles );
102 
103         AccuRevExportCommand command = new AccuRevExportCommand( getLogger() );
104 
105         CommandParameters params = new CommandParameters();
106         params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot/676" ) );
107 
108         ExportScmResult result = command.export( repo, new ScmFileSet( basedir ), params );
109 
110         assertTrue( result.isSuccess() );
111         assertHasScmFile( result.getExportedFiles(), "exported/file", ScmFileStatus.CHECKED_OUT );
112         verify( accurev).syncReplica();
113 
114     }
115     @Test
116     public void testExportVersionOutSideWorkspace()
117         throws Exception
118     {
119 
120         // info defaults to no workspace...
121         info.setWorkSpace( null );
122 
123         when( accurev.info( basedir ) ).thenReturn( info );
124 
125         List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) );
126         when(
127               accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq( (String) null ),
128                                    (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn(
129                                                                                                                          poppedFiles );
130 
131         AccuRevExportCommand command = new AccuRevExportCommand( getLogger() );
132 
133         CommandParameters params = new CommandParameters();
134         params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot" ) );
135 
136         ExportScmResult result = command.export( repo, new ScmFileSet( basedir ), params );
137 
138         assertTrue( result.isSuccess() );
139         assertHasScmFile( result.getExportedFiles(), "exported/file", ScmFileStatus.CHECKED_OUT );
140 
141     }
142 
143     @Test
144     public void testExportFailure()
145         throws Exception
146     {
147 
148         // info defaults to no workspace...
149         info.setWorkSpace( null );
150         when( accurev.info( basedir ) ).thenReturn( info );
151         when( accurev.getClientVersion()).thenReturn( "4.9.0" );
152         when(
153               accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq("544"),
154                                    (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn(
155                                                                                                                          null );
156 
157         AccuRevExportCommand command = new AccuRevExportCommand( getLogger() );
158 
159         CommandParameters params = new CommandParameters();
160         params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot/544"));
161 
162         ExportScmResult result = command.export( repo, new ScmFileSet( basedir ), params );
163 
164         assertThat( result.isSuccess(), is( false ) );
165         assertThat( result.getProviderMessage(), notNullValue() );
166     }
167 
168     @Test
169     public void testNonPersistentWithinExistingWorkspace()
170         throws Exception
171     {
172 
173         // Setup info to return a stream rooted somewhere around here...
174         info.setWorkSpace( "myStream_me" );
175         info.setBasis( "someStream" );
176         info.setTop( basedir.getParent() );
177 
178         when( accurev.info( basedir ) ).thenReturn( info );
179         when( accurev.stat( basedir ) ).thenReturn( null );
180         when( accurev.rmws( "myStream_me" ) ).thenReturn( Boolean.TRUE );
181         List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) );
182         when(
183               accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq( "now" ),
184                                    (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn(
185                                                                                                                          poppedFiles );
186         when( accurev.reactivate( "myStream_me" ) ).thenReturn( Boolean.TRUE );
187 
188         repo.setPersistCheckout( true );
189 
190         AccuRevExportCommand command = new AccuRevExportCommand( getLogger() );
191 
192         CommandParameters params = new CommandParameters();
193         params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot" ) );
194 
195         ExportScmResult result = command.export( repo, new ScmFileSet( basedir ), params );
196 
197         verify( accurev ).rmws( "myStream_me" );
198         verify( accurev ).reactivate( "myStream_me" );
199         assertTrue( result.isSuccess() );
200         // TODO - raise JIRA to move relative path dir to repository rather than checkout result
201         // dassertThat( result.getRelativePathProjectDirectory(), is( "/project/dir" ) );
202 
203     }
204 
205     @Test
206     public void testNonPersistentCheckoutUsesExport()
207         // This is same expectations as above, but using checkout method with setPersist = false.
208         throws AccuRevException, ScmException
209     {
210         // Setup info to return a stream rooted somewhere around here...
211         info.setWorkSpace( "myStream_me" );
212         info.setBasis( "someStream" );
213         info.setTop( basedir.getParent() );
214 
215         when( accurev.info( basedir ) ).thenReturn( info );
216         when( accurev.stat( basedir ) ).thenReturn( null );
217         when( accurev.rmws( "myStream_me" ) ).thenReturn( Boolean.TRUE );
218         List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) );
219         when(
220               accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq( "now" ),
221                                    (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn(
222                                                                                                                          poppedFiles );
223         when( accurev.reactivate( "myStream_me" ) ).thenReturn( Boolean.TRUE );
224 
225         repo.setPersistCheckout( false );
226 
227         ScmRepository scmRepo = new ScmRepository( "accurev", repo );
228 
229         AccuRevScmProvider provider = new AccuRevScmProvider();
230         CheckOutScmResult result = provider.checkOut( scmRepo, new ScmFileSet( basedir ), new ScmTag( "mySnapShot" ) );
231 
232         verify( accurev ).rmws( "myStream_me" );
233         verify( accurev ).reactivate( "myStream_me" );
234 
235         assertTrue( result.isSuccess() );
236 
237     }
238 
239     @Test
240     public void testname()
241         throws Exception
242     {
243         String myString = "Hello " + null;
244         assertThat( myString, is( "Hello null" ) );
245     }
246 }