]> source.dussan.org Git - archiva.git/blob
95d3c90eb7329371b8cc56cd87112a0713b864f0
[archiva.git] /
1 package org.apache.maven.archiva.reporting.processor;
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.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.codehaus.plexus.util.FileUtils;
27
28 import java.io.File;
29 import java.util.Iterator;
30
31 /**
32  * This class tests the OldArtifactReportProcessor.
33  */
34 public class OldArtifactReportProcessorTest
35     extends AbstractRepositoryReportsTestCase
36 {
37     private ArtifactReportProcessor artifactReportProcessor;
38
39     private ReportingDatabase reportDatabase;
40
41     public void setUp()
42         throws Exception
43     {
44         super.setUp();
45         artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "old-artifact" );
46
47         ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "old-artifact" );
48         reportDatabase = new ReportingDatabase( reportGroup );
49     }
50
51     public void testOldArtifact()
52     {
53         Artifact artifact = createArtifact( "org.apache.maven", "maven-model", "2.0" );
54
55         artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
56         assertEquals( 0, reportDatabase.getNumFailures() );
57         assertEquals( 0, reportDatabase.getNumWarnings() );
58         assertEquals( "Check notices", 1, reportDatabase.getNumNotices() );
59         ArtifactResults results = (ArtifactResults) reportDatabase.getArtifactIterator().next();
60         assertEquals( artifact.getArtifactId(), results.getArtifactId() );
61         assertEquals( artifact.getGroupId(), results.getGroupId() );
62         assertEquals( artifact.getVersion(), results.getVersion() );
63         assertEquals( 1, results.getNotices().size() );
64         Iterator i = results.getNotices().iterator();
65         Result result = (Result) i.next();
66         assertEquals( "old-artifact", result.getProcessor() );
67     }
68
69     public void testNewArtifact()
70         throws Exception
71     {
72         File repository = getTestFile( "target/test-repository" );
73
74         FileUtils.copyDirectoryStructure( getTestFile( "src/test/repository/groupId" ),
75                                           new File( repository, "groupId" ) );
76
77         Artifact artifact = createArtifactFromRepository( repository, "groupId", "artifactId", "1.0-alpha-1" );
78
79         artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
80         assertEquals( 0, reportDatabase.getNumFailures() );
81         assertEquals( 0, reportDatabase.getNumWarnings() );
82         assertEquals( "Check no notices", 0, reportDatabase.getNumNotices() );
83     }
84
85     public void testMissingArtifact()
86         throws Exception
87     {
88         Artifact artifact = createArtifact( "foo", "bar", "XP" );
89
90         try
91         {
92             artifactReportProcessor.processArtifact( artifact, null, reportDatabase );
93             fail( "Should not have passed" );
94         }
95         catch ( IllegalStateException e )
96         {
97             assertTrue( true );
98         }
99     }
100 }