1 package org.apache.maven.archiva.reporting.processor;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.archiva.indexer.RepositoryArtifactIndex;
24 import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory;
25 import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory;
26 import org.apache.maven.archiva.reporting.AbstractRepositoryReportsTestCase;
27 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
28 import org.apache.maven.archiva.reporting.group.ReportGroup;
29 import org.apache.maven.artifact.Artifact;
30 import org.apache.maven.artifact.factory.ArtifactFactory;
31 import org.apache.maven.model.Model;
34 import java.util.Collections;
37 * @author Edwin Punzalan
39 public class DuplicateArtifactFileReportProcessorTest
40 extends AbstractRepositoryReportsTestCase
42 private Artifact artifact;
46 private ArtifactReportProcessor processor;
48 private ArtifactFactory artifactFactory;
52 private ReportingDatabase reportDatabase;
54 protected void setUp()
59 indexDirectory = getTestFile( "target/indexDirectory" );
60 FileUtils.deleteDirectory( indexDirectory );
62 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
63 artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "jar" );
64 System.out.println( "artifact = " + artifact );
67 RepositoryArtifactIndexFactory factory =
68 (RepositoryArtifactIndexFactory) lookup( RepositoryArtifactIndexFactory.ROLE, "lucene" );
70 RepositoryArtifactIndex index = factory.createStandardIndex( indexDirectory );
72 RepositoryIndexRecordFactory recordFactory =
73 (RepositoryIndexRecordFactory) lookup( RepositoryIndexRecordFactory.ROLE, "standard" );
75 index.indexRecords( Collections.singletonList( recordFactory.createRecord( artifact ) ) );
77 processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "duplicate" );
79 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
80 reportDatabase = new ReportingDatabase( reportGroup );
83 public void testNullArtifactFile()
86 artifact.setFile( null );
88 processor.processArtifact( artifact, model, reportDatabase );
90 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
91 assertEquals( "Check warnings", 1, reportDatabase.getNumWarnings() );
92 assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
95 public void testSuccessOnAlreadyIndexedArtifact()
98 processor.processArtifact( artifact, model, reportDatabase );
100 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
101 assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
102 assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
105 public void testSuccessOnDifferentGroupId()
108 artifact.setGroupId( "different.groupId" );
109 processor.processArtifact( artifact, model, reportDatabase );
111 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
112 assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
113 assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
116 public void testSuccessOnNewArtifact()
119 Artifact newArtifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1", "1.0-alpha-1", "pom" );
121 processor.processArtifact( newArtifact, model, reportDatabase );
123 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
124 assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
125 assertEquals( "Check no failures", 0, reportDatabase.getNumFailures() );
128 public void testFailure()
131 Artifact duplicate = createArtifact( artifact.getGroupId(), "snapshot-artifact", "1.0-alpha-1-SNAPSHOT",
132 artifact.getVersion(), artifact.getType() );
133 duplicate.setFile( artifact.getFile() );
135 processor.processArtifact( duplicate, model, reportDatabase );
137 assertEquals( "Check warnings", 0, reportDatabase.getNumWarnings() );
138 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
139 assertEquals( "Check no failures", 1, reportDatabase.getNumFailures() );
142 private Artifact createArtifact( String groupId, String artifactId, String baseVersion, String version,
145 Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, type );
146 artifact.setBaseVersion( baseVersion );
147 artifact.setRepository( repository );
148 artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );