1 package org.apache.maven.repository.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.artifact.Artifact;
20 import org.apache.maven.artifact.factory.ArtifactFactory;
21 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
22 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
23 import org.apache.maven.artifact.repository.metadata.Versioning;
25 import java.util.Iterator;
30 public class DefaultArtifactReporterTest
31 extends AbstractRepositoryReportsTestCase
33 private ArtifactReporter reporter;
35 private Artifact artifact;
37 private RepositoryMetadata metadata;
39 public void testEmptyArtifactReporter()
41 assertEquals( "No failures", 0, reporter.getFailures() );
42 assertEquals( "No warnings", 0, reporter.getWarnings() );
43 assertEquals( "No successes", 0, reporter.getSuccesses() );
44 assertFalse( "No artifact failures", reporter.getArtifactFailureIterator().hasNext() );
45 assertFalse( "No artifact warnings", reporter.getArtifactWarningIterator().hasNext() );
46 assertFalse( "No artifact successes", reporter.getArtifactSuccessIterator().hasNext() );
47 assertFalse( "No metadata failures", reporter.getRepositoryMetadataFailureIterator().hasNext() );
48 assertFalse( "No metadata warnings", reporter.getRepositoryMetadataWarningIterator().hasNext() );
49 assertFalse( "No metadata successes", reporter.getRepositoryMetadataSuccessIterator().hasNext() );
52 public void testMetadataSingleFailure()
54 reporter.addFailure( metadata, "Single Failure Reason" );
55 assertEquals( "failures count", 1, reporter.getFailures() );
56 assertEquals( "warnings count", 0, reporter.getWarnings() );
57 assertEquals( "successes count", 0, reporter.getSuccesses() );
59 Iterator results = reporter.getRepositoryMetadataFailureIterator();
60 assertTrue( "must have failures", results.hasNext() );
61 RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
62 assertEquals( "check failure cause", metadata, result.getMetadata() );
63 assertEquals( "check failure reason", "Single Failure Reason", result.getReason() );
64 assertFalse( "no more failures", results.hasNext() );
67 public void testMetadataMultipleFailures()
69 reporter.addFailure( metadata, "First Failure Reason" );
70 reporter.addFailure( metadata, "Second Failure Reason" );
71 assertEquals( "failures count", 2, reporter.getFailures() );
72 assertEquals( "warnings count", 0, reporter.getWarnings() );
73 assertEquals( "successes count", 0, reporter.getSuccesses() );
75 Iterator results = reporter.getRepositoryMetadataFailureIterator();
76 assertTrue( "must have failures", results.hasNext() );
77 RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
78 assertEquals( "check failure cause", metadata, result.getMetadata() );
79 assertEquals( "check failure reason", "First Failure Reason", result.getReason() );
80 assertTrue( "must have 2nd failure", results.hasNext() );
81 result = (RepositoryMetadataResult) results.next();
82 assertEquals( "check failure cause", metadata, result.getMetadata() );
83 assertEquals( "check failure reason", "Second Failure Reason", result.getReason() );
84 assertFalse( "no more failures", results.hasNext() );
87 public void testMetadataSingleWarning()
89 reporter.addWarning( metadata, "Single Warning Message" );
90 assertEquals( "failures count", 0, reporter.getFailures() );
91 assertEquals( "warnings count", 1, reporter.getWarnings() );
92 assertEquals( "successes count", 0, reporter.getSuccesses() );
94 Iterator results = reporter.getRepositoryMetadataWarningIterator();
95 assertTrue( "must have failures", results.hasNext() );
96 RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
97 assertEquals( "check failure cause", metadata, result.getMetadata() );
98 assertEquals( "check failure reason", "Single Warning Message", result.getReason() );
99 assertFalse( "no more failures", results.hasNext() );
102 public void testMetadataMultipleWarnings()
104 reporter.addWarning( metadata, "First Warning" );
105 reporter.addWarning( metadata, "Second Warning" );
106 assertEquals( "failures count", 0, reporter.getFailures() );
107 assertEquals( "warnings count", 2, reporter.getWarnings() );
108 assertEquals( "successes count", 0, reporter.getSuccesses() );
110 Iterator results = reporter.getRepositoryMetadataWarningIterator();
111 assertTrue( "must have warnings", results.hasNext() );
112 RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
113 assertEquals( "check failure cause", metadata, result.getMetadata() );
114 assertEquals( "check failure reason", "First Warning", result.getReason() );
115 assertTrue( "must have 2nd warning", results.hasNext() );
116 result = (RepositoryMetadataResult) results.next();
117 assertEquals( "check failure cause", metadata, result.getMetadata() );
118 assertEquals( "check failure reason", "Second Warning", result.getReason() );
119 assertFalse( "no more failures", results.hasNext() );
122 public void testMetadataSingleSuccess()
124 reporter.addSuccess( metadata );
125 assertEquals( "failures count", 0, reporter.getFailures() );
126 assertEquals( "warnings count", 0, reporter.getWarnings() );
127 assertEquals( "successes count", 1, reporter.getSuccesses() );
129 Iterator results = reporter.getRepositoryMetadataSuccessIterator();
130 assertTrue( "must have successes", results.hasNext() );
131 RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
132 assertEquals( "check success metadata", metadata, result.getMetadata() );
133 assertNull( "check no reason", result.getReason() );
134 assertFalse( "no more failures", results.hasNext() );
137 public void testMetadataMultipleSuccesses()
139 Versioning versioning = new Versioning();
140 versioning.addVersion( "1.0-beta-1" );
141 versioning.addVersion( "1.0-beta-2" );
142 RepositoryMetadata metadata2 = new ArtifactRepositoryMetadata( artifact, versioning );
144 reporter.addSuccess( metadata );
145 reporter.addSuccess( metadata2 );
146 assertEquals( "failures count", 0, reporter.getFailures() );
147 assertEquals( "warnings count", 0, reporter.getWarnings() );
148 assertEquals( "successes count", 2, reporter.getSuccesses() );
150 Iterator results = reporter.getRepositoryMetadataSuccessIterator();
151 assertTrue( "must have successes", results.hasNext() );
152 RepositoryMetadataResult result = (RepositoryMetadataResult) results.next();
153 assertEquals( "check success metadata", metadata, result.getMetadata() );
154 assertNull( "check no reason", result.getReason() );
155 assertTrue( "must have 2nd success", results.hasNext() );
156 result = (RepositoryMetadataResult) results.next();
157 assertEquals( "check success metadata", metadata2, result.getMetadata() );
158 assertNull( "check no reason", result.getReason() );
159 assertFalse( "no more successes", results.hasNext() );
162 protected void setUp()
167 reporter = new DefaultArtifactReporter();
168 ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
169 artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
171 Versioning versioning = new Versioning();
172 versioning.addVersion( "1.0-alpha-1" );
173 versioning.addVersion( "1.0-alpha-2" );
176 protected void tearDown()