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 private ScmWagon wagon; 050 051 private String providerClassName; 052 053 protected void setUp() 054 throws Exception 055 { 056 super.setUp(); 057 058 FileUtils.deleteDirectory( getCheckoutDirectory() ); 059 060 if ( wagon == null ) 061 { 062 wagon = (ScmWagon) super.getWagon(); 063 064 DefaultScmManager scmManager = (DefaultScmManager) wagon.getScmManager(); 065 066 if ( getScmProvider() != null ) 067 { 068 scmManager.setScmProvider( getScmId(), getScmProvider() ); 069 070 providerClassName = getScmProvider().getClass().getName(); 071 } 072 else 073 { 074 providerClassName = scmManager.getProviderByType( getScmId() ).getClass().getName(); 075 } 076 077 wagon.setCheckoutDirectory( getCheckoutDirectory() ); 078 } 079 } 080 081 /** 082 * Allows overriding the {@link ScmProvider} injected by default in the {@link ScmWagon}. 083 * Useful to force the implementation to use for a particular SCM type. 084 * If this method returns <code>null</code> {@link ScmWagon} will use the default {@link ScmProvider}. 085 * 086 * @return the {@link ScmProvider} to use in the {@link ScmWagon} 087 */ 088 protected ScmProvider getScmProvider() 089 { 090 return null; 091 } 092 093 @Override 094 protected int getTestRepositoryPort() 095 { 096 return 0; // not used 097 } 098 099 protected Wagon getWagon() 100 throws Exception 101 { 102 return wagon; 103 } 104 105 private File getCheckoutDirectory() 106 { 107 return new File( FileTestUtils.getTestOutputDir(), "/checkout-" + providerClassName ); 108 } 109 110 protected int getExpectedContentLengthOnGet( int expectedSize ) 111 { 112 return WagonConstants.UNKNOWN_LENGTH; 113 } 114 115 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource ) 116 { 117 return 0; 118 } 119 120 /** 121 * The SCM id, eg. <code>svn</code>, <code>cvs</code> 122 * 123 * @return the SCM id 124 */ 125 protected abstract String getScmId(); 126 127 protected String getProtocol() 128 { 129 return "scm"; 130 } 131 132 protected void createDirectory( Wagon wagon, String resourceToCreate, String dirName ) 133 throws Exception 134 { 135 super.createDirectory( wagon, resourceToCreate, dirName ); 136 FileUtils.deleteDirectory( getCheckoutDirectory() ); 137 } 138 139 protected void assertResourcesAreInRemoteSide( Wagon wagon, List<String> resourceNames ) 140 throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException 141 { 142 FileUtils.deleteDirectory( getCheckoutDirectory() ); 143 super.assertResourcesAreInRemoteSide( wagon, resourceNames ); 144 } 145}