1 package org.apache.maven.archiva.reporting.reporter;
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.archiva.reporting.group.ReportGroup;
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.apache.maven.artifact.factory.ArtifactFactory;
27 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
28 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
29 import org.apache.maven.artifact.repository.metadata.Versioning;
31 import java.util.Iterator;
36 public class DefaultArtifactReporterTest
37 extends AbstractRepositoryReportsTestCase
39 private ReportingDatabase reportingDatabase;
41 private RepositoryMetadata metadata;
43 private static final String PROCESSOR = "processor";
45 private static final String PROBLEM = "problem";
47 private Artifact artifact;
49 public void testEmptyArtifactReporter()
51 assertEquals( "No failures", 0, reportingDatabase.getNumFailures() );
52 assertEquals( "No warnings", 0, reportingDatabase.getNumWarnings() );
53 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
54 assertFalse( "No artifact failures", reportingDatabase.getArtifactIterator().hasNext() );
55 assertFalse( "No metadata failures", reportingDatabase.getMetadataIterator().hasNext() );
58 public void testMetadataSingleFailure()
60 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Single Failure Reason" );
61 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
62 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
63 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
65 Iterator failures = reportingDatabase.getMetadataIterator();
66 assertTrue( "check there is a failure", failures.hasNext() );
67 MetadataResults results = (MetadataResults) failures.next();
68 failures = results.getFailures().iterator();
69 assertTrue( "check there is a failure", failures.hasNext() );
70 Result result = (Result) failures.next();
71 assertMetadata( results );
72 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
73 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
74 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
75 assertFalse( "no more failures", failures.hasNext() );
78 private void assertMetadata( MetadataResults result )
80 assertEquals( "check failure cause", metadata.getGroupId(), result.getGroupId() );
81 assertEquals( "check failure cause", metadata.getArtifactId(), result.getArtifactId() );
82 assertEquals( "check failure cause", metadata.getBaseVersion(), result.getVersion() );
85 public void testMetadataMultipleFailures()
87 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "First Failure Reason" );
88 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Second Failure Reason" );
89 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
90 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
91 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
93 Iterator failures = reportingDatabase.getMetadataIterator();
94 assertTrue( "check there is a failure", failures.hasNext() );
95 MetadataResults results = (MetadataResults) failures.next();
96 failures = results.getFailures().iterator();
97 assertTrue( "check there is a failure", failures.hasNext() );
98 Result result = (Result) failures.next();
99 assertMetadata( results );
100 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
101 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
102 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
103 assertTrue( "must have 2nd failure", failures.hasNext() );
104 result = (Result) failures.next();
105 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
106 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
107 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
108 assertFalse( "no more failures", failures.hasNext() );
111 public void testMetadataSingleWarning()
113 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Single Warning Message" );
114 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
115 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
116 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
118 Iterator warnings = reportingDatabase.getMetadataIterator();
119 assertTrue( "check there is a failure", warnings.hasNext() );
120 MetadataResults results = (MetadataResults) warnings.next();
121 warnings = results.getWarnings().iterator();
122 assertTrue( "check there is a failure", warnings.hasNext() );
123 Result result = (Result) warnings.next();
124 assertMetadata( results );
125 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
126 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
127 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
128 assertFalse( "no more warnings", warnings.hasNext() );
131 public void testMetadataMultipleWarnings()
133 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "First Warning" );
134 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Second Warning" );
135 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
136 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
137 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
139 Iterator warnings = reportingDatabase.getMetadataIterator();
140 assertTrue( "check there is a failure", warnings.hasNext() );
141 MetadataResults results = (MetadataResults) warnings.next();
142 warnings = results.getWarnings().iterator();
143 assertTrue( "check there is a failure", warnings.hasNext() );
144 Result result = (Result) warnings.next();
145 assertMetadata( results );
146 assertEquals( "check failure reason", "First Warning", result.getReason() );
147 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
148 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
149 assertTrue( "must have 2nd warning", warnings.hasNext() );
150 result = (Result) warnings.next();
151 assertEquals( "check failure reason", "Second Warning", result.getReason() );
152 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
153 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
154 assertFalse( "no more warnings", warnings.hasNext() );
157 public void testMetadataSingleNotice()
159 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "Single Notice Message" );
160 assertEquals( "failure count", 0, reportingDatabase.getNumFailures() );
161 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
162 assertEquals( "check notices", 1, reportingDatabase.getNumNotices() );
164 Iterator warnings = reportingDatabase.getMetadataIterator();
165 assertTrue( "check there is a failure", warnings.hasNext() );
166 MetadataResults results = (MetadataResults) warnings.next();
167 warnings = results.getNotices().iterator();
168 assertTrue( "check there is a failure", warnings.hasNext() );
169 Result result = (Result) warnings.next();
170 assertMetadata( results );
171 assertEquals( "check failure reason", "Single Notice Message", result.getReason() );
172 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
173 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
174 assertFalse( "no more warnings", warnings.hasNext() );
177 public void testMetadataMultipleNotices()
179 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "First Notice" );
180 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "Second Notice" );
181 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
182 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
183 assertEquals( "check no notices", 2, reportingDatabase.getNumNotices() );
185 Iterator warnings = reportingDatabase.getMetadataIterator();
186 assertTrue( "check there is a failure", warnings.hasNext() );
187 MetadataResults results = (MetadataResults) warnings.next();
188 warnings = results.getNotices().iterator();
189 assertTrue( "check there is a failure", warnings.hasNext() );
190 Result result = (Result) warnings.next();
191 assertMetadata( results );
192 assertEquals( "check failure reason", "First Notice", result.getReason() );
193 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
194 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
195 assertTrue( "must have 2nd warning", warnings.hasNext() );
196 result = (Result) warnings.next();
197 assertEquals( "check failure reason", "Second Notice", result.getReason() );
198 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
199 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
200 assertFalse( "no more warnings", warnings.hasNext() );
203 public void testArtifactSingleFailure()
205 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "Single Failure Reason" );
206 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
207 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
208 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
210 Iterator failures = reportingDatabase.getArtifactIterator();
211 assertTrue( "check there is a failure", failures.hasNext() );
212 ArtifactResults results = (ArtifactResults) failures.next();
213 failures = results.getFailures().iterator();
214 assertTrue( "check there is a failure", failures.hasNext() );
215 Result result = (Result) failures.next();
216 assertArtifact( results );
217 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
218 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
219 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
220 assertFalse( "no more failures", failures.hasNext() );
223 private void assertArtifact( ArtifactResults results )
225 assertEquals( "check failure cause", artifact.getGroupId(), results.getGroupId() );
226 assertEquals( "check failure cause", artifact.getArtifactId(), results.getArtifactId() );
227 assertEquals( "check failure cause", artifact.getVersion(), results.getVersion() );
228 assertEquals( "check failure cause", artifact.getClassifier(), results.getClassifier() );
229 assertEquals( "check failure cause", artifact.getType(), results.getType() );
232 public void testArtifactMultipleFailures()
234 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "First Failure Reason" );
235 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "Second Failure Reason" );
236 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
237 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
238 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
240 Iterator failures = reportingDatabase.getArtifactIterator();
241 assertTrue( "check there is a failure", failures.hasNext() );
242 ArtifactResults results = (ArtifactResults) failures.next();
243 failures = results.getFailures().iterator();
244 assertTrue( "check there is a failure", failures.hasNext() );
245 Result result = (Result) failures.next();
246 assertArtifact( results );
247 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
248 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
249 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
250 assertTrue( "must have 2nd failure", failures.hasNext() );
251 result = (Result) failures.next();
252 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
253 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
254 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
255 assertFalse( "no more failures", failures.hasNext() );
258 public void testArtifactSingleWarning()
260 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "Single Warning Message" );
261 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
262 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
263 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
265 Iterator warnings = reportingDatabase.getArtifactIterator();
266 assertTrue( "check there is a failure", warnings.hasNext() );
267 ArtifactResults results = (ArtifactResults) warnings.next();
268 warnings = results.getWarnings().iterator();
269 assertTrue( "check there is a failure", warnings.hasNext() );
270 Result result = (Result) warnings.next();
271 assertArtifact( results );
272 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
273 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
274 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
275 assertFalse( "no more warnings", warnings.hasNext() );
278 public void testArtifactMultipleWarnings()
280 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "First Warning" );
281 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "Second Warning" );
282 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
283 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
284 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
286 Iterator warnings = reportingDatabase.getArtifactIterator();
287 assertTrue( "check there is a failure", warnings.hasNext() );
288 ArtifactResults results = (ArtifactResults) warnings.next();
289 warnings = results.getWarnings().iterator();
290 assertTrue( "check there is a failure", warnings.hasNext() );
291 Result result = (Result) warnings.next();
292 assertArtifact( results );
293 assertEquals( "check failure reason", "First Warning", result.getReason() );
294 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
295 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
296 assertTrue( "must have 2nd warning", warnings.hasNext() );
297 result = (Result) warnings.next();
298 assertEquals( "check failure reason", "Second Warning", result.getReason() );
299 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
300 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
301 assertFalse( "no more warnings", warnings.hasNext() );
304 public void testArtifactSingleNotice()
306 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "Single Notice Message" );
307 assertEquals( "failure count", 0, reportingDatabase.getNumFailures() );
308 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
309 assertEquals( "check notices", 1, reportingDatabase.getNumNotices() );
311 Iterator warnings = reportingDatabase.getArtifactIterator();
312 assertTrue( "check there is a failure", warnings.hasNext() );
313 ArtifactResults results = (ArtifactResults) warnings.next();
314 warnings = results.getNotices().iterator();
315 assertTrue( "check there is a failure", warnings.hasNext() );
316 Result result = (Result) warnings.next();
317 assertArtifact( results );
318 assertEquals( "check failure reason", "Single Notice Message", result.getReason() );
319 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
320 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
321 assertFalse( "no more warnings", warnings.hasNext() );
324 public void testArtifactMultipleNotices()
326 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "First Notice" );
327 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "Second Notice" );
328 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
329 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
330 assertEquals( "check no notices", 2, reportingDatabase.getNumNotices() );
332 Iterator warnings = reportingDatabase.getArtifactIterator();
333 assertTrue( "check there is a failure", warnings.hasNext() );
334 ArtifactResults results = (ArtifactResults) warnings.next();
335 warnings = results.getNotices().iterator();
336 assertTrue( "check there is a failure", warnings.hasNext() );
337 Result result = (Result) warnings.next();
338 assertArtifact( results );
339 assertEquals( "check failure reason", "First Notice", result.getReason() );
340 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
341 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
342 assertTrue( "must have 2nd warning", warnings.hasNext() );
343 result = (Result) warnings.next();
344 assertEquals( "check failure reason", "Second Notice", result.getReason() );
345 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
346 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
347 assertFalse( "no more warnings", warnings.hasNext() );
350 protected void setUp()
355 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
357 artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
359 Versioning versioning = new Versioning();
360 versioning.addVersion( "1.0-alpha-1" );
361 versioning.addVersion( "1.0-alpha-2" );
363 metadata = new ArtifactRepositoryMetadata( artifact, versioning );
365 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
366 reportingDatabase = new ReportingDatabase( reportGroup );