1 package org.apache.maven.repository.reporting;
3 import org.apache.maven.artifact.Artifact;
4 import org.apache.maven.artifact.factory.ArtifactFactory;
5 import org.apache.maven.model.Model;
6 import org.apache.maven.repository.digest.DefaultDigester;
7 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
8 import org.codehaus.plexus.util.FileUtils;
13 * @author Edwin Punzalan
15 public class DuplicateArtifactFileReportProcessorTest
16 extends AbstractRepositoryReportsTestCase
18 private MockArtifactReporter reporter;
20 private Artifact artifact;
24 private DuplicateArtifactFileReportProcessor processor;
26 private ArtifactFactory artifactFactory;
28 private String indexPath = new File( "target/.index" ).getAbsolutePath();
30 protected void setUp()
34 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class.getName() );
35 reporter = new MockArtifactReporter();
36 artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
38 processor = new DuplicateArtifactFileReportProcessor();
39 processor.setArtifactFactory( artifactFactory );
41 ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexPath, repository, new DefaultDigester() );
42 index.indexArtifact( artifact );
47 protected void tearDown()
50 FileUtils.deleteDirectory( indexPath );
59 public void testNullArtifactFile()
62 artifact.setFile( null );
64 processor.processArtifact( model, artifact, reporter, repository );
66 assertEquals( "Check no successes", 0, reporter.getSuccesses() );
67 assertEquals( "Check warnings", 1, reporter.getWarnings() );
68 assertEquals( "Check no failures", 0, reporter.getFailures() );
71 public void testSuccessOnAlreadyIndexedArtifact()
74 processor.processArtifact( model, artifact, reporter, repository );
76 assertEquals( "Check no successes", 1, reporter.getSuccesses() );
77 assertEquals( "Check warnings", 0, reporter.getWarnings() );
78 assertEquals( "Check no failures", 0, reporter.getFailures() );
81 public void testSuccessOnDifferentGroupId()
84 artifact.setGroupId( "different.groupId" );
85 processor.processArtifact( model, artifact, reporter, repository );
87 assertEquals( "Check no successes", 1, reporter.getSuccesses() );
88 assertEquals( "Check warnings", 0, reporter.getWarnings() );
89 assertEquals( "Check no failures", 0, reporter.getFailures() );
92 public void testSuccessOnNewArtifact()
95 Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" );
97 processor.processArtifact( model, newArtifact, reporter, repository );
99 assertEquals( "Check no successes", 1, reporter.getSuccesses() );
100 assertEquals( "Check warnings", 0, reporter.getWarnings() );
101 assertEquals( "Check no failures", 0, reporter.getFailures() );
104 public void testFailure()
107 Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT",
108 artifact.getVersion(), artifact.getType() );
109 duplicate.setFile( artifact.getFile() );
111 processor.processArtifact( model, duplicate, reporter, repository );
113 assertEquals( "Check no successes", 0, reporter.getSuccesses() );
114 assertEquals( "Check warnings", 0, reporter.getWarnings() );
115 assertEquals( "Check no failures", 1, reporter.getFailures() );
118 private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
121 Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
122 artifact.setBaseVersion( baseVersion );
123 artifact.setRepository( repository );
124 artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );