001package org.apache.maven.wagon.providers.scm; 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 org.apache.maven.scm.manager.plexus.DefaultScmManager; 023import org.apache.maven.scm.provider.ScmProvider; 024import org.apache.maven.wagon.FileTestUtils; 025import org.apache.maven.wagon.ResourceDoesNotExistException; 026import org.apache.maven.wagon.TransferFailedException; 027import org.apache.maven.wagon.Wagon; 028import org.apache.maven.wagon.WagonConstants; 029import org.apache.maven.wagon.WagonTestCase; 030import org.apache.maven.wagon.authorization.AuthorizationException; 031import org.apache.maven.wagon.repository.Repository; 032import org.apache.maven.wagon.resource.Resource; 033import org.codehaus.plexus.util.FileUtils; 034 035import java.io.File; 036import java.io.IOException; 037import java.util.List; 038 039/** 040 * Test for {@link ScmWagon}. You need a subclass for each SCM provider you want to test. 041 * 042 * @author <a href="carlos@apache.org">Carlos Sanchez</a> 043 * 044 */ 045public abstract class AbstractScmWagonTest 046 extends WagonTestCase 047{ 048 049 @Override 050 public void testWagonPutDirectory() throws Exception 051 { 052 super.testWagonPutDirectory(); 053 // repeat the test on a non-empty repo 054 // ScmWagon should checkout all involved subdirs before calling 055 // FileUtils.copyDirectoryStructure() 056 super.testWagonPutDirectory(); 057 } 058 059 private ScmWagon wagon; 060 061 private String providerClassName; 062 063 protected void setUp() 064 throws Exception 065 { 066 super.setUp(); 067 068 FileUtils.deleteDirectory( getCheckoutDirectory() ); 069 070 if ( wagon == null ) 071 { 072 wagon = (ScmWagon) super.getWagon(); 073 074 DefaultScmManager scmManager = (DefaultScmManager) wagon.getScmManager(); 075 076 if ( getScmProvider() != null ) 077 { 078 scmManager.setScmProvider( getScmId(), getScmProvider() ); 079 080 providerClassName = getScmProvider().getClass().getName(); 081 } 082 else 083 { 084 providerClassName = scmManager.getProviderByType( getScmId() ).getClass().getName(); 085 } 086 087 wagon.setCheckoutDirectory( getCheckoutDirectory() ); 088 } 089 } 090 091 /** 092 * Allows overriding the {@link ScmProvider} injected by default in the {@link ScmWagon}. 093 * Useful to force the implementation to use for a particular SCM type. 094 * If this method returns <code>null</code> {@link ScmWagon} will use the default {@link ScmProvider}. 095 * 096 * @return the {@link ScmProvider} to use in the {@link ScmWagon} 097 */ 098 protected ScmProvider getScmProvider() 099 { 100 return null; 101 } 102 103 protected Wagon getWagon() 104 throws Exception 105 { 106 return wagon; 107 } 108 109 private File getCheckoutDirectory() 110 { 111 return new File( FileTestUtils.getTestOutputDir(), "/checkout-" + providerClassName ); 112 } 113 114 protected int getExpectedContentLengthOnGet( int expectedSize ) 115 { 116 return WagonConstants.UNKNOWN_LENGTH; 117 } 118 119 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource ) 120 { 121 return 0; 122 } 123 124 /** 125 * The SCM id, eg. <code>svn</code>, <code>cvs</code> 126 * 127 * @return the SCM id 128 */ 129 protected abstract String getScmId(); 130 131 protected String getProtocol() 132 { 133 return "scm"; 134 } 135 136 protected void createDirectory( Wagon wagon, String resourceToCreate, String dirName ) 137 throws Exception 138 { 139 super.createDirectory( wagon, resourceToCreate, dirName ); 140 FileUtils.deleteDirectory( getCheckoutDirectory() ); 141 } 142 143 protected void assertResourcesAreInRemoteSide( Wagon wagon, List<String> resourceNames ) 144 throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException 145 { 146 FileUtils.deleteDirectory( getCheckoutDirectory() ); 147 super.assertResourcesAreInRemoteSide( wagon, resourceNames ); 148 } 149}