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.reporting.model.ArtifactResults;
20 import org.apache.maven.archiva.reporting.model.Result;
21 import org.apache.maven.artifact.Artifact;
22 import org.codehaus.plexus.util.FileUtils;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
27 import java.util.Iterator;
30 * This class tests the OldArtifactReportProcessor.
32 public class OldSnapshotArtifactReportProcessorTest
33 extends AbstractRepositoryReportsTestCase
35 private ArtifactReportProcessor artifactReportProcessor;
37 private ReportingDatabase reportDatabase;
39 private File tempRepository;
45 artifactReportProcessor =
46 (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "old-snapshot-artifact" );
48 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "old-artifact" );
49 reportDatabase = new ReportingDatabase( reportGroup );
50 tempRepository = getTestFile( "target/test-repository" );
51 FileUtils.deleteDirectory( tempRepository );
54 public void testOldSnapshotArtifact()
56 Artifact artifact = createArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1", "pom" );
58 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
59 assertEquals( 0, reportDatabase.getNumFailures() );
60 assertEquals( 0, reportDatabase.getNumWarnings() );
61 assertEquals( "Check notices", 1, reportDatabase.getNumNotices() );
62 Iterator artifactIterator = reportDatabase.getArtifactIterator();
63 assertArtifactResults( artifactIterator, artifact );
66 private static void assertArtifactResults( Iterator artifactIterator, Artifact artifact )
68 ArtifactResults results = (ArtifactResults) artifactIterator.next();
69 assertEquals( artifact.getArtifactId(), results.getArtifactId() );
70 assertEquals( artifact.getGroupId(), results.getGroupId() );
71 assertEquals( artifact.getVersion(), results.getVersion() );
72 assertFalse( artifact.getVersion().indexOf( "SNAPSHOT" ) >= 0 );
73 assertEquals( 1, results.getNotices().size() );
74 Iterator i = results.getNotices().iterator();
75 Result result = (Result) i.next();
76 assertEquals( "old-snapshot-artifact", result.getProcessor() );
79 public void testSNAPSHOTArtifact()
81 Artifact artifact = createArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "pom" );
83 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
84 assertEquals( 0, reportDatabase.getNumFailures() );
85 assertEquals( 0, reportDatabase.getNumWarnings() );
86 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
89 public void testNonSnapshotArtifact()
91 Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
93 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
94 assertEquals( 0, reportDatabase.getNumFailures() );
95 assertEquals( 0, reportDatabase.getNumWarnings() );
96 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
99 public void testNewSnapshotArtifact()
102 File repository = getTestFile( "target/test-repository" );
104 File dir = new File( repository, "groupId/artifactId/1.0-alpha-1-SNAPSHOT" );
107 String date = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( new Date() );
108 FileUtils.fileWrite( new File( dir, "artifactId-1.0-alpha-1-" + date + "-1.jar" ).getAbsolutePath(), "foo" );
111 createArtifactFromRepository( repository, "groupId", "artifactId", "1.0-alpha-1-" + date + "-1" );
113 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
114 assertEquals( 0, reportDatabase.getNumFailures() );
115 assertEquals( 0, reportDatabase.getNumWarnings() );
116 assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
119 public void testTooManySnapshotArtifact()
122 File dir = new File( tempRepository, "groupId/artifactId/1.0-alpha-1-SNAPSHOT" );
125 String date = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( new Date() );
126 for ( int i = 1; i <= 5; i++ )
128 FileUtils.fileWrite( new File( dir, "artifactId-1.0-alpha-1-" + date + "-" + i + ".jar" ).getAbsolutePath(),
132 for ( int i = 1; i <= 5; i++ )
134 Artifact artifact = createArtifactFromRepository( tempRepository, "groupId", "artifactId",
135 "1.0-alpha-1-" + date + "-" + i );
136 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
139 assertEquals( 0, reportDatabase.getNumFailures() );
140 assertEquals( 0, reportDatabase.getNumWarnings() );
141 assertEquals( "Check notices", 3, reportDatabase.getNumNotices() );
142 Iterator artifactIterator = reportDatabase.getArtifactIterator();
143 for ( int i = 1; i <= 3; i++ )
145 String version = "1.0-alpha-1-" + date + "-" + i;
146 Artifact artifact = createArtifactFromRepository( tempRepository, "groupId", "artifactId", version );
147 assertArtifactResults( artifactIterator, artifact );
151 public void testMissingArtifact()
154 Artifact artifact = createArtifact( "foo", "bar", "XP" );
158 artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
159 fail( "Should not have passed" );
161 catch ( IllegalStateException e )