More junit coverage

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@376168 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Edwin L. Punzalan 2006-02-09 03:19:34 +00:00
parent f04a7ab30f
commit 69ee104b55
4 changed files with 90 additions and 30 deletions

View File

@ -33,8 +33,8 @@ import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.FileInputStream;
@ -218,7 +218,7 @@ public class DefaultProxyManager
{
tries++;
getLogger().info( "trying " + path + " from " + repository.getId() );
getLogger().info( "Trying " + path + " from " + repository.getId() + "...");
wagon.get( path, temp );
@ -238,23 +238,7 @@ public class DefaultProxyManager
}
disconnectWagon( wagon );
if ( !temp.renameTo( target ) )
{
getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." );
try
{
FileUtils.copyFile( temp, target );
}
catch ( IOException e )
{
throw new ProxyException( "Cannot copy tmp file to its final location", e );
}
finally
{
temp.delete();
}
}
copyTempToTarget( temp, target );
return target;
}
@ -371,6 +355,7 @@ public class DefaultProxyManager
* @return true when the checksum succeeds and false when the checksum failed.
*/
private boolean doChecksumCheck( Map checksumMap, String path, Wagon wagon )
throws ProxyException
{
releaseChecksums( wagon, checksumMap );
for ( Iterator checksums = checksumMap.keySet().iterator(); checksums.hasNext(); )
@ -382,7 +367,7 @@ public class DefaultProxyManager
try
{
File tempChecksumFile = new File( checksumFile.getAbsolutePath() + "." + checksumExt );
File tempChecksumFile = new File( checksumFile.getAbsolutePath() + ".tmp" );
wagon.get( checksumPath, tempChecksumFile );
@ -391,7 +376,15 @@ public class DefaultProxyManager
{
remoteChecksum = remoteChecksum.substring( 0, remoteChecksum.indexOf( ' ' ) );
}
return remoteChecksum.toUpperCase().equals( checksum.getActualChecksum().toUpperCase() );
boolean checksumCheck = false;
if ( remoteChecksum.toUpperCase().equals( checksum.getActualChecksum().toUpperCase() ) )
{
copyTempToTarget( tempChecksumFile, checksumFile );
checksumCheck = true;
}
return checksumCheck;
}
catch ( ChecksumFailedException e )
{
@ -399,27 +392,27 @@ public class DefaultProxyManager
}
catch ( TransferFailedException e )
{
getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() );
getLogger().debug( "An error occurred during the download of " + checksumPath + ": " + e.getMessage(), e );
// do nothing try the next checksum
}
catch ( ResourceDoesNotExistException e )
{
getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() );
getLogger().debug( "An error occurred during the download of " + checksumPath + ": " + e.getMessage(), e );
// do nothing try the next checksum
}
catch ( AuthorizationException e )
{
getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() );
getLogger().debug( "An error occurred during the download of " + checksumPath + ": " + e.getMessage(), e );
// do nothing try the next checksum
}
catch ( IOException e )
{
getLogger().info( "An error occurred while reading the temporary checksum file." );
getLogger().debug( "An error occurred while reading the temporary checksum file.", e );
return false;
}
}
getLogger().info( "Skipping checksum validation for " + path + ": No remote checksums available." );
getLogger().debug( "Skipping checksum validation for " + path + ": No remote checksums available." );
return true;
}
@ -461,6 +454,33 @@ public class DefaultProxyManager
return text;
}
private void copyTempToTarget( File temp, File target )
throws ProxyException
{
if ( target.exists() && !target.delete() )
{
throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() );
}
if ( !temp.renameTo( target ) )
{
getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." );
try
{
FileUtils.copyFile( temp, target );
}
catch ( IOException e )
{
throw new ProxyException( "Cannot copy tmp file to its final location", e );
}
finally
{
temp.delete();
}
}
}
/**
* Used to disconnect the wagonManager from its repository
*

View File

@ -62,22 +62,61 @@ public class DefaultProxyManagerTest
}
}
public void testCache()
public void testArtifactDownload()
throws Exception
{
//test download
File file = proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
//test cache
file = proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" );
file = proxy.get( "/not-standard/repository/file.txt" );
try
{
file = proxy.get( "/commons-logging/commons-logging/2.0/commons-logging-2.0.jar" );
fail( "Expected ResourceDoesNotExistException exception not thrown" );
}
catch ( ResourceDoesNotExistException e )
{
assertTrue( true );
}
}
public void testArtifactChecksum()
throws Exception
{
//force the downlod from the remote repository, use getRemoteFile()
File file = proxy.getRemoteFile( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
}
file = proxy.get( "/checksumed-md5/repository/file.txt" );
public void testNonArtifactWithNoChecksum()
throws Exception
{
File file = proxy.get( "/not-standard/repository/file.txt" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
}
public void testNonArtifactWithMD5Checksum()
throws Exception
{
File file = proxy.get( "/checksumed-md5/repository/file.txt" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
}
public void testNonArtifactWithSHA1Checksum()
throws Exception
{
File file = proxy.get( "/checksumed-sha1/repository/file.txt" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );

View File

@ -1 +1 @@
ABCDE
afb037c2bd96fe1ef1cfd220e82682d088d60d3e

View File

@ -0,0 +1 @@
240b26992977c9ad119efb91cb21f8f8