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.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.GroupRepositoryMetadata;
23 import org.apache.maven.artifact.repository.metadata.Plugin;
24 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
25 import org.apache.maven.artifact.repository.metadata.Snapshot;
26 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
27 import org.apache.maven.artifact.repository.metadata.Versioning;
29 import java.util.Iterator;
31 public class BadMetadataReportProcessorTest
32 extends AbstractRepositoryReportsTestCase
34 private ArtifactFactory artifactFactory;
36 private MetadataReportProcessor badMetadataReportProcessor;
38 protected void setUp()
43 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
45 badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE );
48 public void testMetadataMissingLastUpdated()
49 throws ReportProcessorException
51 ArtifactReporter reporter = new MockArtifactReporter();
53 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
55 Versioning versioning = new Versioning();
56 versioning.addVersion( "1.0-alpha-1" );
57 versioning.addVersion( "1.0-alpha-2" );
59 RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
61 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
63 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
64 assertTrue( "check there is a failure", failures.hasNext() );
65 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
66 assertEquals( "check metadata", metadata, result.getMetadata() );
67 assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() );
68 assertFalse( "check no more failures", failures.hasNext() );
71 public void testMetadataValidVersions()
72 throws ReportProcessorException
74 ArtifactReporter reporter = new MockArtifactReporter();
76 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
78 Versioning versioning = new Versioning();
79 versioning.addVersion( "1.0-alpha-1" );
80 versioning.addVersion( "1.0-alpha-2" );
81 versioning.setLastUpdated( "20050611.202020" );
83 RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
85 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
87 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
88 assertFalse( "check there are no failures", failures.hasNext() );
91 public void testMetadataMissingADirectory()
92 throws ReportProcessorException
94 ArtifactReporter reporter = new MockArtifactReporter();
96 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
98 Versioning versioning = new Versioning();
99 versioning.addVersion( "1.0-alpha-1" );
100 versioning.setLastUpdated( "20050611.202020" );
102 RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
104 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
106 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
107 assertTrue( "check there is a failure", failures.hasNext() );
108 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
109 assertEquals( "check metadata", metadata, result.getMetadata() );
110 // TODO: should be more robust
111 assertEquals( "check reason",
112 "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.",
113 result.getReason() );
114 assertFalse( "check no more failures", failures.hasNext() );
117 public void testMetadataInvalidArtifactVersion()
118 throws ReportProcessorException
120 ArtifactReporter reporter = new MockArtifactReporter();
122 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
124 Versioning versioning = new Versioning();
125 versioning.addVersion( "1.0-alpha-1" );
126 versioning.addVersion( "1.0-alpha-2" );
127 versioning.addVersion( "1.0-alpha-3" );
128 versioning.setLastUpdated( "20050611.202020" );
130 RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
132 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
134 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
135 assertTrue( "check there is a failure", failures.hasNext() );
136 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
137 assertEquals( "check metadata", metadata, result.getMetadata() );
138 // TODO: should be more robust
139 assertEquals( "check reason",
140 "Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.",
141 result.getReason() );
142 assertFalse( "check no more failures", failures.hasNext() );
145 public void testMoreThanOneMetadataVersionErrors()
146 throws ReportProcessorException
148 ArtifactReporter reporter = new MockArtifactReporter();
150 Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
152 Versioning versioning = new Versioning();
153 versioning.addVersion( "1.0-alpha-1" );
154 versioning.addVersion( "1.0-alpha-3" );
155 versioning.setLastUpdated( "20050611.202020" );
157 RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning );
159 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
161 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
162 assertTrue( "check there is a failure", failures.hasNext() );
163 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
164 assertEquals( "check metadata", metadata, result.getMetadata() );
165 // TODO: should be more robust
166 assertEquals( "check reason",
167 "Artifact version 1.0-alpha-3 is present in metadata but missing in the repository.",
168 result.getReason() );
169 assertTrue( "check there is a 2nd failure", failures.hasNext() );
170 result = (RepositoryMetadataResult) failures.next();
171 // TODO: should be more robust
172 assertEquals( "check reason",
173 "Artifact version 1.0-alpha-2 found in the repository but missing in the metadata.",
174 result.getReason() );
175 assertFalse( "check no more failures", failures.hasNext() );
178 public void testValidPluginMetadata()
179 throws ReportProcessorException
181 ArtifactReporter reporter = new MockArtifactReporter();
183 RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
184 metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
185 metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
187 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
189 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
190 assertFalse( "check there are no failures", failures.hasNext() );
193 public void testMissingMetadataPlugin()
194 throws ReportProcessorException
196 ArtifactReporter reporter = new MockArtifactReporter();
198 RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
199 metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
200 metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
201 metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) );
203 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
205 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
206 assertTrue( "check there is a failure", failures.hasNext() );
207 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
208 // TODO: should be more robust
209 assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository",
210 result.getReason() );
211 assertFalse( "check no more failures", failures.hasNext() );
214 public void testIncompletePluginMetadata()
215 throws ReportProcessorException
217 ArtifactReporter reporter = new MockArtifactReporter();
219 RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
220 metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
222 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
224 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
225 assertTrue( "check there is a failure", failures.hasNext() );
226 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
227 // TODO: should be more robust
228 assertEquals( "check reason",
229 "Plugin snapshot-artifact is present in the repository but " + "missing in the metadata.",
230 result.getReason() );
231 assertFalse( "check no more failures", failures.hasNext() );
234 public void testInvalidPluginArtifactId()
235 throws ReportProcessorException
237 ArtifactReporter reporter = new MockArtifactReporter();
239 RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
240 metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
241 metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) );
242 metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) );
243 metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) );
245 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
247 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
248 assertTrue( "check there is a failure", failures.hasNext() );
249 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
250 // TODO: should be more robust
251 assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() );
252 assertTrue( "check there is a 2nd failure", failures.hasNext() );
253 result = (RepositoryMetadataResult) failures.next();
254 // TODO: should be more robust
255 assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() );
256 assertFalse( "check no more failures", failures.hasNext() );
259 public void testInvalidPluginPrefix()
260 throws ReportProcessorException
262 ArtifactReporter reporter = new MockArtifactReporter();
264 RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
265 metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) );
266 metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "" ) );
268 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
270 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
271 assertTrue( "check there is a failure", failures.hasNext() );
272 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
273 // TODO: should be more robust
274 assertEquals( "check reason", "Missing or empty plugin prefix for artifactId artifactId.", result.getReason() );
275 assertTrue( "check there is a 2nd failure", failures.hasNext() );
276 result = (RepositoryMetadataResult) failures.next();
277 // TODO: should be more robust
278 assertEquals( "check reason", "Missing or empty plugin prefix for artifactId snapshot-artifact.",
279 result.getReason() );
280 assertFalse( "check no more failures", failures.hasNext() );
283 public void testDuplicatePluginPrefixes()
284 throws ReportProcessorException
286 ArtifactReporter reporter = new MockArtifactReporter();
288 RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" );
289 metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) );
290 metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default" ) );
292 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
294 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
295 assertTrue( "check there is a failure", failures.hasNext() );
296 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
297 // TODO: should be more robust
298 assertEquals( "check reason", "Duplicate plugin prefix found: default.", result.getReason() );
299 assertFalse( "check no more failures", failures.hasNext() );
302 public void testValidSnapshotMetadata()
303 throws ReportProcessorException
305 ArtifactReporter reporter = new MockArtifactReporter();
308 artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
310 Snapshot snapshot = new Snapshot();
311 snapshot.setBuildNumber( 1 );
312 snapshot.setTimestamp( "20050611.202024" );
314 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
316 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
318 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
319 assertFalse( "check there are no failures", failures.hasNext() );
322 public void testInvalidSnapshotMetadata()
323 throws ReportProcessorException
325 ArtifactReporter reporter = new MockArtifactReporter();
328 artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
330 Snapshot snapshot = new Snapshot();
331 snapshot.setBuildNumber( 2 );
332 snapshot.setTimestamp( "20050611.202024" );
334 RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot );
336 badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
338 Iterator failures = reporter.getRepositoryMetadataFailureIterator();
339 assertTrue( "check there is a failure", failures.hasNext() );
340 RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
341 assertEquals( "check metadata", metadata, result.getMetadata() );
342 // TODO: should be more robust
343 assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() );
344 assertFalse( "check no more failures", failures.hasNext() );
347 private Plugin createMetadataPlugin( String artifactId, String prefix )
349 Plugin plugin = new Plugin();
350 plugin.setArtifactId( artifactId );
351 plugin.setName( artifactId );
352 plugin.setPrefix( prefix );