1 package org.apache.maven.archiva.reporting.reporter;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.reporting.AbstractRepositoryReportsTestCase;
23 import org.apache.maven.archiva.reporting.database.ReportingDatabase;
24 import org.apache.maven.archiva.reporting.group.ReportGroup;
25 import org.apache.maven.archiva.reporting.model.ArtifactResults;
26 import org.apache.maven.archiva.reporting.model.MetadataResults;
27 import org.apache.maven.archiva.reporting.model.Result;
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.artifact.factory.ArtifactFactory;
30 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
31 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
32 import org.apache.maven.artifact.repository.metadata.Versioning;
34 import java.util.Iterator;
39 public class DefaultArtifactReporterTest
40 extends AbstractRepositoryReportsTestCase
42 private ReportingDatabase reportingDatabase;
44 private RepositoryMetadata metadata;
46 private static final String PROCESSOR = "processor";
48 private static final String PROBLEM = "problem";
50 private Artifact artifact;
52 public void testEmptyArtifactReporter()
54 assertEquals( "No failures", 0, reportingDatabase.getNumFailures() );
55 assertEquals( "No warnings", 0, reportingDatabase.getNumWarnings() );
56 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
57 assertFalse( "No artifact failures", reportingDatabase.getArtifactIterator().hasNext() );
58 assertFalse( "No metadata failures", reportingDatabase.getMetadataIterator().hasNext() );
61 public void testMetadataSingleFailure()
63 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Single Failure Reason" );
64 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
65 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
66 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
68 Iterator failures = reportingDatabase.getMetadataIterator();
69 assertTrue( "check there is a failure", failures.hasNext() );
70 MetadataResults results = (MetadataResults) failures.next();
71 failures = results.getFailures().iterator();
72 assertTrue( "check there is a failure", failures.hasNext() );
73 Result result = (Result) failures.next();
74 assertMetadata( results );
75 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
76 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
77 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
78 assertFalse( "no more failures", failures.hasNext() );
81 private void assertMetadata( MetadataResults result )
83 assertEquals( "check failure cause", metadata.getGroupId(), result.getGroupId() );
84 assertEquals( "check failure cause", metadata.getArtifactId(), result.getArtifactId() );
85 assertEquals( "check failure cause", metadata.getBaseVersion(), result.getVersion() );
88 public void testMetadataMultipleFailures()
90 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "First Failure Reason" );
91 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Second Failure Reason" );
92 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
93 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
94 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
96 Iterator failures = reportingDatabase.getMetadataIterator();
97 assertTrue( "check there is a failure", failures.hasNext() );
98 MetadataResults results = (MetadataResults) failures.next();
99 failures = results.getFailures().iterator();
100 assertTrue( "check there is a failure", failures.hasNext() );
101 Result result = (Result) failures.next();
102 assertMetadata( results );
103 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
104 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
105 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
106 assertTrue( "must have 2nd failure", failures.hasNext() );
107 result = (Result) failures.next();
108 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
109 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
110 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
111 assertFalse( "no more failures", failures.hasNext() );
114 public void testMetadataSingleWarning()
116 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Single Warning Message" );
117 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
118 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
119 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
121 Iterator warnings = reportingDatabase.getMetadataIterator();
122 assertTrue( "check there is a failure", warnings.hasNext() );
123 MetadataResults results = (MetadataResults) warnings.next();
124 warnings = results.getWarnings().iterator();
125 assertTrue( "check there is a failure", warnings.hasNext() );
126 Result result = (Result) warnings.next();
127 assertMetadata( results );
128 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
129 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
130 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
131 assertFalse( "no more warnings", warnings.hasNext() );
134 public void testMetadataMultipleWarnings()
136 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "First Warning" );
137 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Second Warning" );
138 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
139 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
140 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
142 Iterator warnings = reportingDatabase.getMetadataIterator();
143 assertTrue( "check there is a failure", warnings.hasNext() );
144 MetadataResults results = (MetadataResults) warnings.next();
145 warnings = results.getWarnings().iterator();
146 assertTrue( "check there is a failure", warnings.hasNext() );
147 Result result = (Result) warnings.next();
148 assertMetadata( results );
149 assertEquals( "check failure reason", "First Warning", result.getReason() );
150 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
151 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
152 assertTrue( "must have 2nd warning", warnings.hasNext() );
153 result = (Result) warnings.next();
154 assertEquals( "check failure reason", "Second Warning", result.getReason() );
155 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
156 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
157 assertFalse( "no more warnings", warnings.hasNext() );
160 public void testMetadataSingleNotice()
162 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "Single Notice Message" );
163 assertEquals( "failure count", 0, reportingDatabase.getNumFailures() );
164 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
165 assertEquals( "check notices", 1, reportingDatabase.getNumNotices() );
167 Iterator warnings = reportingDatabase.getMetadataIterator();
168 assertTrue( "check there is a failure", warnings.hasNext() );
169 MetadataResults results = (MetadataResults) warnings.next();
170 warnings = results.getNotices().iterator();
171 assertTrue( "check there is a failure", warnings.hasNext() );
172 Result result = (Result) warnings.next();
173 assertMetadata( results );
174 assertEquals( "check failure reason", "Single Notice Message", result.getReason() );
175 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
176 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
177 assertFalse( "no more warnings", warnings.hasNext() );
180 public void testMetadataMultipleNotices()
182 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "First Notice" );
183 reportingDatabase.addNotice( metadata, PROCESSOR, PROBLEM, "Second Notice" );
184 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
185 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
186 assertEquals( "check no notices", 2, reportingDatabase.getNumNotices() );
188 Iterator warnings = reportingDatabase.getMetadataIterator();
189 assertTrue( "check there is a failure", warnings.hasNext() );
190 MetadataResults results = (MetadataResults) warnings.next();
191 warnings = results.getNotices().iterator();
192 assertTrue( "check there is a failure", warnings.hasNext() );
193 Result result = (Result) warnings.next();
194 assertMetadata( results );
195 assertEquals( "check failure reason", "First Notice", result.getReason() );
196 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
197 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
198 assertTrue( "must have 2nd warning", warnings.hasNext() );
199 result = (Result) warnings.next();
200 assertEquals( "check failure reason", "Second Notice", result.getReason() );
201 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
202 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
203 assertFalse( "no more warnings", warnings.hasNext() );
206 public void testArtifactSingleFailure()
208 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "Single Failure Reason" );
209 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
210 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
211 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
213 Iterator failures = reportingDatabase.getArtifactIterator();
214 assertTrue( "check there is a failure", failures.hasNext() );
215 ArtifactResults results = (ArtifactResults) failures.next();
216 failures = results.getFailures().iterator();
217 assertTrue( "check there is a failure", failures.hasNext() );
218 Result result = (Result) failures.next();
219 assertArtifact( results );
220 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
221 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
222 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
223 assertFalse( "no more failures", failures.hasNext() );
226 private void assertArtifact( ArtifactResults results )
228 assertEquals( "check failure cause", artifact.getGroupId(), results.getGroupId() );
229 assertEquals( "check failure cause", artifact.getArtifactId(), results.getArtifactId() );
230 assertEquals( "check failure cause", artifact.getVersion(), results.getVersion() );
231 assertEquals( "check failure cause", artifact.getClassifier(), results.getClassifier() );
232 assertEquals( "check failure cause", artifact.getType(), results.getType() );
235 public void testArtifactMultipleFailures()
237 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "First Failure Reason" );
238 reportingDatabase.addFailure( artifact, PROCESSOR, PROBLEM, "Second Failure Reason" );
239 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
240 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
241 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
243 Iterator failures = reportingDatabase.getArtifactIterator();
244 assertTrue( "check there is a failure", failures.hasNext() );
245 ArtifactResults results = (ArtifactResults) failures.next();
246 failures = results.getFailures().iterator();
247 assertTrue( "check there is a failure", failures.hasNext() );
248 Result result = (Result) failures.next();
249 assertArtifact( results );
250 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
251 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
252 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
253 assertTrue( "must have 2nd failure", failures.hasNext() );
254 result = (Result) failures.next();
255 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
256 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
257 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
258 assertFalse( "no more failures", failures.hasNext() );
261 public void testArtifactSingleWarning()
263 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "Single Warning Message" );
264 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
265 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
266 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
268 Iterator warnings = reportingDatabase.getArtifactIterator();
269 assertTrue( "check there is a failure", warnings.hasNext() );
270 ArtifactResults results = (ArtifactResults) warnings.next();
271 warnings = results.getWarnings().iterator();
272 assertTrue( "check there is a failure", warnings.hasNext() );
273 Result result = (Result) warnings.next();
274 assertArtifact( results );
275 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
276 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
277 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
278 assertFalse( "no more warnings", warnings.hasNext() );
281 public void testArtifactMultipleWarnings()
283 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "First Warning" );
284 reportingDatabase.addWarning( artifact, PROCESSOR, PROBLEM, "Second Warning" );
285 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
286 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
287 assertEquals( "check no notices", 0, reportingDatabase.getNumNotices() );
289 Iterator warnings = reportingDatabase.getArtifactIterator();
290 assertTrue( "check there is a failure", warnings.hasNext() );
291 ArtifactResults results = (ArtifactResults) warnings.next();
292 warnings = results.getWarnings().iterator();
293 assertTrue( "check there is a failure", warnings.hasNext() );
294 Result result = (Result) warnings.next();
295 assertArtifact( results );
296 assertEquals( "check failure reason", "First Warning", result.getReason() );
297 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
298 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
299 assertTrue( "must have 2nd warning", warnings.hasNext() );
300 result = (Result) warnings.next();
301 assertEquals( "check failure reason", "Second Warning", result.getReason() );
302 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
303 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
304 assertFalse( "no more warnings", warnings.hasNext() );
307 public void testArtifactSingleNotice()
309 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "Single Notice Message" );
310 assertEquals( "failure count", 0, reportingDatabase.getNumFailures() );
311 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
312 assertEquals( "check notices", 1, reportingDatabase.getNumNotices() );
314 Iterator warnings = reportingDatabase.getArtifactIterator();
315 assertTrue( "check there is a failure", warnings.hasNext() );
316 ArtifactResults results = (ArtifactResults) warnings.next();
317 warnings = results.getNotices().iterator();
318 assertTrue( "check there is a failure", warnings.hasNext() );
319 Result result = (Result) warnings.next();
320 assertArtifact( results );
321 assertEquals( "check failure reason", "Single Notice Message", result.getReason() );
322 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
323 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
324 assertFalse( "no more warnings", warnings.hasNext() );
327 public void testArtifactMultipleNotices()
329 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "First Notice" );
330 reportingDatabase.addNotice( artifact, PROCESSOR, PROBLEM, "Second Notice" );
331 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
332 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
333 assertEquals( "check no notices", 2, reportingDatabase.getNumNotices() );
335 Iterator warnings = reportingDatabase.getArtifactIterator();
336 assertTrue( "check there is a failure", warnings.hasNext() );
337 ArtifactResults results = (ArtifactResults) warnings.next();
338 warnings = results.getNotices().iterator();
339 assertTrue( "check there is a failure", warnings.hasNext() );
340 Result result = (Result) warnings.next();
341 assertArtifact( results );
342 assertEquals( "check failure reason", "First Notice", result.getReason() );
343 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
344 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
345 assertTrue( "must have 2nd warning", warnings.hasNext() );
346 result = (Result) warnings.next();
347 assertEquals( "check failure reason", "Second Notice", result.getReason() );
348 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
349 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
350 assertFalse( "no more warnings", warnings.hasNext() );
353 protected void setUp()
358 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
360 artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
362 Versioning versioning = new Versioning();
363 versioning.addVersion( "1.0-alpha-1" );
364 versioning.addVersion( "1.0-alpha-2" );
366 metadata = new ArtifactRepositoryMetadata( artifact, versioning );
368 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
369 reportingDatabase = new ReportingDatabase( reportGroup );