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 reporter;
37 private RepositoryMetadata metadata;
39 public void testEmptyArtifactReporter()
41 assertEquals( "No failures", 0, reporter.getNumFailures() );
42 assertEquals( "No warnings", 0, reporter.getNumWarnings() );
43 assertFalse( "No artifact failures", reporter.getArtifactIterator().hasNext() );
44 assertFalse( "No metadata failures", reporter.getMetadataIterator().hasNext() );
47 public void testMetadataSingleFailure()
49 reporter.addFailure( metadata, "Single Failure Reason" );
50 assertEquals( "failures count", 1, reporter.getNumFailures() );
51 assertEquals( "warnings count", 0, reporter.getNumWarnings() );
53 Iterator failures = reporter.getMetadataIterator();
54 assertTrue( "check there is a failure", failures.hasNext() );
55 MetadataResults results = (MetadataResults) failures.next();
56 failures = results.getFailures().iterator();
57 assertTrue( "check there is a failure", failures.hasNext() );
58 Result result = (Result) failures.next();
59 assertMetadata( results );
60 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
61 assertFalse( "no more failures", failures.hasNext() );
64 private void assertMetadata( MetadataResults result )
66 assertEquals( "check failure cause", metadata.getGroupId(), result.getGroupId() );
67 assertEquals( "check failure cause", metadata.getArtifactId(), result.getArtifactId() );
68 assertEquals( "check failure cause", metadata.getBaseVersion(), result.getVersion() );
71 public void testMetadataMultipleFailures()
73 reporter.addFailure( metadata, "First Failure Reason" );
74 reporter.addFailure( metadata, "Second Failure Reason" );
75 assertEquals( "failures count", 2, reporter.getNumFailures() );
76 assertEquals( "warnings count", 0, reporter.getNumWarnings() );
78 Iterator failures = reporter.getMetadataIterator();
79 assertTrue( "check there is a failure", failures.hasNext() );
80 MetadataResults results = (MetadataResults) failures.next();
81 failures = results.getFailures().iterator();
82 assertTrue( "check there is a failure", failures.hasNext() );
83 Result result = (Result) failures.next();
84 assertMetadata( results );
85 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
86 assertTrue( "must have 2nd failure", failures.hasNext() );
87 result = (Result) failures.next();
88 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
89 assertFalse( "no more failures", failures.hasNext() );
92 public void testMetadataSingleWarning()
94 reporter.addWarning( metadata, "Single Warning Message" );
95 assertEquals( "warnings count", 0, reporter.getNumFailures() );
96 assertEquals( "warnings count", 1, reporter.getNumWarnings() );
98 Iterator warnings = reporter.getMetadataIterator();
99 assertTrue( "check there is a failure", warnings.hasNext() );
100 MetadataResults results = (MetadataResults) warnings.next();
101 warnings = results.getWarnings().iterator();
102 assertTrue( "check there is a failure", warnings.hasNext() );
103 Result result = (Result) warnings.next();
104 assertMetadata( results );
105 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
106 assertFalse( "no more warnings", warnings.hasNext() );
109 public void testMetadataMultipleWarnings()
111 reporter.addWarning( metadata, "First Warning" );
112 reporter.addWarning( metadata, "Second Warning" );
113 assertEquals( "warnings count", 0, reporter.getNumFailures() );
114 assertEquals( "warnings count", 2, reporter.getNumWarnings() );
116 Iterator warnings = reporter.getMetadataIterator();
117 assertTrue( "check there is a failure", warnings.hasNext() );
118 MetadataResults results = (MetadataResults) warnings.next();
119 warnings = results.getWarnings().iterator();
120 assertTrue( "check there is a failure", warnings.hasNext() );
121 Result result = (Result) warnings.next();
122 assertMetadata( results );
123 assertEquals( "check failure reason", "First Warning", result.getReason() );
124 assertTrue( "must have 2nd warning", warnings.hasNext() );
125 result = (Result) warnings.next();
126 assertEquals( "check failure reason", "Second Warning", result.getReason() );
127 assertFalse( "no more warnings", warnings.hasNext() );
130 protected void setUp()
135 reporter = new ReportingDatabase();
136 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
137 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
139 Versioning versioning = new Versioning();
140 versioning.addVersion( "1.0-alpha-1" );
141 versioning.addVersion( "1.0-alpha-2" );
143 metadata = new ArtifactRepositoryMetadata( artifact, versioning );