more legacy discoverer tests

PR: MRM-9

git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@349655 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2005-11-29 05:36:41 +00:00
parent 7b61ac8764
commit 31af359ff4
9 changed files with 113 additions and 17 deletions

View File

@ -18,7 +18,6 @@ package org.apache.maven.repository.discovery;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
@ -144,6 +143,13 @@ public class LegacyArtifactDiscoverer
return null;
}
}
else
{
// no extension
addKickedOutPath( path );
return null;
}
}
// TODO: this is obscene - surely a better way?
@ -281,7 +287,9 @@ public class LegacyArtifactDiscoverer
if ( version.length() < 1 )
{
version = null;
addKickedOutPath( path );
return null;
}
getLogger().debug( "Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n" +
@ -299,17 +307,10 @@ public class LegacyArtifactDiscoverer
}
else
{
if ( StringUtils.isNotEmpty( groupId ) && StringUtils.isNotEmpty( artifactId ) &&
StringUtils.isNotEmpty( version ) && StringUtils.isNotEmpty( type ) )
{
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type );
}
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type );
}
if ( result != null )
{
result.setFile( new File( path ) );
}
result.setFile( new File( path ) );
return result;
}

View File

@ -119,7 +119,7 @@ public class LegacyArtifactDiscovererTest
found = path.replace( '\\', '/' ).equals( "invalid/invalid-1.0.jar" );
}
assertTrue( "Check exclusion was found", found );
assertTrue( "Check kickout was found", found );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
@ -139,7 +139,7 @@ public class LegacyArtifactDiscovererTest
found = path.replace( '\\', '/' ).equals( "invalid/jars/1.0/invalid-1.0.jar" );
}
assertTrue( "Check exclusion was found", found );
assertTrue( "Check kickout was found", found );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
@ -159,7 +159,7 @@ public class LegacyArtifactDiscovererTest
found = path.replace( '\\', '/' ).equals( "invalid/foo/invalid-1.0.foo" );
}
assertTrue( "Check exclusion was found", found );
assertTrue( "Check kickout was found", found );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
@ -168,6 +168,66 @@ public class LegacyArtifactDiscovererTest
}
}
public void testKickoutWithNoExtension()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
found = path.replace( '\\', '/' ).equals( "invalid/jars/no-extension" );
}
assertTrue( "Check kickout was found", found );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
assertFalse( "Check not 'no-extension'", a.getFile().getName().equals( "no-extension" ) );
}
}
public void testKickoutWithWrongExtension()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
found = path.replace( '\\', '/' ).equals( "invalid/jars/invalid-1.0.rar" );
}
assertTrue( "Check kickout was found", found );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
assertFalse( "Check not 'invalid-1.0.rar'", a.getFile().getName().equals( "invalid-1.0.rar" ) );
}
}
public void testKickoutWithNoVersion()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, false );
assertNotNull( "Check artifacts not null", artifacts );
boolean found = false;
for ( Iterator i = discoverer.getKickedOutPathsIterator(); i.hasNext() && !found; )
{
String path = (String) i.next();
found = path.replace( '\\', '/' ).equals( "invalid/jars/invalid.jar" );
}
assertTrue( "Check kickout was found", found );
for ( Iterator i = artifacts.iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
assertFalse( "Check not 'invalid.jar'", a.getFile().getName().equals( "invalid.jar" ) );
}
}
public void testInclusion()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
@ -177,13 +237,43 @@ public class LegacyArtifactDiscovererTest
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0" ) ) );
}
public void testTextualVersion()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
artifacts.contains( createArtifact( "org.apache.maven", "testing", "UNKNOWN" ) ) );
}
public void testArtifactWithClassifier()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
artifacts.contains( createArtifact( "org.apache.maven", "some-ejb", "1.0", "jar", "client" ) ) );
}
public void testJavaSourcesInclusion()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check normal included",
artifacts.contains( createSourceArtifact( "org.apache.maven", "testing", "1.0" ) ) );
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "java-source" ) ) );
}
public void testDistributionInclusion()
{
List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true );
assertNotNull( "Check artifacts not null", artifacts );
assertTrue( "Check zip included",
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-zip" ) ) );
assertTrue( "Check tar.gz included",
artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "distribution-tgz" ) ) );
}
public void testSnapshotInclusion()
@ -211,9 +301,14 @@ public class LegacyArtifactDiscovererTest
return factory.createArtifact( groupId, artifactId, version, null, "jar" );
}
private Artifact createSourceArtifact( String groupId, String artifactId, String version )
private Artifact createArtifact( String groupId, String artifactId, String version, String type )
{
return factory.createArtifact( groupId, artifactId, version, null, "java-source" );
return factory.createArtifact( groupId, artifactId, version, null, type );
}
private Artifact createArtifact( String groupId, String artifactId, String version, String type, String classifier )
{
return factory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
}
}