001package org.apache.maven.scm.provider.accurev.command.export; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.apache.maven.scm.ScmFileMatcher.assertHasScmFile; 023import static org.hamcrest.Matchers.hasItem; 024import static org.hamcrest.Matchers.is; 025import static org.hamcrest.Matchers.notNullValue; 026import static org.junit.Assert.assertThat; 027import static org.mockito.Matchers.argThat; 028import static org.mockito.Matchers.eq; 029import static org.mockito.Mockito.verify; 030import static org.mockito.Mockito.when; 031 032import java.io.File; 033import java.util.Collection; 034import java.util.Collections; 035import java.util.List; 036 037import org.apache.maven.scm.CommandParameter; 038import org.apache.maven.scm.CommandParameters; 039import org.apache.maven.scm.ScmException; 040import org.apache.maven.scm.ScmFileSet; 041import org.apache.maven.scm.ScmFileStatus; 042import org.apache.maven.scm.ScmTag; 043import org.apache.maven.scm.command.checkout.CheckOutScmResult; 044import org.apache.maven.scm.command.export.ExportScmResult; 045import org.apache.maven.scm.provider.accurev.AccuRevException; 046import org.apache.maven.scm.provider.accurev.AccuRevScmProvider; 047import org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest; 048import org.apache.maven.scm.repository.ScmRepository; 049import org.junit.Test; 050 051public class AccuRevExportCommandTest 052 extends AbstractAccuRevCommandTest 053{ 054 055 @Test 056 public void testExportToVersionPre490() 057 throws Exception 058 { 059 // info defaults to no workspace... 060 info.setWorkSpace( null ); 061 062 when( accurev.info( basedir ) ).thenReturn( info ); 063 064 // A version that does not support pop -t 065 when( accurev.getClientVersion()).thenReturn( "4.7.4b" ); 066 067 List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) ); 068 when( 069 accurev.popExternal( eq( basedir ), eq( "mySnapShot" ), eq( "now" ), 070 (Collection<File>) argThat( hasItem( new File( "/./project/dir" ) ) ) ) ).thenReturn( 071 poppedFiles ); 072 073 AccuRevExportCommand command = new AccuRevExportCommand( getLogger() ); 074 075 CommandParameters params = new CommandParameters(); 076 params.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( "mySnapShot/676" ) ); 077 078 ExportScmResult result = command.export( repo, new ScmFileSet( basedir ), params ); 079 080 assertTrue( result.isSuccess() ); 081 assertHasScmFile( result.getExportedFiles(), "exported/file", ScmFileStatus.CHECKED_OUT ); 082 083 } 084 085 @Test 086 public void testExportToVersion490() 087 throws Exception 088 { 089 // info defaults to no workspace... 090 info.setWorkSpace( null ); 091 092 when( accurev.info( basedir ) ).thenReturn( info ); 093 094 // A version that does not support pop -t 095 when( accurev.getClientVersion()).thenReturn( "4.9.0" ); 096 097 List<File> poppedFiles = Collections.singletonList( new File( "exported/file" ) ); 098 when( 099 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}