enhance/fix tests, and make resolver work correctly when at least one repo is good out of a list

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@162989 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2004-08-17 20:58:29 +00:00
parent 059a3f888c
commit 36f1e02099
3 changed files with 100 additions and 22 deletions

View File

@ -126,6 +126,9 @@ public class DefaultWagonManager
* If we won't plug validation process here the question is what we can do afterwards?
* We don't know from which ArtifactRepository artifact was fetched and where we should restart.
* We should be also fetching md5 sums and such from the same exact directory then artifacts
* <p/>
* @todo probably all exceptions should just be logged and continue
* @todo is the exception for warnings logged at debug level correct?
*/
public void get( Artifact artifact, File destination, Set repositories )
throws TransferFailedException
@ -194,6 +197,12 @@ public class DefaultWagonManager
{
throw new TransferFailedException( "Authorization failed: ", e );
}
catch ( TransferFailedException e )
{
getLogger().warn( "Failure getting artifact from repository '" + repository + "'" + e );
getLogger().debug( "Stack trace", e );
continue;
}
catch ( Exception e )
{
throw new TransferFailedException( "Release of wagon failed: ", e );
@ -227,7 +236,7 @@ public class DefaultWagonManager
return;
}
throw new TransferFailedException( "Resource doesn't exist in any remote repository" );
throw new TransferFailedException( "Unable to download the artifact from any repository" );
}
public void contextualize( Context context )

View File

@ -1,15 +1,3 @@
package org.apache.maven.artifact;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
import java.io.Writer;
import java.io.FileWriter;
import java.util.Set;
import java.util.HashSet;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@ -26,6 +14,19 @@ import java.util.HashSet;
* limitations under the License.
*/
package org.apache.maven.artifact;
import org.codehaus.plexus.PlexusTestCase;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Set;
import java.util.HashSet;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -56,11 +57,20 @@ public abstract class ArtifactComponentTestCase
protected ArtifactRepository remoteRepository()
{
ArtifactRepository localRepository = new ArtifactRepository();
ArtifactRepository repository = new ArtifactRepository();
localRepository.setUrl( "file://" + "target/test-classes/repositories/" + component() + "/remote-repository" );
repository.setUrl( "file://" + "target/test-classes/repositories/" + component() + "/remote-repository" );
return localRepository;
return repository;
}
protected ArtifactRepository badRemoteRepository()
{
ArtifactRepository repository = new ArtifactRepository();
repository.setUrl( "http://foo.bar/repository" );
return repository;
}
protected void assertRemoteArtifactPresent( Artifact artifact )
@ -71,7 +81,7 @@ public abstract class ArtifactComponentTestCase
if ( !file.exists() )
{
fail( "Local artifact " + file + " should be present." );
fail( "Remote artifact " + file + " should be present." );
}
}
@ -83,7 +93,7 @@ public abstract class ArtifactComponentTestCase
if ( !file.exists() )
{
fail( "Remote artifact " + file + " should be present." );
fail( "Local artifact " + file + " should be present." );
}
}
@ -95,7 +105,7 @@ public abstract class ArtifactComponentTestCase
if ( file.exists() )
{
fail( "Local artifact " + file + " should not be present." );
fail( "Remote artifact " + file + " should not be present." );
}
}
@ -107,7 +117,7 @@ public abstract class ArtifactComponentTestCase
if ( file.exists() )
{
fail( "Remote artifact " + file + " should not be present." );
fail( "Local artifact " + file + " should not be present." );
}
}
@ -188,4 +198,27 @@ public abstract class ArtifactComponentTestCase
{
return new DefaultArtifact( "maven", artifactId, version, type );
}
protected void deleteLocalArtifact( Artifact artifact )
throws Exception
{
deleteArtifact( artifact, localRepository() );
}
protected void deleteArtifact( Artifact artifact, ArtifactRepository repository )
throws Exception
{
String path = artifactHandlerManager.path( artifact );
File artifactFile = new File( repository.getBasedir(), path );
if ( artifactFile.exists() )
{
if ( !artifactFile.delete() )
{
throw new IOException( "Failure while attempting to delete artifact " + artifactFile );
}
}
}
}

View File

@ -72,7 +72,8 @@ public class ArtifactResolverTest
public void testResolutionOfASingleArtifactWhereTheArtifactIsNotPresentLocallyAndMustBeRetrievedFromTheRemoteRepository()
throws Exception
{
Artifact b = createLocalArtifact( "b", "1.0" );
Artifact b = createRemoteArtifact( "b", "1.0" );
deleteLocalArtifact( b );
artifactResolver.resolve( b, remoteRepositories(), localRepository() );
@ -110,8 +111,10 @@ public class ArtifactResolverTest
Set artifacts = new HashSet();
Artifact e = createRemoteArtifact( "e", "1.0" );
deleteLocalArtifact( e );
Artifact f = createRemoteArtifact( "f", "1.0" );
deleteLocalArtifact( f );
artifacts.add( e );
@ -180,8 +183,10 @@ public class ArtifactResolverTest
throws Exception
{
Artifact i = createRemoteArtifact( "i", "1.0" );
deleteLocalArtifact( i );
Artifact j = createRemoteArtifact( "j", "1.0" );
deleteLocalArtifact( j );
ArtifactMetadataSource mds = new ArtifactMetadataSource()
{
@ -221,4 +226,35 @@ public class ArtifactResolverTest
assertLocalArtifactPresent( j );
}
}
public void testResolutionFailureWhenArtifactNotPresentInRemoteRepository()
{
Artifact k = createArtifact( "k", "1.0" );
try
{
artifactResolver.resolve( k, remoteRepositories(), localRepository() );
fail( "Resolution succeeded when it should have failed" );
}
catch ( ArtifactResolutionException expected )
{
assertTrue( true );
}
}
public void testResolutionOfAnArtifactWhereOneRemoteRepositoryIsBadButOneIsGood()
throws Exception
{
Artifact l = createRemoteArtifact( "l", "1.0" );
deleteLocalArtifact( l );
Set repositories = new HashSet();
repositories.add( remoteRepository() );
repositories.add( badRemoteRepository() );
artifactResolver.resolve( l, repositories, localRepository() );
assertLocalArtifactPresent( l );
}
}