1 package org.apache.maven.archiva.reporting;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
20 import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
21 import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.factory.ArtifactFactory;
24 import org.apache.maven.model.Model;
25 import org.codehaus.plexus.util.FileUtils;
28 import java.util.Collections;
31 * @author Edwin Punzalan
33 public class DuplicateArtifactFileReportProcessorTest
34 extends AbstractRepositoryReportsTestCase
36 private Artifact artifact;
40 private ArtifactReportProcessor processor;
42 private ArtifactFactory artifactFactory;
46 private DefaultArtifactReporter reporter = new DefaultArtifactReporter();
48 protected void setUp()
53 indexDirectory = getTestFile( "target/indexDirectory" );
54 FileUtils.deleteDirectory( indexDirectory );
56 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
57 artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
60 RepositoryArtifactIndexFactory factory =
61 (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" );
63 RepositoryArtifactIndex index = factory.createStandardIndex( indexDirectory );
65 RepositoryIndexRecordFactory recordFactory =
66 (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" );
68 index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact ) ) );
70 processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
73 public void testNullArtifactFile()
76 artifact.setFile( null );
78 processor.processArtifact( model, artifact, reporter, repository );
80 assertEquals( "Check no successes", 0, reporter.getNumSuccesses() );
81 assertEquals( "Check warnings", 1, reporter.getNumWarnings() );
82 assertEquals( "Check no failures", 0, reporter.getNumFailures() );
85 public void testSuccessOnAlreadyIndexedArtifact()
88 processor.processArtifact( model, artifact, reporter, repository );
90 assertEquals( "Check no successes", 1, reporter.getNumSuccesses() );
91 assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
92 assertEquals( "Check no failures", 0, reporter.getNumFailures() );
95 public void testSuccessOnDifferentGroupId()
98 artifact.setGroupId( "different.groupId" );
99 processor.processArtifact( model, artifact, reporter, repository );
101 assertEquals( "Check no successes", 1, reporter.getNumSuccesses() );
102 assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
103 assertEquals( "Check no failures", 0, reporter.getNumFailures() );
106 public void testSuccessOnNewArtifact()
109 Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" );
111 processor.processArtifact( model, newArtifact, reporter, repository );
113 assertEquals( "Check no successes", 1, reporter.getNumSuccesses() );
114 assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
115 assertEquals( "Check no failures", 0, reporter.getNumFailures() );
118 public void testFailure()
121 Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT",
122 artifact.getVersion(), artifact.getType() );
123 duplicate.setFile( artifact.getFile() );
125 processor.processArtifact( model, duplicate, reporter, repository );
127 assertEquals( "Check no successes", 0, reporter.getNumSuccesses() );
128 assertEquals( "Check warnings", 0, reporter.getNumWarnings() );
129 assertEquals( "Check no failures", 1, reporter.getNumFailures() );
132 private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
135 Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
136 artifact.setBaseVersion( baseVersion );
137 artifact.setRepository( repository );
138 artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );