aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2006-09-05 07:00:52 +0000
committerBrett Porter <brett@apache.org>2006-09-05 07:00:52 +0000
commit63c171e2eb136117115bc2f964d92c8a30480d6e (patch)
tree5a802f4e4eae01cda1374229a75a87b99e96b1f5
parentd29cdf4ab1f77b962802f92f9d94c707fbb39037 (diff)
downloadarchiva-63c171e2eb136117115bc2f964d92c8a30480d6e.tar.gz
archiva-63c171e2eb136117115bc2f964d92c8a30480d6e.zip
[MRM-161] move the query layer tests, remove unnecessary mocks, and fix tests to test legitimate things. Remove tests for null artifact ids, etc since it is impossible that they would be created with a normal (non-mock) API and the reporting will get these errors fed through from the file positioning and model validation errors instead
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@440282 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java2
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java23
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java31
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java123
-rw-r--r--archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java2
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java373
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java68
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java3
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/GenericMockObject.java62
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifact.java258
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactFactory.java92
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactReportProcessor.java80
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockRepositoryQueryLayer.java80
-rw-r--r--archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ReportCondition.java74
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayer.java106
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java56
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java70
-rw-r--r--archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/RepositoryQueryLayer.java6
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayerTestCase.java (renamed from archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryQueryLayerTestCase.java)53
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CacheTest.java (renamed from archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/CacheTest.java)3
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java (renamed from archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/CachedRepositoryQueryLayerTest.java)25
-rw-r--r--archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayerTest.java29
-rw-r--r--archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jarbin0 -> 45568 bytes
-rw-r--r--archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom6
-rw-r--r--archiva-repository-layer/src/test/repository/groupId/artifactId/maven-metadata.xml26
-rw-r--r--archiva-repository-layer/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom0
26 files changed, 336 insertions, 1315 deletions
diff --git a/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java b/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java
index 35681ea65..271f97a09 100644
--- a/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java
+++ b/archiva-core/src/main/java/org/apache/maven/archiva/DefaultRepositoryManager.java
@@ -49,7 +49,7 @@ public class DefaultRepositoryManager
private RepositoryConverter repositoryConverter;
/**
- * @plexus.requirement role-hint="default"
+ * @plexus.requirement
*/
private ArtifactReporter reporter;
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java
index dab65753c..d9bfcc7c3 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/ArtifactReporter.java
@@ -28,34 +28,19 @@ import java.util.Iterator;
* failures and successes for checking assertions. Later, implementations will be made to present reports on the
* web interface, send them via mail, and so on.
*
- * @todo i18n
+ * @todo i18n, including message formatting and parameterisation
+ * @todo remove no longer used reports!
*/
public interface ArtifactReporter
{
String ROLE = ArtifactReporter.class.getName();
- String NULL_MODEL = "Provided model was null";
-
- String NULL_ARTIFACT = "Provided artifact was null";
-
- String EMPTY_GROUP_ID = "Group id was empty or null";
-
- String EMPTY_ARTIFACT_ID = "Artifact id was empty or null";
-
- String EMPTY_VERSION = "Version was empty or null";
-
- String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null";
-
- String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null";
-
- String EMPTY_DEPENDENCY_VERSION = "Version was empty or null";
-
- String NO_DEPENDENCIES = "Artifact has no dependencies";
-
String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository";
String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository";
+ String DEPENDENCY_INVALID_VERSION = "Artifact's dependency contains an invalid version";
+
void addFailure( Artifact artifact, String reason );
void addSuccess( Artifact artifact );
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
index 733524002..7ba79b61a 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessor.java
@@ -212,13 +212,16 @@ public class BadMetadataReportProcessor
boolean hasFailures = false;
Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
- String timestamp = snapshot.getTimestamp();
- String buildNumber = String.valueOf( snapshot.getBuildNumber() );
- Artifact artifact = createArtifact( metadata );
- if ( !repositoryQueryLayer.containsArtifact( artifact, snapshot ) )
+ String version = metadata.getBaseVersion().replace( Artifact.SNAPSHOT_VERSION,
+ snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
+ Artifact artifact =
+ artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
+ artifact.isSnapshot(); // trigger baseVersion correction
+
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
- reporter.addFailure( metadata, "Snapshot artifact " + timestamp + "-" + buildNumber + " does not exist." );
+ reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
hasFailures = true;
}
@@ -244,7 +247,8 @@ public class BadMetadataReportProcessor
{
String version = (String) versions.next();
- Artifact artifact = createArtifact( metadata, version );
+ Artifact artifact =
+ artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
@@ -287,20 +291,9 @@ public class BadMetadataReportProcessor
return hasFailures;
}
- /**
- * Used to create an artifact object from a metadata base version
- */
- private Artifact createArtifact( RepositoryMetadata metadata )
- {
- return artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(),
- metadata.getBaseVersion() );
- }
-
- /**
- * Used to create an artifact object with a specified version
- */
- private Artifact createArtifact( RepositoryMetadata metadata, String version )
+ private Artifact createArtifact( RepositoryMetadata metadata, Snapshot snapshot )
{
+ String version = metadata.getBaseVersion();
return artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java
index 22e220a66..b9fd36dd7 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReportProcessor.java
@@ -17,9 +17,12 @@ package org.apache.maven.archiva.reporting;
*/
import org.apache.maven.archiva.layer.RepositoryQueryLayer;
+import org.apache.maven.archiva.layer.RepositoryQueryLayerFactory;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
@@ -32,94 +35,54 @@ import java.util.List;
public class DefaultArtifactReportProcessor
implements ArtifactReportProcessor
{
- private static final String EMPTY_STRING = "";
-
- // plexus components
+ /**
+ * @plexus.requirement
+ */
private ArtifactFactory artifactFactory;
- private RepositoryQueryLayer repositoryQueryLayer;
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryQueryLayerFactory layerFactory;
public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
ArtifactRepository repository )
{
- if ( artifact == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT );
- }
- else
- {
- processArtifact( artifact, reporter );
- }
+ RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository );
+ processArtifact( artifact, reporter, queryLayer );
- if ( model == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL );
- }
- else
- {
- List dependencies = model.getDependencies();
- processDependencies( dependencies, reporter );
- }
+ List dependencies = model.getDependencies();
+ processDependencies( dependencies, reporter, queryLayer );
}
- private void processArtifact( Artifact artifact, ArtifactReporter reporter )
+ private void processArtifact( Artifact artifact, ArtifactReporter reporter,
+ RepositoryQueryLayer repositoryQueryLayer )
{
- boolean hasFailed = false;
- if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null )
+ if ( repositoryQueryLayer.containsArtifact( artifact ) )
{
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID );
- hasFailed = true;
+ reporter.addSuccess( artifact );
}
- if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID );
- hasFailed = true;
- }
- if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null )
+ else
{
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION );
- hasFailed = true;
- }
- if ( !hasFailed )
- {
- if ( repositoryQueryLayer.containsArtifact( artifact ) )
- {
- reporter.addSuccess( artifact );
- }
- else
- {
- reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
- }
+ reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
}
}
- private void processDependencies( List dependencies, ArtifactReporter reporter )
+ private void processDependencies( List dependencies, ArtifactReporter reporter,
+ RepositoryQueryLayer repositoryQueryLayer )
{
if ( dependencies.size() > 0 )
{
Iterator iterator = dependencies.iterator();
while ( iterator.hasNext() )
{
- boolean hasFailed = false;
Dependency dependency = (Dependency) iterator.next();
- Artifact artifact = createArtifact( dependency );
- if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID );
- hasFailed = true;
- }
- if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID );
- hasFailed = true;
- }
- if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION );
- hasFailed = true;
- }
- if ( !hasFailed )
+
+ Artifact artifact = null;
+ try
{
+ artifact = createArtifact( dependency );
+
if ( repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addSuccess( artifact );
@@ -129,34 +92,20 @@ public class DefaultArtifactReportProcessor
reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
}
}
+ catch ( InvalidVersionSpecificationException e )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION );
+ }
}
}
-
- }
-
- /**
- * Only used for passing a mock object when unit testing
- *
- * @param repositoryQueryLayer
- */
- protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer )
- {
- this.repositoryQueryLayer = repositoryQueryLayer;
- }
-
- /**
- * Only used for passing a mock object when unit testing
- *
- * @param artifactFactory
- */
- protected void setArtifactFactory( ArtifactFactory artifactFactory )
- {
- this.artifactFactory = artifactFactory;
}
private Artifact createArtifact( Dependency dependency )
+ throws InvalidVersionSpecificationException
{
- return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(),
- dependency.getVersion(), "pom" );
+ return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
+ VersionRange.createFromVersionSpec( dependency.getVersion() ),
+ dependency.getType(), dependency.getClassifier(),
+ dependency.getScope() );
}
}
diff --git a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java
index d70e77144..7c10eb4e6 100644
--- a/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java
+++ b/archiva-reports-standard/src/main/java/org/apache/maven/archiva/reporting/DefaultArtifactReporter.java
@@ -24,7 +24,7 @@ import java.util.Iterator;
import java.util.List;
/**
- * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReporter" role-hint="default"
+ * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReporter"
*/
public class DefaultArtifactReporter
implements ArtifactReporter
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java
index f1e245368..1b3d60759 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReportProcessorTest.java
@@ -17,6 +17,7 @@ package org.apache.maven.archiva.reporting;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
@@ -28,77 +29,53 @@ import java.util.Iterator;
public class ArtifactReportProcessorTest
extends AbstractRepositoryReportsTestCase
{
- private static final String EMPTY_STRING = "";
+ private static final String VALID_GROUP_ID = "groupId";
- private static final String VALID = "temp";
+ private static final String VALID_ARTIFACT_ID = "artifactId";
- private ArtifactReporter reporter;
+ private static final String VALID_VERSION = "1.0-alpha-1";
- private Artifact artifact;
+ private ArtifactReporter reporter;
private Model model;
- private DefaultArtifactReportProcessor processor;
+ private ArtifactReportProcessor processor;
- private static final boolean ARTIFACT_FOUND = true;
+ private ArtifactFactory artifactFactory;
- private static final boolean ARTIFACT_NOT_FOUND = false;
+ private static final String INVALID = "invalid";
protected void setUp()
throws Exception
{
super.setUp();
- reporter = new DefaultArtifactReporter();
- artifact = new MockArtifact();
+ reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
model = new Model();
- processor = new DefaultArtifactReportProcessor();
- }
+ processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "default" );
- public void testNullArtifact()
- {
- processor.processArtifact( model, null, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.NULL_ARTIFACT, result.getReason() );
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
}
- public void testNoProjectDescriptor()
+ public void testArtifactFoundButNoDirectDependencies()
+ throws ReportProcessorException
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.processArtifact( null, artifact, reporter, null );
+ Artifact artifact = createValidArtifact();
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.NULL_MODEL, result.getReason() );
}
- public void testArtifactFoundButNoDirectDependencies()
+ private Artifact createValidArtifact()
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 0, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
+ return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
}
public void testArtifactNotFound()
+ throws ReportProcessorException
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_NOT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
+ Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 0, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
@@ -108,100 +85,67 @@ public class ArtifactReportProcessorTest
}
public void testValidArtifactWithNullDependency()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 2, reporter.getNumSuccesses() );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
- public void testValidArtifactWithValidSingleDependency()
+ private Dependency createValidDependency()
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ return createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
+ }
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
+ public void testValidArtifactWithValidSingleDependency()
+ throws ReportProcessorException
+ {
+ Artifact artifact = createValidArtifact();
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 2, reporter.getNumSuccesses() );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithValidMultipleDependencies()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
-
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ Artifact artifact = createValidArtifact();
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 6, reporter.getNumSuccesses() );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithAnInvalidDependency()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
-
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
- model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_NOT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( createDependency( INVALID, INVALID, INVALID ) );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ Artifact artifact = createValidArtifact();
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 5, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
@@ -211,253 +155,84 @@ public class ArtifactReportProcessorTest
assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testEmptyGroupId()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, EMPTY_STRING, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
- }
-
- public void testEmptyArtifactId()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, VALID, EMPTY_STRING, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
- }
-
- public void testEmptyVersion()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, VALID, VALID, EMPTY_STRING );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
- }
-
- public void testNullGroupId()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, null, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
- }
-
- public void testNullArtifactId()
+ public void testValidArtifactWithInvalidDependencyGroupId()
+ throws ReportProcessorException
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, VALID, null, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
- }
+ Artifact artifact = createValidArtifact();
- public void testNullVersion()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
+ Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION );
+ model.addDependency( dependency );
- setRequiredElements( artifact, VALID, VALID, null );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
+ processor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
- }
-
- public void testMultipleFailures()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, null, null, null );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 3, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testValidArtifactWithInvalidDependencyGroupId()
+ private Dependency createDependency( String o, String valid, String s )
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
-
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
Dependency dependency = new Dependency();
- setRequiredElements( dependency, null, VALID, VALID );
- model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
+ dependency.setGroupId( o );
+ dependency.setArtifactId( valid );
+ dependency.setVersion( s );
+ return dependency;
}
public void testValidArtifactWithInvalidDependencyArtifactId()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, null, VALID );
+ Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testValidArtifactWithInvalidDependencyVersion()
+ public void testValidArtifactWithIncorrectDependencyVersion()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, null );
+ Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testValidArtifactWithInvalidDependencyRequiredElements()
+ public void testValidArtifactWithInvalidDependencyVersion()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, null, null, null );
+ Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 3, reporter.getNumFailures() );
+ assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
- }
-
- protected void tearDown()
- throws Exception
- {
- model = null;
- artifact = null;
- reporter = null;
- super.tearDown();
- }
-
- private void setRequiredElements( Artifact artifact, String groupId, String artifactId, String version )
- {
- artifact.setGroupId( groupId );
- artifact.setArtifactId( artifactId );
- artifact.setVersion( version );
- }
-
- private void setRequiredElements( Dependency dependency, String groupId, String artifactId, String version )
- {
- dependency.setGroupId( groupId );
- dependency.setArtifactId( artifactId );
- dependency.setVersion( version );
+ assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() );
}
}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java
index 80a09f72d..71bcffca3 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ArtifactReporterTest.java
@@ -33,18 +33,15 @@ public class ArtifactReporterTest
private Artifact artifact;
- private MockArtifactReportProcessor processor;
-
private Model model;
protected void setUp()
throws Exception
{
super.setUp();
- reporter = new DefaultArtifactReporter();
+ reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
- processor = new MockArtifactReportProcessor();
Versioning versioning = new Versioning();
versioning.addVersion( "1.0-alpha-1" );
versioning.setLastUpdated( "20050611.202020" );
@@ -53,11 +50,12 @@ public class ArtifactReporterTest
public void testArtifactReporterSingleSuccess()
{
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "all is good" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addSuccess( artifact );
+
+ assertEquals( 1, reporter.getNumSuccesses() );
+
Iterator success = reporter.getArtifactSuccessIterator();
assertTrue( success.hasNext() );
- assertEquals( 1, reporter.getNumSuccesses() );
Artifact result = ( (ArtifactResult) success.next() ).getArtifact();
assertEquals( "groupId", result.getGroupId() );
assertEquals( "artifactId", result.getArtifactId() );
@@ -67,12 +65,9 @@ public class ArtifactReporterTest
public void testArtifactReporterMultipleSuccess()
{
- processor.clearList();
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "one" );
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "two" );
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "three" );
- reporter = new DefaultArtifactReporter();
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addSuccess( artifact );
+ reporter.addSuccess( artifact );
+ reporter.addSuccess( artifact );
Iterator success = reporter.getArtifactSuccessIterator();
assertTrue( success.hasNext() );
int i;
@@ -88,8 +83,7 @@ public class ArtifactReporterTest
public void testArtifactReporterSingleFailure()
{
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addFailure( artifact, "failed once" );
Iterator failure = reporter.getArtifactFailureIterator();
assertTrue( failure.hasNext() );
failure.next();
@@ -101,10 +95,9 @@ public class ArtifactReporterTest
public void testArtifactReporterMultipleFailure()
{
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addFailure( artifact, "failed once" );
+ reporter.addFailure( artifact, "failed twice" );
+ reporter.addFailure( artifact, "failed thrice" );
Iterator failure = reporter.getArtifactFailureIterator();
assertTrue( failure.hasNext() );
int i;
@@ -120,10 +113,9 @@ public class ArtifactReporterTest
public void testFailureMessages()
{
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addFailure( artifact, "failed once" );
+ reporter.addFailure( artifact, "failed twice" );
+ reporter.addFailure( artifact, "failed thrice" );
Iterator failure = reporter.getArtifactFailureIterator();
assertEquals( "failed once", ( (ArtifactResult) failure.next() ).getReason() );
assertEquals( "failed twice", ( (ArtifactResult) failure.next() ).getReason() );
@@ -132,8 +124,7 @@ public class ArtifactReporterTest
public void testArtifactReporterSingleWarning()
{
- processor.addReturnValue( ReportCondition.WARNING, artifact, "you've been warned" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addWarning( artifact, "you've been warned" );
Iterator warning = reporter.getArtifactWarningIterator();
assertTrue( warning.hasNext() );
warning.next();
@@ -145,10 +136,10 @@ public class ArtifactReporterTest
public void testArtifactReporterMultipleWarning()
{
- processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addWarning( artifact, "i'm warning you" );
+ reporter.addWarning( artifact, "you have to stop now" );
+ reporter.addWarning( artifact, "all right... that does it!" );
+
Iterator warning = reporter.getArtifactWarningIterator();
assertTrue( warning.hasNext() );
int i;
@@ -164,24 +155,13 @@ public class ArtifactReporterTest
public void testWarningMessages()
{
- processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addWarning( artifact, "i'm warning you" );
+ reporter.addWarning( artifact, "you have to stop now" );
+ reporter.addWarning( artifact, "all right... that does it!" );
+
Iterator warning = reporter.getArtifactWarningIterator();
assertEquals( "i'm warning you", ( (ArtifactResult) warning.next() ).getReason() );
assertEquals( "you have to stop now", ( (ArtifactResult) warning.next() ).getReason() );
assertEquals( "all right... that does it!", ( (ArtifactResult) warning.next() ).getReason() );
}
-
- protected void tearDown()
- throws Exception
- {
- model = null;
- processor.clearList();
- processor = null;
- reporter = null;
- super.tearDown();
- }
-
}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java
index 73f58393d..30a60b1b3 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java
+++ b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/BadMetadataReportProcessorTest.java
@@ -316,7 +316,8 @@ public class BadMetadataReportProcessorTest
RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
assertEquals( "check metadata", metadata, result.getMetadata() );
// TODO: should be more robust
- assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() );
+ assertEquals( "check reason", "Snapshot artifact 1.0-alpha-1-20050611.202024-2 does not exist.",
+ result.getReason() );
assertFalse( "check no more failures", failures.hasNext() );
}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/GenericMockObject.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/GenericMockObject.java
deleted file mode 100644
index 8e8a49c15..000000000
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/GenericMockObject.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Edwin Punzalan
- */
-public class GenericMockObject
- implements InvocationHandler
-{
- private Map invocations = new HashMap();
-
- public GenericMockObject()
- {
- //default constructor
- }
-
- public GenericMockObject( Map returnMap )
- {
- invocations = new HashMap( returnMap );
- }
-
- public void setExpectedReturns( Method method, List returnList )
- {
- invocations.put( method, returnList );
- }
-
- public Object invoke( Object proxy, Method method, Object[] args )
- {
- if ( !invocations.containsKey( method ) )
- {
- throw new UnsupportedOperationException( "No expected return values defined." );
- }
-
- List returnList = (List) invocations.get( method );
- if ( returnList.size() < 1 )
- {
- throw new UnsupportedOperationException( "Too few expected return values defined." );
- }
- return returnList.remove( 0 );
- }
-}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifact.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifact.java
deleted file mode 100644
index 9e4482137..000000000
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifact.java
+++ /dev/null
@@ -1,258 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
-import org.apache.maven.artifact.versioning.VersionRange;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @noinspection ReturnOfNull
- */
-public class MockArtifact
- implements Artifact
-{
- private String groupId;
-
- private String artifactId;
-
- private String version;
-
- public String getGroupId()
- {
- return groupId;
- }
-
- public String getArtifactId()
- {
- return artifactId;
- }
-
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion( String s )
- {
- version = s;
- }
-
- public String getScope()
- {
- return null;
- }
-
- public String getType()
- {
- return null;
- }
-
- public String getClassifier()
- {
- return null;
- }
-
- public boolean hasClassifier()
- {
- return false;
- }
-
- public File getFile()
- {
- return null;
- }
-
- public void setFile( File file )
- {
- }
-
- public String getBaseVersion()
- {
- return null;
- }
-
- public void setBaseVersion( String s )
- {
- }
-
- public String getId()
- {
- return null;
- }
-
- public String getDependencyConflictId()
- {
- return null;
- }
-
- public void addMetadata( ArtifactMetadata artifactMetadata )
- {
- }
-
- public Collection getMetadataList()
- {
- return null;
- }
-
- public void setRepository( ArtifactRepository artifactRepository )
- {
- }
-
- public ArtifactRepository getRepository()
- {
- return null;
- }
-
- public void updateVersion( String s, ArtifactRepository artifactRepository )
- {
- }
-
- public String getDownloadUrl()
- {
- return null;
- }
-
- public void setDownloadUrl( String s )
- {
- }
-
- public ArtifactFilter getDependencyFilter()
- {
- return null;
- }
-
- public void setDependencyFilter( ArtifactFilter artifactFilter )
- {
- }
-
- public ArtifactHandler getArtifactHandler()
- {
- return null;
- }
-
- public List getDependencyTrail()
- {
- return null;
- }
-
- public void setDependencyTrail( List list )
- {
- }
-
- public void setScope( String s )
- {
- }
-
- public VersionRange getVersionRange()
- {
- return null;
- }
-
- public void setVersionRange( VersionRange versionRange )
- {
- }
-
- public void selectVersion( String s )
- {
- }
-
- public void setGroupId( String s )
- {
- groupId = s;
- }
-
- public void setArtifactId( String s )
- {
- artifactId = s;
- }
-
- public boolean isSnapshot()
- {
- return false;
- }
-
- public void setResolved( boolean b )
- {
- }
-
- public boolean isResolved()
- {
- return false;
- }
-
- public void setResolvedVersion( String s )
- {
- }
-
- public void setArtifactHandler( ArtifactHandler artifactHandler )
- {
- }
-
- public boolean isRelease()
- {
- return false;
- }
-
- public void setRelease( boolean b )
- {
- }
-
- public List getAvailableVersions()
- {
- return null;
- }
-
- public void setAvailableVersions( List list )
- {
- }
-
- public boolean isOptional()
- {
- return false;
- }
-
- public ArtifactVersion getSelectedVersion()
- throws OverConstrainedVersionException
- {
- return null;
- }
-
- public boolean isSelectedVersionKnown()
- throws OverConstrainedVersionException
- {
- return false;
- }
-
- public int compareTo( Object o )
- {
- return 0;
- }
-
- public void setOptional( boolean b )
- {
- }
-}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactFactory.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactFactory.java
deleted file mode 100644
index bf4cb5382..000000000
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactFactory.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.versioning.VersionRange;
-
-/**
- * @noinspection ReturnOfNull
- */
-public class MockArtifactFactory
- implements ArtifactFactory
-{
- public Artifact createArtifact( String s, String s1, String s2, String s3, String s4 )
- {
- return null;
- }
-
- public Artifact createArtifactWithClassifier( String s, String s1, String s2, String s3, String s4 )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
- String s4 )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
- String s4, String s5 )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
- String s4, String s5, boolean b )
- {
- return null;
- }
-
- public Artifact createBuildArtifact( String s, String s1, String s2, String s3 )
- {
- return null;
- }
-
- public Artifact createProjectArtifact( String s, String s1, String s2 )
- {
- return null;
- }
-
- public Artifact createParentArtifact( String s, String s1, String s2 )
- {
- return null;
- }
-
- public Artifact createPluginArtifact( String s, String s1, VersionRange versionRange )
- {
- return null;
- }
-
- public Artifact createProjectArtifact( String s, String s1, String s2, String s3 )
- {
- return null;
- }
-
- public Artifact createExtensionArtifact( String s, String s1, VersionRange versionRange )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String string, String string1, VersionRange versionRange, String string2,
- String string3, String string4, boolean b )
- {
- return null;
- }
-}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactReportProcessor.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactReportProcessor.java
deleted file mode 100644
index 54697973f..000000000
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockArtifactReportProcessor.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Model;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- *
- */
-public class MockArtifactReportProcessor
- implements ArtifactReportProcessor
-{
- private List reportConditions;
-
- private Iterator iterator;
-
- public MockArtifactReportProcessor()
- {
- reportConditions = new ArrayList();
- }
-
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
- {
- if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
- {
- iterator = reportConditions.iterator();
- }
- if ( !reportConditions.isEmpty() )
- {
- while ( iterator.hasNext() )
- {
- ReportCondition reportCondition = (ReportCondition) iterator.next();
- int i = reportCondition.getResult();
- if ( i == ReportCondition.SUCCESS )
- {
- reporter.addSuccess( reportCondition.getArtifact() );
- }
- else if ( i == ReportCondition.WARNING )
- {
- reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() );
- }
- else if ( i == ReportCondition.FAILURE )
- {
- reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() );
- }
- }
- }
- }
-
- public void addReturnValue( int result, Artifact artifact, String reason )
- {
- reportConditions.add( new ReportCondition( result, artifact, reason ) );
- }
-
- public void clearList()
- {
- reportConditions.clear();
- }
-}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockRepositoryQueryLayer.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockRepositoryQueryLayer.java
deleted file mode 100644
index e1aa69ac2..000000000
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/MockRepositoryQueryLayer.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.archiva.layer.RepositoryQueryLayer;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- *
- */
-public class MockRepositoryQueryLayer
- implements RepositoryQueryLayer
-{
- private List queryConditions;
-
- private Iterator iterator;
-
- public MockRepositoryQueryLayer()
- {
- queryConditions = new ArrayList();
- }
-
- public boolean containsArtifact( Artifact artifact )
- {
- if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
- {
- iterator = queryConditions.iterator();
- }
- boolean b;
- if ( queryConditions.isEmpty() )
- {
- b = false;
- }
- else
- {
- b = ( (Boolean) iterator.next() ).booleanValue();
- }
- return b;
- }
-
- public void addReturnValue( boolean queryCondition )
- {
- queryConditions.add( Boolean.valueOf( queryCondition ) );
- }
-
- public void clearList()
- {
- queryConditions.clear();
- }
-
- public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
- {
- return containsArtifact( artifact );
- }
-
- public List getVersions( Artifact artifact )
- {
- return Collections.EMPTY_LIST;
- }
-}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ReportCondition.java b/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ReportCondition.java
deleted file mode 100644
index fcabbbd78..000000000
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/ReportCondition.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-
-/**
- *
- */
-public class ReportCondition
-{
- public static final int SUCCESS = 0;
-
- public static final int FAILURE = -1;
-
- public static final int WARNING = 1;
-
- private int result;
-
- private Artifact artifact;
-
- private String reason;
-
- public ReportCondition( int result, Artifact artifact, String reason )
- {
- this.result = result;
- this.artifact = artifact;
- this.reason = reason;
- }
-
- public int getResult()
- {
- return result;
- }
-
- public void setResult( int result )
- {
- this.result = result;
- }
-
- public Artifact getArtifact()
- {
- return artifact;
- }
-
- public void setArtifact( Artifact artifact )
- {
- this.artifact = artifact;
- }
-
- public String getReason()
- {
- return reason;
- }
-
- public void setReason( String reason )
- {
- this.reason = reason;
- }
-}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayer.java
deleted file mode 100644
index 60b0e5bb0..000000000
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.apache.maven.archiva.layer;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.List;
-
-/**
- *
- */
-public abstract class AbstractRepositoryQueryLayer
- implements RepositoryQueryLayer
-{
- protected ArtifactRepository repository;
-
- public boolean containsArtifact( Artifact artifact )
- {
- File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
- return f.exists();
- }
-
- public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
- {
- String artifactPath = getSnapshotArtifactRepositoryPath( artifact, snapshot );
- File artifactFile = new File( artifactPath );
- return artifactFile.exists();
- }
-
- public List getVersions( Artifact artifact )
- throws RepositoryQueryLayerException
- {
- Metadata metadata = getMetadata( artifact );
-
- return metadata.getVersioning().getVersions();
- }
-
- protected String getSnapshotArtifactRepositoryPath( Artifact artifact, Snapshot snapshot )
- {
- File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
- String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" +
- snapshot.getBuildNumber() + ".pom" );
- File snapshotFile = new File( f.getParentFile(), artifact.getArtifactId() + "-" + snapshotInfo );
- return snapshotFile.getAbsolutePath();
- }
-
- protected Metadata getMetadata( Artifact artifact )
- throws RepositoryQueryLayerException
- {
- Metadata metadata;
-
- ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
- String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
- File metadataFile = new File( repository.getBasedir(), path );
- if ( metadataFile.exists() )
- {
- MetadataXpp3Reader reader = new MetadataXpp3Reader();
- try
- {
- metadata = reader.read( new FileReader( metadataFile ) );
- }
- catch ( FileNotFoundException e )
- {
- throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
- }
- catch ( IOException e )
- {
- throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
- }
- catch ( XmlPullParserException e )
- {
- throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
- }
- }
- else
- {
- throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() );
- }
-
- return metadata;
- }
-}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java
index 91f9c5ff9..9453588e9 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayer.java
@@ -18,27 +18,35 @@ package org.apache.maven.archiva.layer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
+
+import java.util.List;
/**
*
*/
public class CachedRepositoryQueryLayer
- extends AbstractRepositoryQueryLayer
+ implements RepositoryQueryLayer
{
private Cache cache;
public static final double CACHE_HIT_RATIO = 0.5;
- public CachedRepositoryQueryLayer( ArtifactRepository repository )
+ private RepositoryQueryLayer layer;
+
+ public CachedRepositoryQueryLayer( RepositoryQueryLayer layer )
{
- this.repository = repository;
+ this.layer = layer;
cache = new Cache( CACHE_HIT_RATIO );
}
+ public CachedRepositoryQueryLayer( RepositoryQueryLayer layer, Cache cache )
+ {
+ this.cache = cache;
+ this.layer = layer;
+ }
+
public double getCacheHitRate()
{
return cache.getHitRate();
@@ -48,11 +56,11 @@ public class CachedRepositoryQueryLayer
{
boolean artifactFound = true;
- String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact );
+ String artifactPath = layer.getRepository().pathOf( artifact );
if ( cache.get( artifactPath ) == null )
{
- artifactFound = super.containsArtifact( artifact );
+ artifactFound = layer.containsArtifact( artifact );
if ( artifactFound )
{
cache.put( artifactPath, artifactPath );
@@ -62,38 +70,22 @@ public class CachedRepositoryQueryLayer
return artifactFound;
}
- public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
+ public List getVersions( Artifact artifact )
+ throws RepositoryQueryLayerException
{
- boolean artifactFound = true;
+ List list = (List) cache.get( artifact.getId() );
- String path = getSnapshotArtifactRepositoryPath( artifact, snapshot );
-
- if ( cache.get( path ) == null )
+ if ( list == null )
{
- artifactFound = super.containsArtifact( artifact, snapshot );
- if ( artifactFound )
- {
- cache.put( path, path );
- }
+ list = layer.getVersions( artifact );
+ cache.put( artifact.getId(), list );
}
- return artifactFound;
+ return list;
}
- /**
- * Override method to utilize the cache
- */
- protected Metadata getMetadata( Artifact artifact )
- throws RepositoryQueryLayerException
+ public ArtifactRepository getRepository()
{
- Metadata metadata = (Metadata) cache.get( artifact.getId() );
-
- if ( metadata == null )
- {
- metadata = super.getMetadata( artifact );
- cache.put( artifact.getId(), metadata );
- }
-
- return metadata;
+ return layer.getRepository();
}
}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java
index 582d5f377..0eadd6d2c 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayer.java
@@ -16,16 +16,84 @@ package org.apache.maven.archiva.layer;
* limitations under the License.
*/
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
/**
*
*/
public class DefaultRepositoryQueryLayer
- extends AbstractRepositoryQueryLayer
+ implements RepositoryQueryLayer
{
+ protected ArtifactRepository repository;
+
public DefaultRepositoryQueryLayer( ArtifactRepository repository )
{
this.repository = repository;
}
+
+ public boolean containsArtifact( Artifact artifact )
+ {
+ File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
+ return f.exists();
+ }
+
+ public List getVersions( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata = getMetadata( artifact );
+
+ return metadata.getVersioning().getVersions();
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return repository;
+ }
+
+ private Metadata getMetadata( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata;
+
+ ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
+ String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
+ File metadataFile = new File( repository.getBasedir(), path );
+ if ( metadataFile.exists() )
+ {
+ MetadataXpp3Reader reader = new MetadataXpp3Reader();
+ try
+ {
+ metadata = reader.read( new FileReader( metadataFile ) );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ }
+ else
+ {
+ throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() );
+ }
+
+ return metadata;
+ }
}
diff --git a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/RepositoryQueryLayer.java b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/RepositoryQueryLayer.java
index 93c57ef1f..874f52e05 100644
--- a/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/RepositoryQueryLayer.java
+++ b/archiva-repository-layer/src/main/java/org/apache/maven/archiva/layer/RepositoryQueryLayer.java
@@ -17,7 +17,7 @@ package org.apache.maven.archiva.layer;
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
@@ -30,8 +30,8 @@ public interface RepositoryQueryLayer
boolean containsArtifact( Artifact artifact );
- boolean containsArtifact( Artifact artifact, Snapshot snapshot );
-
List getVersions( Artifact artifact )
throws RepositoryQueryLayerException;
+
+ ArtifactRepository getRepository();
}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryQueryLayerTestCase.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayerTestCase.java
index 52fd4efc5..76debd58e 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/AbstractRepositoryQueryLayerTestCase.java
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/AbstractRepositoryQueryLayerTestCase.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.reporting;
+package org.apache.maven.archiva.layer;
/*
* Copyright 2005-2006 The Apache Software Foundation.
@@ -16,14 +16,11 @@ package org.apache.maven.archiva.reporting;
* limitations under the License.
*/
-import org.apache.maven.archiva.layer.CachedRepositoryQueryLayer;
-import org.apache.maven.archiva.layer.RepositoryQueryLayerException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
@@ -39,7 +36,7 @@ public abstract class AbstractRepositoryQueryLayerTestCase
protected ArtifactRepository repository;
- protected CachedRepositoryQueryLayer queryLayer;
+ protected RepositoryQueryLayer queryLayer;
protected void setUp()
throws Exception
@@ -71,25 +68,17 @@ public abstract class AbstractRepositoryQueryLayerTestCase
public void testContainsSnapshotArtifactTrue()
{
- Snapshot snapshot = new Snapshot();
- snapshot.setTimestamp( "20050611.202024" );
- snapshot.setBuildNumber( 1 );
-
- Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
- assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
+ Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1" );
+ assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact ) );
}
public void testContainsSnapshotArtifactFalse()
{
- Snapshot snapshot = new Snapshot();
- snapshot.setTimestamp( "20050611.202024" );
- snapshot.setBuildNumber( 2 );
-
- Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
- assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
+ Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-2" );
+ assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact ) );
}
- public void testArtifactVersionsTrue()
+ public void testArtifactVersions()
throws Exception
{
Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
@@ -97,20 +86,7 @@ public abstract class AbstractRepositoryQueryLayerTestCase
List versions = queryLayer.getVersions( artifact );
assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
- assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
- assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
- }
-
- public void testArtifactVersionsFalse()
- throws Exception
- {
- Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
-
- List versions = queryLayer.getVersions( artifact );
-
- assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
- assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
- assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
+ assertFalse( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
}
public void testArtifactVersionsError()
@@ -130,15 +106,8 @@ public abstract class AbstractRepositoryQueryLayerTestCase
private Artifact getArtifact( String groupId, String artifactId, String version )
{
- return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
- }
-
- protected void tearDown()
- throws Exception
- {
- release( artifactFactory );
- super.tearDown();
- artifactFactory = null;
- repository = null;
+ Artifact projectArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
+ projectArtifact.isSnapshot();
+ return projectArtifact;
}
}
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/CacheTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CacheTest.java
index 65d6f8109..a784c1373 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/CacheTest.java
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CacheTest.java
@@ -1,4 +1,4 @@
-package org.apache.maven.archiva.reporting;
+package org.apache.maven.archiva.layer;
/*
* Copyright 2005-2006 The Apache Software Foundation.
@@ -17,7 +17,6 @@ package org.apache.maven.archiva.reporting;
*/
import junit.framework.TestCase;
-import org.apache.maven.archiva.layer.Cache;
/**
*
diff --git a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/CachedRepositoryQueryLayerTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java
index bba92c722..8f717973e 100644
--- a/archiva-reports-standard/src/test/java/org/apache/maven/archiva/reporting/CachedRepositoryQueryLayerTest.java
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/CachedRepositoryQueryLayerTest.java
@@ -1,6 +1,4 @@
-package org.apache.maven.archiva.reporting;
-
-import org.apache.maven.archiva.layer.CachedRepositoryQueryLayer;
+package org.apache.maven.archiva.layer;
/*
* Copyright 2005-2006 The Apache Software Foundation.
@@ -24,37 +22,40 @@ import org.apache.maven.archiva.layer.CachedRepositoryQueryLayer;
public class CachedRepositoryQueryLayerTest
extends AbstractRepositoryQueryLayerTestCase
{
+ private Cache cache;
protected void setUp()
throws Exception
{
super.setUp();
- queryLayer = new CachedRepositoryQueryLayer( repository );
+ cache = new Cache( CachedRepositoryQueryLayer.CACHE_HIT_RATIO );
+
+ queryLayer = new CachedRepositoryQueryLayer( new DefaultRepositoryQueryLayer( repository ), cache );
}
public void testUseFileCache()
{
testContainsArtifactTrue();
- assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( 0, cache.getHitRate(), 0 );
testContainsArtifactTrue();
- assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, cache.getHitRate(), 0 );
}
public void testUseMetadataCache()
throws Exception
{
- testArtifactVersionsTrue();
- assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
- testArtifactVersionsTrue();
- assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
+ testArtifactVersions();
+ assertEquals( 0, cache.getHitRate(), 0 );
+ testArtifactVersions();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, cache.getHitRate(), 0 );
}
public void testUseFileCacheOnSnapshot()
{
testContainsSnapshotArtifactTrue();
- assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( 0, cache.getHitRate(), 0 );
testContainsSnapshotArtifactTrue();
- assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, cache.getHitRate(), 0 );
}
}
diff --git a/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayerTest.java b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayerTest.java
new file mode 100644
index 000000000..1a1817cea
--- /dev/null
+++ b/archiva-repository-layer/src/test/java/org/apache/maven/archiva/layer/DefaultRepositoryQueryLayerTest.java
@@ -0,0 +1,29 @@
+package org.apache.maven.archiva.layer;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class DefaultRepositoryQueryLayerTest
+ extends AbstractRepositoryQueryLayerTestCase
+{
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ queryLayer = new DefaultRepositoryQueryLayer( repository );
+ }
+}
diff --git a/archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar b/archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar
new file mode 100644
index 000000000..c2ea777c1
--- /dev/null
+++ b/archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.jar
Binary files differ
diff --git a/archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom b/archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom
new file mode 100644
index 000000000..c5f8bccb2
--- /dev/null
+++ b/archiva-repository-layer/src/test/repository/groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom
@@ -0,0 +1,6 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-1</version>
+</project>
diff --git a/archiva-repository-layer/src/test/repository/groupId/artifactId/maven-metadata.xml b/archiva-repository-layer/src/test/repository/groupId/artifactId/maven-metadata.xml
new file mode 100644
index 000000000..bb105fbcb
--- /dev/null
+++ b/archiva-repository-layer/src/test/repository/groupId/artifactId/maven-metadata.xml
@@ -0,0 +1,26 @@
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<metadata>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-1</version>
+ <versioning>
+ <versions>
+ <version>1.0-alpha-1</version>
+ </versions>
+ </versioning>
+</metadata>
diff --git a/archiva-repository-layer/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom b/archiva-repository-layer/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/archiva-repository-layer/src/test/repository/groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom