]> source.dussan.org Git - archiva.git/blob
93c7de65f6afdc950d49de96f48c4dd79105e76c
[archiva.git] /
1 package org.apache.maven.archiva.reporting;
2
3 /*
4  * Copyright 2005-2006 The Apache Software Foundation.
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
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;
23
24 import java.io.File;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
27 import java.util.Iterator;
28
29 /**
30  * This class tests the OldArtifactReportProcessor.
31  */
32 public class OldSnapshotArtifactReportProcessorTest
33     extends AbstractRepositoryReportsTestCase
34 {
35     private ArtifactReportProcessor artifactReportProcessor;
36
37     private ReportingDatabase reportDatabase;
38
39     private File tempRepository;
40
41     public void setUp()
42         throws Exception
43     {
44         super.setUp();
45         artifactReportProcessor =
46             (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "old-snapshot-artifact" );
47
48         ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "old-artifact" );
49         reportDatabase = new ReportingDatabase( reportGroup );
50         tempRepository = getTestFile( "target/test-repository" );
51         FileUtils.deleteDirectory( tempRepository );
52     }
53
54     public void testOldSnapshotArtifact()
55     {
56         Artifact artifact = createArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1", "pom" );
57
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 );
64     }
65
66     private static void assertArtifactResults( Iterator artifactIterator, Artifact artifact )
67     {
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() );
77     }
78
79     public void testSNAPSHOTArtifact()
80     {
81         Artifact artifact = createArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "pom" );
82
83         artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
84         assertEquals( 0, reportDatabase.getNumFailures() );
85         assertEquals( 0, reportDatabase.getNumWarnings() );
86         assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
87     }
88
89     public void testNonSnapshotArtifact()
90     {
91         Artifact artifact = createArtifact( "groupId", "artifactId", "1.0-alpha-1" );
92
93         artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
94         assertEquals( 0, reportDatabase.getNumFailures() );
95         assertEquals( 0, reportDatabase.getNumWarnings() );
96         assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
97     }
98
99     public void testNewSnapshotArtifact()
100         throws Exception
101     {
102         File repository = getTestFile( "target/test-repository" );
103
104         File dir = new File( repository, "groupId/artifactId/1.0-alpha-1-SNAPSHOT" );
105         dir.mkdirs();
106
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" );
109
110         Artifact artifact =
111             createArtifactFromRepository( repository, "groupId", "artifactId", "1.0-alpha-1-" + date + "-1" );
112
113         artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
114         assertEquals( 0, reportDatabase.getNumFailures() );
115         assertEquals( 0, reportDatabase.getNumWarnings() );
116         assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
117     }
118
119     public void testTooManySnapshotArtifact()
120         throws Exception
121     {
122         File dir = new File( tempRepository, "groupId/artifactId/1.0-alpha-1-SNAPSHOT" );
123         dir.mkdirs();
124
125         String date = new SimpleDateFormat( "yyyyMMdd.HHmmss" ).format( new Date() );
126         for ( int i = 1; i <= 5; i++ )
127         {
128             FileUtils.fileWrite( new File( dir, "artifactId-1.0-alpha-1-" + date + "-" + i + ".jar" ).getAbsolutePath(),
129                                  "foo" );
130         }
131
132         for ( int i = 1; i <= 5; i++ )
133         {
134             Artifact artifact = createArtifactFromRepository( tempRepository, "groupId", "artifactId",
135                                                               "1.0-alpha-1-" + date + "-" + i );
136             artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
137         }
138
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++ )
144         {
145             String version = "1.0-alpha-1-" + date + "-" + i;
146             Artifact artifact = createArtifactFromRepository( tempRepository, "groupId", "artifactId", version );
147             assertArtifactResults( artifactIterator, artifact );
148         }
149     }
150
151     public void testMissingArtifact()
152         throws Exception
153     {
154         Artifact artifact = createArtifact( "foo", "bar", "XP" );
155
156         try
157         {
158             artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
159             fail( "Should not have passed" );
160         }
161         catch ( IllegalStateException e )
162         {
163             assertTrue( true );
164         }
165     }
166 }