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.MetadataResults;
21 import org.apache.maven.archiva.reporting.model.Result;
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.factory.ArtifactFactory;
24 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
25 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
26 import org.apache.maven.artifact.repository.metadata.Versioning;
28 import java.util.Iterator;
33 public class DefaultArtifactReporterTest
34 extends AbstractRepositoryReportsTestCase
36 private ReportingDatabase reportingDatabase;
38 private RepositoryMetadata metadata;
40 private static final String PROCESSOR = "processor";
42 private static final String PROBLEM = "problem";
44 private Artifact artifact;
46 public void testEmptyArtifactReporter()
48 assertEquals( "No failures", 0, reportingDatabase.getNumFailures() );
49 assertEquals( "No warnings", 0, reportingDatabase.getNumWarnings() );
50 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
51 assertFalse( "No artifact failures", reportingDatabase.getArtifactIterator().hasNext() );
52 assertFalse( "No metadata failures", reportingDatabase.getMetadataIterator().hasNext() );
55 public void testMetadataSingleFailure()
57 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Single Failure Reason" );
58 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
59 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
60 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
62 Iterator failures = reportingDatabase.getMetadataIterator();
63 assertTrue( "check there is a failure", failures.hasNext() );
64 MetadataResults results = (MetadataResults) failures.next();
65 failures = results.getFailures().iterator();
66 assertTrue( "check there is a failure", failures.hasNext() );
67 Result result = (Result) failures.next();
68 assertMetadata( results );
69 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
70 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
71 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
72 assertFalse( "no more failures", failures.hasNext() );
75 private void assertMetadata( MetadataResults result )
77 assertEquals( "check failure cause", metadata.getGroupId(), result.getGroupId() );
78 assertEquals( "check failure cause", metadata.getArtifactId(), result.getArtifactId() );
79 assertEquals( "check failure cause", metadata.getBaseVersion(), result.getVersion() );
82 public void testMetadataMultipleFailures()
84 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "First Failure Reason" );
85 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Second Failure Reason" );
86 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
87 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
88 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
90 Iterator failures = reportingDatabase.getMetadataIterator();
91 assertTrue( "check there is a failure", failures.hasNext() );
92 MetadataResults results = (MetadataResults) failures.next();
93 failures = results.getFailures().iterator();
94 assertTrue( "check there is a failure", failures.hasNext() );
95 Result result = (Result) failures.next();
96 assertMetadata( results );
97 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
98 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
99 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
100 assertTrue( "must have 2nd failure", failures.hasNext() );
101 result = (Result) failures.next();
102 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
103 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
104 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
105 assertFalse( "no more failures", failures.hasNext() );
108 public void testMetadataSingleWarning()
110 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Single Warning Message" );
111 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
112 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
113 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
115 Iterator warnings = reportingDatabase.getMetadataIterator();
116 assertTrue( "check there is a failure", warnings.hasNext() );
117 MetadataResults results = (MetadataResults) warnings.next();
118 warnings = results.getWarnings().iterator();
119 assertTrue( "check there is a failure", warnings.hasNext() );
120 Result result = (Result) warnings.next();
121 assertMetadata( results );
122 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
123 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
124 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
125 assertFalse( "no more warnings", warnings.hasNext() );
128 public void testMetadataMultipleWarnings()
130 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "First Warning" );
131 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Second Warning" );
132 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
133 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
134 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
136 Iterator warnings = reportingDatabase.getMetadataIterator();
137 assertTrue( "check there is a failure", warnings.hasNext() );
138 MetadataResults results = (MetadataResults) warnings.next();
139 warnings = results.getWarnings().iterator();
140 assertTrue( "check there is a failure", warnings.hasNext() );
141 Result result = (Result) warnings.next();
142 assertMetadata( results );
143 assertEquals( "check failure reason", "First Warning", result.getReason() );
144 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
145 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
146 assertTrue( "must have 2nd warning", warnings.hasNext() );
147 result = (Result) warnings.next();
148 assertEquals( "check failure reason", "Second Warning", result.getReason() );
149 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
150 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
151 assertFalse( "no more warnings", warnings.hasNext() );
154 public void testMetadataSingleNotice()
156 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "Single Notice Message" );
157 assertEquals( "failure count", 0, reportingDatabase.getNumFailures() );
158 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
159 assertEquals( "check notices", 1, reportingDatabase.getNumNotices() );
161 Iterator warnings = reportingDatabase.getMetadataIterator();
162 assertTrue( "check there is a failure", warnings.hasNext() );
163 MetadataResults results = (MetadataResults) warnings.next();
164 warnings = results.getNotices().iterator();
165 assertTrue( "check there is a failure", warnings.hasNext() );
166 Result result = (Result) warnings.next();
167 assertMetadata( results );
168 assertEquals( "check failure reason", "Single Notice Message", result.getReason() );
169 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
170 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
171 assertFalse( "no more warnings", warnings.hasNext() );
174 public void testMetadataMultipleNotices()
176 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "First Notice" );
177 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "Second Notice" );
178 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
179 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
180 assertEquals( "check no notices", 2, reportingDatabase.getNumNotices() );
182 Iterator warnings = reportingDatabase.getMetadataIterator();
183 assertTrue( "check there is a failure", warnings.hasNext() );
184 MetadataResults results = (MetadataResults) warnings.next();
185 warnings = results.getNotices().iterator();
186 assertTrue( "check there is a failure", warnings.hasNext() );
187 Result result = (Result) warnings.next();
188 assertMetadata( results );
189 assertEquals( "check failure reason", "First Notice", result.getReason() );
190 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
191 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
192 assertTrue( "must have 2nd warning", warnings.hasNext() );
193 result = (Result) warnings.next();
194 assertEquals( "check failure reason", "Second Notice", result.getReason() );
195 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
196 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
197 assertFalse( "no more warnings", warnings.hasNext() );
200 public void testArtifactSingleFailure()
202 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "Single Failure Reason" );
203 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
204 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
205 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
207 Iterator failures = reportingDatabase.getArtifactIterator();
208 assertTrue( "check there is a failure", failures.hasNext() );
209 ArtifactResults results = (ArtifactResults) failures.next();
210 failures = results.getFailures().iterator();
211 assertTrue( "check there is a failure", failures.hasNext() );
212 Result result = (Result) failures.next();
213 assertArtifact( results );
214 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
215 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
216 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
217 assertFalse( "no more failures", failures.hasNext() );
220 private void assertArtifact( ArtifactResults results )
222 assertEquals( "check failure cause", artifact.getGroupId(), results.getGroupId() );
223 assertEquals( "check failure cause", artifact.getArtifactId(), results.getArtifactId() );
224 assertEquals( "check failure cause", artifact.getVersion(), results.getVersion() );
225 assertEquals( "check failure cause", artifact.getClassifier(), results.getClassifier() );
226 assertEquals( "check failure cause", artifact.getType(), results.getType() );
229 public void testArtifactMultipleFailures()
231 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "First Failure Reason" );
232 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "Second Failure Reason" );
233 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
234 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
235 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
237 Iterator failures = reportingDatabase.getArtifactIterator();
238 assertTrue( "check there is a failure", failures.hasNext() );
239 ArtifactResults results = (ArtifactResults) failures.next();
240 failures = results.getFailures().iterator();
241 assertTrue( "check there is a failure", failures.hasNext() );
242 Result result = (Result) failures.next();
243 assertArtifact( results );
244 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
245 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
246 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
247 assertTrue( "must have 2nd failure", failures.hasNext() );
248 result = (Result) failures.next();
249 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
250 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
251 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
252 assertFalse( "no more failures", failures.hasNext() );
255 public void testArtifactSingleWarning()
257 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "Single Warning Message" );
258 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
259 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
260 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
262 Iterator warnings = reportingDatabase.getArtifactIterator();
263 assertTrue( "check there is a failure", warnings.hasNext() );
264 ArtifactResults results = (ArtifactResults) warnings.next();
265 warnings = results.getWarnings().iterator();
266 assertTrue( "check there is a failure", warnings.hasNext() );
267 Result result = (Result) warnings.next();
268 assertArtifact( results );
269 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
270 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
271 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
272 assertFalse( "no more warnings", warnings.hasNext() );
275 public void testArtifactMultipleWarnings()
277 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "First Warning" );
278 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "Second Warning" );
279 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
280 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
281 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
283 Iterator warnings = reportingDatabase.getArtifactIterator();
284 assertTrue( "check there is a failure", warnings.hasNext() );
285 ArtifactResults results = (ArtifactResults) warnings.next();
286 warnings = results.getWarnings().iterator();
287 assertTrue( "check there is a failure", warnings.hasNext() );
288 Result result = (Result) warnings.next();
289 assertArtifact( results );
290 assertEquals( "check failure reason", "First Warning", result.getReason() );
291 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
292 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
293 assertTrue( "must have 2nd warning", warnings.hasNext() );
294 result = (Result) warnings.next();
295 assertEquals( "check failure reason", "Second Warning", result.getReason() );
296 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
297 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
298 assertFalse( "no more warnings", warnings.hasNext() );
301 public void testArtifactSingleNotice()
303 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "Single Notice Message" );
304 assertEquals( "failure count", 0, reportingDatabase.getNumFailures() );
305 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
306 assertEquals( "check notices", 1, reportingDatabase.getNumNotices() );
308 Iterator warnings = reportingDatabase.getArtifactIterator();
309 assertTrue( "check there is a failure", warnings.hasNext() );
310 ArtifactResults results = (ArtifactResults) warnings.next();
311 warnings = results.getNotices().iterator();
312 assertTrue( "check there is a failure", warnings.hasNext() );
313 Result result = (Result) warnings.next();
314 assertArtifact( results );
315 assertEquals( "check failure reason", "Single Notice Message", result.getReason() );
316 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
317 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
318 assertFalse( "no more warnings", warnings.hasNext() );
321 public void testArtifactMultipleNotices()
323 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "First Notice" );
324 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "Second Notice" );
325 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
326 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
327 assertEquals( "check no notices", 2, reportingDatabase.getNumNotices() );
329 Iterator warnings = reportingDatabase.getArtifactIterator();
330 assertTrue( "check there is a failure", warnings.hasNext() );
331 ArtifactResults results = (ArtifactResults) warnings.next();
332 warnings = results.getNotices().iterator();
333 assertTrue( "check there is a failure", warnings.hasNext() );
334 Result result = (Result) warnings.next();
335 assertArtifact( results );
336 assertEquals( "check failure reason", "First Notice", result.getReason() );
337 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
338 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
339 assertTrue( "must have 2nd warning", warnings.hasNext() );
340 result = (Result) warnings.next();
341 assertEquals( "check failure reason", "Second Notice", result.getReason() );
342 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
343 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
344 assertFalse( "no more warnings", warnings.hasNext() );
347 protected void setUp()
352 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
354 artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
356 Versioning versioning = new Versioning();
357 versioning.addVersion( "1.0-alpha-1" );
358 versioning.addVersion( "1.0-alpha-2" );
360 metadata = new ArtifactRepositoryMetadata( artifact, versioning );
362 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
363 reportingDatabase = new ReportingDatabase( reportGroup );