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.MetadataResults;
20 import org.apache.maven.archiva.reporting.model.Result;
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.factory.ArtifactFactory;
23 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
24 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
25 import org.apache.maven.artifact.repository.metadata.Versioning;
27 import java.util.Iterator;
32 public class DefaultArtifactReporterTest
33 extends AbstractRepositoryReportsTestCase
35 private ReportingDatabase reportingDatabase;
37 private RepositoryMetadata metadata;
39 private static final String PROCESSOR = "processor";
41 private static final String PROBLEM = "problem";
43 public void testEmptyArtifactReporter()
45 assertEquals( "No failures", 0, reportingDatabase.getNumFailures() );
46 assertEquals( "No warnings", 0, reportingDatabase.getNumWarnings() );
47 assertFalse( "No artifact failures", reportingDatabase.getArtifactIterator().hasNext() );
48 assertFalse( "No metadata failures", reportingDatabase.getMetadataIterator().hasNext() );
51 public void testMetadataSingleFailure()
53 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Single Failure Reason" );
54 assertEquals( "failures count", 1, reportingDatabase.getNumFailures() );
55 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
57 Iterator failures = reportingDatabase.getMetadataIterator();
58 assertTrue( "check there is a failure", failures.hasNext() );
59 MetadataResults results = (MetadataResults) failures.next();
60 failures = results.getFailures().iterator();
61 assertTrue( "check there is a failure", failures.hasNext() );
62 Result result = (Result) failures.next();
63 assertMetadata( results );
64 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
65 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
66 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
67 assertFalse( "no more failures", failures.hasNext() );
70 private void assertMetadata( MetadataResults result )
72 assertEquals( "check failure cause", metadata.getGroupId(), result.getGroupId() );
73 assertEquals( "check failure cause", metadata.getArtifactId(), result.getArtifactId() );
74 assertEquals( "check failure cause", metadata.getBaseVersion(), result.getVersion() );
77 public void testMetadataMultipleFailures()
79 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "First Failure Reason" );
80 reportingDatabase.addFailure( metadata, PROCESSOR, PROBLEM, "Second Failure Reason" );
81 assertEquals( "failures count", 2, reportingDatabase.getNumFailures() );
82 assertEquals( "warnings count", 0, reportingDatabase.getNumWarnings() );
84 Iterator failures = reportingDatabase.getMetadataIterator();
85 assertTrue( "check there is a failure", failures.hasNext() );
86 MetadataResults results = (MetadataResults) failures.next();
87 failures = results.getFailures().iterator();
88 assertTrue( "check there is a failure", failures.hasNext() );
89 Result result = (Result) failures.next();
90 assertMetadata( results );
91 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
92 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
93 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
94 assertTrue( "must have 2nd failure", failures.hasNext() );
95 result = (Result) failures.next();
96 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
97 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
98 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
99 assertFalse( "no more failures", failures.hasNext() );
102 public void testMetadataSingleWarning()
104 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Single Warning Message" );
105 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
106 assertEquals( "warnings count", 1, reportingDatabase.getNumWarnings() );
108 Iterator warnings = reportingDatabase.getMetadataIterator();
109 assertTrue( "check there is a failure", warnings.hasNext() );
110 MetadataResults results = (MetadataResults) warnings.next();
111 warnings = results.getWarnings().iterator();
112 assertTrue( "check there is a failure", warnings.hasNext() );
113 Result result = (Result) warnings.next();
114 assertMetadata( results );
115 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
116 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
117 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
118 assertFalse( "no more warnings", warnings.hasNext() );
121 public void testMetadataMultipleWarnings()
123 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "First Warning" );
124 reportingDatabase.addWarning( metadata, PROCESSOR, PROBLEM, "Second Warning" );
125 assertEquals( "warnings count", 0, reportingDatabase.getNumFailures() );
126 assertEquals( "warnings count", 2, reportingDatabase.getNumWarnings() );
128 Iterator warnings = reportingDatabase.getMetadataIterator();
129 assertTrue( "check there is a failure", warnings.hasNext() );
130 MetadataResults results = (MetadataResults) warnings.next();
131 warnings = results.getWarnings().iterator();
132 assertTrue( "check there is a failure", warnings.hasNext() );
133 Result result = (Result) warnings.next();
134 assertMetadata( results );
135 assertEquals( "check failure reason", "First Warning", result.getReason() );
136 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
137 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
138 assertTrue( "must have 2nd warning", warnings.hasNext() );
139 result = (Result) warnings.next();
140 assertEquals( "check failure reason", "Second Warning", result.getReason() );
141 assertEquals( "check failure parameters", PROCESSOR, result.getProcessor() );
142 assertEquals( "check failure parameters", PROBLEM, result.getProblem() );
143 assertFalse( "no more warnings", warnings.hasNext() );
146 protected void setUp()
151 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
152 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
154 Versioning versioning = new Versioning();
155 versioning.addVersion( "1.0-alpha-1" );
156 versioning.addVersion( "1.0-alpha-2" );
158 metadata = new ArtifactRepositoryMetadata( artifact, versioning );
160 ReportGroup reportGroup = (ReportGroup) lookup( ReportGroup.ROLE, "health" );
161 reportingDatabase = new ReportingDatabase( reportGroup );