o workspace tests

Submitted by: Igor Fedorenko

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@777301 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-21 22:41:39 +00:00
parent b54a1b781b
commit 44c864a463
2 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,83 @@
package org.apache.maven.repository.ideworkspace;
import java.io.File;
import java.util.ArrayList;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.PlexusTestCase;
public class IdeWorkspaceRepositoryTest
extends PlexusTestCase
{
private RepositorySystem repositorySystem;
private ArtifactRepository localRepository;
@Override
protected void setUp()
throws Exception
{
super.setUp();
repositorySystem = lookup( RepositorySystem.class );
localRepository = repositorySystem.createLocalRepository( new File( "target/IdeWorkspaceRepositoryTest" ).getCanonicalFile() );
}
@Override
protected void tearDown()
throws Exception
{
repositorySystem = null;
localRepository = null;
super.tearDown();
}
public void testResolveFromWorkspace()
throws Exception
{
Artifact artifact =
repositorySystem.createArtifact( TestIdeWorkspaceRepository.GROUP_ID, TestIdeWorkspaceRepository.ARTIFACT_ID,
TestIdeWorkspaceRepository.VERSION, "jar" );
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact( artifact );
request.setLocalRepository( localRepository );
request.setRemoteRepostories( new ArrayList<ArtifactRepository>() );
repositorySystem.resolve( request );
assertTrue( artifact.isResolved() );
assertEquals( TestIdeWorkspaceRepository.ARTIFACT_FILE, artifact.getFile() );
assertSame( localRepository, request.getLocalRepository() );
}
public void testDelegatingLocalRepo()
throws Exception
{
Artifact artifact =
repositorySystem.createArtifact( TestIdeWorkspaceRepository.GROUP_ID, TestIdeWorkspaceRepository.ARTIFACT_ID,
TestIdeWorkspaceRepository.VERSION, "jar" );
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository = new DelegatingLocalArtifactRepository( localRepository );
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact( artifact );
request.setLocalRepository( delegatingLocalArtifactRepository );
request.setRemoteRepostories( new ArrayList<ArtifactRepository>() );
repositorySystem.resolve( request );
assertTrue( artifact.isResolved() );
assertEquals( TestIdeWorkspaceRepository.ARTIFACT_FILE, artifact.getFile() );
// make sure we restore original repository
assertSame( delegatingLocalArtifactRepository, request.getLocalRepository() );
assertNull( delegatingLocalArtifactRepository.getIdeWorspace() );
}
}

View File

@ -0,0 +1,46 @@
package org.apache.maven.repository.ideworkspace;
import java.io.File;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.repository.LocalArtifactRepository;
import org.codehaus.plexus.component.annotations.Component;
@Component( role = LocalArtifactRepository.class, hint = LocalArtifactRepository.IDE_WORKSPACE )
public class TestIdeWorkspaceRepository
extends LocalArtifactRepository
{
public static final String GROUP_ID = "test";
public static final String ARTIFACT_ID = "test";
public static final String VERSION = "1.0.0-SNAPSHOT";
public static final File ARTIFACT_FILE = new File( "/a/b/c/d" );
@Override
public Artifact find( Artifact artifact )
{
if ( GROUP_ID.equals( artifact.getGroupId() ) && ARTIFACT_ID.equals( artifact.getArtifactId() )
&& VERSION.equals( artifact.getVersion() ) )
{
artifact.setFile( ARTIFACT_FILE );
artifact.setResolved( true );
}
return artifact;
}
@Override
public boolean hasLocalMetadata()
{
return false;
}
@Override
public boolean isAuthoritative()
{
return true;
}
}