]> source.dussan.org Git - archiva.git/blob
1b3d607593a5f03bff4a7e6c0207285d5b1e916f
[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.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.apache.maven.model.Dependency;
22 import org.apache.maven.model.Model;
23
24 import java.util.Iterator;
25
26 /**
27  *
28  */
29 public class ArtifactReportProcessorTest
30     extends AbstractRepositoryReportsTestCase
31 {
32     private static final String VALID_GROUP_ID = "groupId";
33
34     private static final String VALID_ARTIFACT_ID = "artifactId";
35
36     private static final String VALID_VERSION = "1.0-alpha-1";
37
38     private ArtifactReporter reporter;
39
40     private Model model;
41
42     private ArtifactReportProcessor processor;
43
44     private ArtifactFactory artifactFactory;
45
46     private static final String INVALID = "invalid";
47
48     protected void setUp()
49         throws Exception
50     {
51         super.setUp();
52         reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
53         model = new Model();
54         processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "default" );
55
56         artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
57     }
58
59     public void testArtifactFoundButNoDirectDependencies()
60         throws ReportProcessorException
61     {
62         Artifact artifact = createValidArtifact();
63         processor.processArtifact( model, artifact, reporter, repository );
64         assertEquals( 1, reporter.getNumSuccesses() );
65         assertEquals( 0, reporter.getNumFailures() );
66         assertEquals( 0, reporter.getNumWarnings() );
67     }
68
69     private Artifact createValidArtifact()
70     {
71         return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
72     }
73
74     public void testArtifactNotFound()
75         throws ReportProcessorException
76     {
77         Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID );
78         processor.processArtifact( model, artifact, reporter, repository );
79         assertEquals( 0, reporter.getNumSuccesses() );
80         assertEquals( 1, reporter.getNumFailures() );
81         assertEquals( 0, reporter.getNumWarnings() );
82         Iterator failures = reporter.getArtifactFailureIterator();
83         ArtifactResult result = (ArtifactResult) failures.next();
84         assertEquals( ArtifactReporter.ARTIFACT_NOT_FOUND, result.getReason() );
85     }
86
87     public void testValidArtifactWithNullDependency()
88         throws ReportProcessorException
89     {
90         Artifact artifact = createValidArtifact();
91
92         Dependency dependency = createValidDependency();
93         model.addDependency( dependency );
94
95         processor.processArtifact( model, artifact, reporter, repository );
96         assertEquals( 2, reporter.getNumSuccesses() );
97         assertEquals( 0, reporter.getNumFailures() );
98         assertEquals( 0, reporter.getNumWarnings() );
99     }
100
101     private Dependency createValidDependency()
102     {
103         return createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
104     }
105
106     public void testValidArtifactWithValidSingleDependency()
107         throws ReportProcessorException
108     {
109         Artifact artifact = createValidArtifact();
110
111         Dependency dependency = createValidDependency();
112         model.addDependency( dependency );
113
114         processor.processArtifact( model, artifact, reporter, repository );
115         assertEquals( 2, reporter.getNumSuccesses() );
116         assertEquals( 0, reporter.getNumFailures() );
117         assertEquals( 0, reporter.getNumWarnings() );
118     }
119
120     public void testValidArtifactWithValidMultipleDependencies()
121         throws ReportProcessorException
122     {
123         Dependency dependency = createValidDependency();
124         model.addDependency( dependency );
125         model.addDependency( dependency );
126         model.addDependency( dependency );
127         model.addDependency( dependency );
128         model.addDependency( dependency );
129
130         Artifact artifact = createValidArtifact();
131         processor.processArtifact( model, artifact, reporter, repository );
132         assertEquals( 6, reporter.getNumSuccesses() );
133         assertEquals( 0, reporter.getNumFailures() );
134         assertEquals( 0, reporter.getNumWarnings() );
135     }
136
137     public void testValidArtifactWithAnInvalidDependency()
138         throws ReportProcessorException
139     {
140         Dependency dependency = createValidDependency();
141         model.addDependency( dependency );
142         model.addDependency( dependency );
143         model.addDependency( dependency );
144         model.addDependency( dependency );
145         model.addDependency( createDependency( INVALID, INVALID, INVALID ) );
146
147         Artifact artifact = createValidArtifact();
148         processor.processArtifact( model, artifact, reporter, repository );
149         assertEquals( 5, reporter.getNumSuccesses() );
150         assertEquals( 1, reporter.getNumFailures() );
151         assertEquals( 0, reporter.getNumWarnings() );
152
153         Iterator failures = reporter.getArtifactFailureIterator();
154         ArtifactResult result = (ArtifactResult) failures.next();
155         assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
156     }
157
158     public void testValidArtifactWithInvalidDependencyGroupId()
159         throws ReportProcessorException
160     {
161         Artifact artifact = createValidArtifact();
162
163         Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION );
164         model.addDependency( dependency );
165
166         processor.processArtifact( model, artifact, reporter, repository );
167         assertEquals( 1, reporter.getNumSuccesses() );
168         assertEquals( 1, reporter.getNumFailures() );
169         assertEquals( 0, reporter.getNumWarnings() );
170
171         Iterator failures = reporter.getArtifactFailureIterator();
172         ArtifactResult result = (ArtifactResult) failures.next();
173         assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
174     }
175
176     private Dependency createDependency( String o, String valid, String s )
177     {
178         Dependency dependency = new Dependency();
179         dependency.setGroupId( o );
180         dependency.setArtifactId( valid );
181         dependency.setVersion( s );
182         return dependency;
183     }
184
185     public void testValidArtifactWithInvalidDependencyArtifactId()
186         throws ReportProcessorException
187     {
188         Artifact artifact = createValidArtifact();
189
190         Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION );
191         model.addDependency( dependency );
192
193         processor.processArtifact( model, artifact, reporter, repository );
194         assertEquals( 1, reporter.getNumSuccesses() );
195         assertEquals( 1, reporter.getNumFailures() );
196         assertEquals( 0, reporter.getNumWarnings() );
197
198         Iterator failures = reporter.getArtifactFailureIterator();
199         ArtifactResult result = (ArtifactResult) failures.next();
200         assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
201     }
202
203     public void testValidArtifactWithIncorrectDependencyVersion()
204         throws ReportProcessorException
205     {
206         Artifact artifact = createValidArtifact();
207
208         Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID );
209         model.addDependency( dependency );
210
211         processor.processArtifact( model, artifact, reporter, repository );
212         assertEquals( 1, reporter.getNumSuccesses() );
213         assertEquals( 1, reporter.getNumFailures() );
214         assertEquals( 0, reporter.getNumWarnings() );
215
216         Iterator failures = reporter.getArtifactFailureIterator();
217         ArtifactResult result = (ArtifactResult) failures.next();
218         assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
219     }
220
221     public void testValidArtifactWithInvalidDependencyVersion()
222         throws ReportProcessorException
223     {
224         Artifact artifact = createValidArtifact();
225
226         Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" );
227         model.addDependency( dependency );
228
229         processor.processArtifact( model, artifact, reporter, repository );
230         assertEquals( 1, reporter.getNumSuccesses() );
231         assertEquals( 1, reporter.getNumFailures() );
232         assertEquals( 0, reporter.getNumWarnings() );
233
234         Iterator failures = reporter.getArtifactFailureIterator();
235         ArtifactResult result = (ArtifactResult) failures.next();
236         assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() );
237     }
238 }