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