1 package org.apache.maven.repository.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.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.apache.maven.model.Model;
22 import org.apache.maven.repository.digest.Digester;
23 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
24 import org.codehaus.plexus.util.FileUtils;
29 * @author Edwin Punzalan
31 public class DuplicateArtifactFileReportProcessorTest
32 extends AbstractRepositoryReportsTestCase
34 private MockArtifactReporter reporter;
36 private Artifact artifact;
40 private ArtifactReportProcessor processor;
42 private ArtifactFactory artifactFactory;
46 protected void setUp()
51 Digester digester = (Digester) lookup( Digester.ROLE );
53 indexDirectory = getTestFile( "target/indexDirectory" );
55 if ( !indexDirectory.exists() )
57 indexDirectory.mkdirs();
60 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
61 artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
62 reporter = new MockArtifactReporter();
65 ArtifactRepositoryIndex index = new ArtifactRepositoryIndex( indexDirectory, repository, digester );
66 index.indexArtifact( artifact );
70 processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
73 protected void tearDown()
76 //FileUtils.deleteDirectory( indexDirectory );
85 public void testNullArtifactFile()
88 artifact.setFile( null );
90 processor.processArtifact( model, artifact, reporter, repository );
92 assertEquals( "Check no successes", 0, reporter.getSuccesses() );
93 assertEquals( "Check warnings", 1, reporter.getWarnings() );
94 assertEquals( "Check no failures", 0, reporter.getFailures() );
97 public void testSuccessOnAlreadyIndexedArtifact()
100 processor.processArtifact( model, artifact, reporter, repository );
102 assertEquals( "Check no successes", 1, reporter.getSuccesses() );
103 assertEquals( "Check warnings", 0, reporter.getWarnings() );
104 assertEquals( "Check no failures", 0, reporter.getFailures() );
107 public void testSuccessOnDifferentGroupId()
110 artifact.setGroupId( "different.groupId" );
111 processor.processArtifact( model, artifact, reporter, repository );
113 assertEquals( "Check no successes", 1, reporter.getSuccesses() );
114 assertEquals( "Check warnings", 0, reporter.getWarnings() );
115 assertEquals( "Check no failures", 0, reporter.getFailures() );
118 public void testSuccessOnNewArtifact()
121 Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" );
123 processor.processArtifact( model, newArtifact, reporter, repository );
125 assertEquals( "Check no successes", 1, reporter.getSuccesses() );
126 assertEquals( "Check warnings", 0, reporter.getWarnings() );
127 assertEquals( "Check no failures", 0, reporter.getFailures() );
130 public void testFailure()
133 Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT",
134 artifact.getVersion(), artifact.getType() );
135 duplicate.setFile( artifact.getFile() );
137 processor.processArtifact( model, duplicate, reporter, repository );
139 assertEquals( "Check no successes", 0, reporter.getSuccesses() );
140 assertEquals( "Check warnings", 0, reporter.getWarnings() );
141 assertEquals( "Check no failures", 1, reporter.getFailures() );
144 private Artifact createArtifact( String groupId,
150 Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
151 artifact.setBaseVersion( baseVersion );
152 artifact.setRepository( repository );
153 artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );