1 package org.apache.maven.archiva.reporting.processor;
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.reporting.model.ArtifactResults;
20 import org.apache.maven.archiva.reporting.model.Result;
21 import org.apache.maven.archiva.reporting.group.ReportGroup;
22 import org.apache.maven.archiva.reporting.processor.ArtifactReportProcessor;
23 import org.apache.maven.archiva.reporting.AbstractRepositoryReportsTestCase;
24 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.commons.io.FileUtils;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
31 import java.util.Iterator;
34 * This class tests the OldArtifactReportProcessor.
36 public class OldSnapshotArtifactReportProcessorTest
37 extends AbstractRepositoryReportsTestCase
39 private ArtifactReportProcessor artifactReportProcessor;
41 private ReportingDatabase reportDatabase;
43 private File tempRepository;
49 artifactReportProcessor =
50 (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "old-snapshot-artifact" );
52 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "old-artifact" );
53 reportDatabase = new ReportingDatabase( reportGroup );
54 tempRepository = getTestFile( "target/test-repository" );
55 FileUtils.deleteDirectory( tempRepository );
58 public void testOldSnapshotArtifact()
60 Artifact artifact = createArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1", "pom" );
62 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
63 assertEquals( 0, reportDatabase.getNumFailures() );
64 assertEquals( 0, reportDatabase.getNumWarnings() );
65 assertEquals( "Check notices", 1, reportDatabase.getNumNotices() );
66 Iterator artifactIterator = reportDatabase.getArtifactIterator();
67 assertArtifactResults( artifactIterator, artifact );
70 private static void assertArtifactResults( Iterator artifactIterator, Artifact artifact )
72 ArtifactResults results = (ArtifactResults) artifactIterator.next();
73 assertEquals( artifact.getArtifactId(), results.getArtifactId() );
74 assertEquals( artifact.getGroupId(), results.getGroupId() );
75 assertEquals( artifact.getVersion(), results.getVersion() );
76 assertFalse( artifact.getVersion().indexOf( "SNAPSHOT" ) >= 0 );
77 assertEquals( 1, results.getNotices().size() );
78 Iterator i = results.getNotices().iterator();
79 Result result = (Result) i.next();
80 assertEquals( "old-snapshot-artifact", result.getProcessor() );
83 public void testSNAPSHOTArtifact()
85 Artifact artifact = createArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "pom" );
87 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
88 assertEquals( 0, reportDatabase.getNumFailures() );
89 assertEquals( 0, reportDatabase.getNumWarnings() );
90 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
93 public void testNonSnapshotArtifact()
95 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
97 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
98 assertEquals( 0, reportDatabase.getNumFailures() );
99 assertEquals( 0, reportDatabase.getNumWarnings() );
100 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
103 public void testNewSnapshotArtifact()
106 File repository = getTestFile( "target/test-repository" );
108 File dir = new File( repository, "groupId/artifactId/1.0-alpha-1-SNAPSHOT" );
111 String date = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( new Date() );
112 FileUtils.writeStringToFile( new File( dir, "artifactId-1.0-alpha-1-" + date + "-1.jar" ), "foo", null );
115 createArtifactFromRepository( repository, "groupId", "artifactId", "1.0-alpha-1-" + date + "-1" );
117 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
118 assertEquals( 0, reportDatabase.getNumFailures() );
119 assertEquals( 0, reportDatabase.getNumWarnings() );
120 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
123 public void testTooManySnapshotArtifact()
126 File dir = new File( tempRepository, "groupId/artifactId/1.0-alpha-1-SNAPSHOT" );
129 String date = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( new Date() );
130 for ( int i = 1; i <= 5; i++ )
132 FileUtils.writeStringToFile( new File( dir, "artifactId-1.0-alpha-1-" + date + "-" + i + ".jar" ),
136 for ( int i = 1; i <= 5; i++ )
138 Artifact artifact = createArtifactFromRepository( tempRepository, "groupId", "artifactId",
139 "1.0-alpha-1-" + date + "-" + i );
140 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
143 assertEquals( 0, reportDatabase.getNumFailures() );
144 assertEquals( 0, reportDatabase.getNumWarnings() );
145 assertEquals( "Check notices", 3, reportDatabase.getNumNotices() );
146 Iterator artifactIterator = reportDatabase.getArtifactIterator();
147 for ( int i = 1; i <= 3; i++ )
149 String version = "1.0-alpha-1-" + date + "-" + i;
150 Artifact artifact = createArtifactFromRepository( tempRepository, "groupId", "artifactId", version );
151 assertArtifactResults( artifactIterator, artifact );
155 public void testMissingArtifact()
158 Artifact artifact = createArtifact( "foo", "bar", "XP" );
162 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
163 fail( "Should not have passed" );
165 catch ( IllegalStateException e )