1 package org.apache.maven.archiva.proxy;
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.commons.lang.StringUtils;
23 import org.apache.maven.archiva.common.utils.VersionUtil;
24 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
25 import org.apache.maven.archiva.model.Plugin;
26 import org.apache.maven.archiva.model.ProjectReference;
27 import org.apache.maven.archiva.model.SnapshotVersion;
28 import org.apache.maven.archiva.model.VersionedReference;
29 import org.apache.maven.archiva.policies.CachedFailuresPolicy;
30 import org.apache.maven.archiva.policies.ChecksumPolicy;
31 import org.apache.maven.archiva.policies.ReleasesPolicy;
32 import org.apache.maven.archiva.policies.SnapshotsPolicy;
33 import org.apache.maven.archiva.repository.metadata.MetadataTools;
34 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
35 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
36 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
37 import org.apache.maven.wagon.TransferFailedException;
38 import org.custommonkey.xmlunit.DetailedDiff;
39 import org.custommonkey.xmlunit.Diff;
42 import java.io.StringWriter;
43 import java.util.Arrays;
46 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
47 * present in the repository.
49 * Test Case Naming is as follows.
52 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
56 * Which should leave the following matrix of test cases.
58 * Metadata | Proxied | Local | Remote
59 * ----------+----------+-------+---------
60 * Release | Not | Not | n/a (1)
61 * Release | Not | On | n/a (1)
62 * Release | | Not | Not
63 * Release | | Not | On
64 * Release | | Not | Multiple
65 * Release | | On | Not
67 * Release | | On | Multiple
68 * Snapshot | Not | Not | n/a (1)
69 * Snapshot | Not | On | n/a (1)
70 * Snapshot | | Not | Not
71 * Snapshot | | Not | On
72 * Snapshot | | Not | Multiple
73 * Snapshot | | On | Not
74 * Snapshot | | On | On
75 * Snapshot | | On | Multiple
76 * Project | Not | Not | n/a (1)
77 * Project | Not | On | n/a (1)
78 * Project | | Not | Not
79 * Project | | Not | On
80 * Project | | Not | Multiple
81 * Project | | On | Not
83 * Project | | On | Multiple
85 * (1) If it isn't proxied, no point in having a remote.
90 public class MetadataTransferTest
91 extends AbstractProxyTestCase
96 private MetadataTools metadataTools;
98 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
101 // New project metadata that does not exist locally but exists on remote.
102 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
103 setupTestableManagedRepository( requestedResource );
105 // Configure Connector (usually done within archiva.xml configuration)
106 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
107 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true);
109 assertResourceNotFound( requestedResource );
110 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
112 File expectedFile = new File( managedDefaultDir, requestedResource );
114 ProjectReference metadata = createProjectReference( requestedResource );
116 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) );
118 assertNull( "Should not have downloaded a file.", downloadedFile );
119 assertNoTempFiles( expectedFile );
122 // TODO: same test for other fetch* methods
123 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
126 // Project metadata that does not exist locally, but has multiple versions in remote repos
127 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
128 setupTestableManagedRepository( requestedResource );
130 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
132 // Configure Connector (usually done within archiva.xml configuration)
133 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
134 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
135 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
136 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
138 assertResourceNotFound( requestedResource );
139 assertNoRepoMetadata( "badproxied1", requestedResource );
140 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
142 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
143 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
144 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
145 wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
147 wagonMockControl.setMatcher(customWagonGetMatcher);
149 wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) );
151 wagonMockControl.replay();
153 assertFetchProjectOrGroup( requestedResource );
155 wagonMockControl.verify();
157 assertProjectMetadataContents( requestedResource, new String[] { "1.0.1" }, "1.0.1", "1.0.1" );
158 assertNoRepoMetadata( "badproxied1", requestedResource );
159 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } );
163 * Attempt to get the project metadata for non-existant artifact.
165 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
166 * to the requesting client.
168 public void testGetProjectMetadataNotProxiedNotLocal()
171 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
172 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
173 setupTestableManagedRepository( requestedResource );
175 assertResourceNotFound( requestedResource );
177 // No proxy setup, nothing fetched, failure expected.
178 assertFetchProjectOrGroupFailed( requestedResource );
180 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
181 assertResourceNotFound( requestedResource );
184 public void testGetProjectMetadataNotProxiedOnLocal()
187 // Project metadata that exists and has multiple versions
188 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
189 setupTestableManagedRepository( requestedResource );
191 assertResourceExists( requestedResource );
193 // No proxy setup, nothing fetched from remote, but local exists.
194 assertFetchProjectOrGroup( requestedResource );
196 // Nothing fetched. Should only contain contents of what is in the repository.
197 // A metadata update is not performed in this use case. Local metadata content is only
198 // updated via the metadata updater consumer.
199 assertProjectMetadataContents( requestedResource, new String[] { "1.0" }, null, null );
202 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
205 // Project metadata that does not exist locally, but has multiple versions in remote repos
206 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
207 setupTestableManagedRepository( requestedResource );
209 // Configure Connector (usually done within archiva.xml configuration)
210 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
211 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
212 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
213 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
215 assertResourceNotFound( requestedResource );
216 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
217 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
219 // Two proxies setup, metadata fetched from both remotes.
220 assertFetchProjectOrGroup( requestedResource );
222 // Nothing fetched. Should only contain contents of what is in the repository.
223 assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
224 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0" } );
225 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } );
228 public void testGetProjectMetadataProxiedNotLocalNotRemote()
231 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
232 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
233 setupTestableManagedRepository( requestedResource );
235 // Configure Connector (usually done within archiva.xml configuration)
236 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
237 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
238 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
239 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
241 assertResourceNotFound( requestedResource );
242 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
243 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
245 // Two proxies setup, nothing fetched from remotes, local does not exist.
246 assertFetchProjectOrGroupFailed( requestedResource );
248 // Nothing fetched. Nothing should exist.
249 assertResourceNotFound( requestedResource );
250 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
251 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
254 public void testGetProjectMetadataProxiedNotLocalOnRemote()
257 // New project metadata that does not exist locally but exists on remote.
258 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
259 setupTestableManagedRepository( requestedResource );
261 // Configure Connector (usually done within archiva.xml configuration)
262 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
263 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
265 assertResourceNotFound( requestedResource );
266 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
268 // One proxy setup, metadata fetched from remote, local does not exist.
269 assertFetchProjectOrGroup( requestedResource );
271 // Remote fetched. Local created/updated.
272 assertProjectMetadataContents( requestedResource, new String[] { "1.0.5" }, "1.0.5", "1.0.5" );
273 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0.5" } );
276 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
279 // Project metadata that exist locally, and has multiple versions in remote repos
280 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
281 setupTestableManagedRepository( requestedResource );
283 // Configure Connector (usually done within archiva.xml configuration)
284 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
285 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
286 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
287 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
289 assertProjectMetadataContents( requestedResource, new String[] { "1.0" }, null, null );
290 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
291 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
293 // Two proxies setup, metadata fetched from both remotes.
294 assertFetchProjectOrGroup( requestedResource );
296 // metadata fetched from both repos, and merged with local version.
297 assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
298 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0", "2.0" } );
299 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0", "1.0.1" } );
302 public void testGetProjectMetadataProxiedOnLocalNotRemote()
305 // Project metadata that exist locally, and does not exist in remote repos.
306 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
307 setupTestableManagedRepository( requestedResource );
309 // Configure Connector (usually done within archiva.xml configuration)
310 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
311 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
312 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
313 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
315 assertProjectMetadataContents( requestedResource, new String[] { "1.0-beta-2" }, null, null );
316 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
317 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
319 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
320 assertFetchProjectOrGroup( requestedResource );
322 // metadata not fetched from both repos, and local version exists.
323 // Since there was no updated metadata content from a remote/proxy, a metadata update on
324 // the local file never ran. Local only updates are performed via the metadata updater consumer.
325 assertProjectMetadataContents( requestedResource, new String[] { "1.0-beta-2" }, null, null );
326 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
327 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
330 public void testGetProjectMetadataProxiedOnLocalOnRemote()
333 // Project metadata that exist locally and exists on remote.
334 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
335 setupTestableManagedRepository( requestedResource );
337 // Configure Connector (usually done within archiva.xml configuration)
338 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
339 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
341 assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22" }, null, null );
342 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
344 // One proxy setup, metadata fetched from remote, local exists.
345 assertFetchProjectOrGroup( requestedResource );
347 // Remote fetched. Local updated.
348 assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
349 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0.22", "2.0" } );
353 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
354 * repository has no proxied repositories set up.
356 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
357 * to the requesting client.
359 public void testGetReleaseMetadataNotProxiedNotLocal()
362 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
363 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
364 setupTestableManagedRepository( requestedResource );
366 assertNoMetadata( requestedResource );
368 // No proxy setup, nothing fetched, failure expected.
369 assertFetchVersionedFailed( requestedResource );
371 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
372 assertNoMetadata( requestedResource );
376 * A request for a maven-metadata.xml file that does exist locally, and the managed
377 * repository has no proxied repositories set up.
379 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
380 * information, and then returned to the client.
382 public void testGetReleaseMetadataNotProxiedOnLocal()
385 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
386 setupTestableManagedRepository( requestedResource );
388 assertResourceExists( requestedResource );
390 assertFetchVersioned( requestedResource );
392 assertReleaseMetadataContents( requestedResource );
396 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
397 * exists on multiple remote repositories.
399 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
400 * file location on the managed repository, a merge of the contents to the requested
401 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
402 * returned to the client.
404 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
407 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
408 setupTestableManagedRepository( requestedResource );
410 // Configure Connector (usually done within archiva.xml configuration)
411 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
412 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
413 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
414 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
416 assertResourceNotFound( requestedResource );
417 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
418 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
420 assertFetchVersioned( requestedResource );
422 assertReleaseMetadataContents( requestedResource );
423 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
424 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
428 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
429 * proxied repository.
431 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
432 * information, and then return to the client.
434 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
437 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
438 setupTestableManagedRepository( requestedResource );
440 // Configure Connector (usually done within archiva.xml configuration)
441 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
442 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
444 assertResourceNotFound( requestedResource );
446 assertFetchProjectOrGroupFailed( requestedResource );
448 assertResourceNotFound( requestedResource );
449 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
453 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
454 * exists on 1 remote repository.
456 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
457 * file location on the managed repository, a merge of the contents to the requested
458 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
459 * returned to the client.
461 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
464 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
465 setupTestableManagedRepository( requestedResource );
467 // Configure Connector (usually done within archiva.xml configuration)
468 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
469 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
471 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
473 assertFetchVersioned( requestedResource );
475 assertReleaseMetadataContents( requestedResource );
476 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
480 * A request for a maven-metadata.xml file that exists in the managed repository, but
481 * not on any remote repository.
483 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
484 * is not downloaded. There is no repository specific metadata file on the managed
485 * repository. The managed repository maven-metadata.xml is returned to the
488 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
491 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
492 setupTestableManagedRepository( requestedResource );
494 // Configure Connector (usually done within archiva.xml configuration)
495 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
496 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
498 assertReleaseMetadataContents( requestedResource );
500 assertFetchVersioned( requestedResource );
502 assertReleaseMetadataContents( requestedResource );
503 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
507 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
508 * remote repositories.
510 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
511 * and merged into the contents of the existing managed repository copy of
512 * the maven-metadata.xml file.
514 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
517 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
518 setupTestableManagedRepository( requestedResource );
520 // Configure Connector (usually done within archiva.xml configuration)
521 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
522 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
523 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
524 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
526 assertReleaseMetadataContents( requestedResource );
527 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
528 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
530 assertFetchVersioned( requestedResource );
532 assertReleaseMetadataContents( requestedResource );
533 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
534 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
538 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
541 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
542 * and merged into the contents of the existing managed repository copy of
543 * the maven-metadata.xml file.
545 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
548 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
549 setupTestableManagedRepository( requestedResource );
551 // Configure Connector (usually done within archiva.xml configuration)
552 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
553 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
555 assertReleaseMetadataContents( requestedResource );
556 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
558 assertFetchVersioned( requestedResource );
560 assertReleaseMetadataContents( requestedResource );
561 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
564 public void testGetSnapshotMetadataNotProxiedNotLocal()
567 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
568 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
569 setupTestableManagedRepository( requestedResource );
571 assertNoMetadata( requestedResource );
573 // No proxy setup, nothing fetched, no local file, failure expected.
574 assertFetchVersionedFailed( requestedResource );
576 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
577 assertNoMetadata( requestedResource );
580 public void testGetSnapshotMetadataNotProxiedOnLocal()
583 // The artifactId exists locally (but not on a remote repo)
584 String requestedResource = "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
585 setupTestableManagedRepository( requestedResource );
587 assertResourceExists( requestedResource );
589 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
590 assertFetchVersioned( requestedResource );
592 // Local metadata exists, should be updated to reflect the latest release.
593 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
596 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
599 String requestedResource = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
600 setupTestableManagedRepository( requestedResource );
602 // Configure Connector (usually done within archiva.xml configuration)
603 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
604 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
605 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
606 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
608 assertResourceNotFound( requestedResource );
609 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
610 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
612 // Proxying 2 repos, both have content, local file updated.
613 assertFetchVersioned( requestedResource );
615 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
616 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
617 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
620 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
623 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
624 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
625 setupTestableManagedRepository( requestedResource );
627 // Configure Connector (usually done within archiva.xml configuration)
628 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
629 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
631 assertNoMetadata( requestedResource );
633 // One proxy setup, nothing fetched, no local file, failure expected.
634 assertFetchVersionedFailed( requestedResource );
636 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
637 assertNoMetadata( requestedResource );
638 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
641 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
644 // Artifact exists only in the proxied1 location.
645 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
646 setupTestableManagedRepository( requestedResource );
648 // Configure Connector (usually done within archiva.xml configuration)
649 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
650 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
652 assertResourceNotFound( requestedResource );
654 // One proxy setup, one metadata fetched, local file created/updated.
655 assertFetchVersioned( requestedResource );
657 // Local artifact Id should contain latest (which in this case is from proxied download)
658 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
659 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
662 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
665 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
666 setupTestableManagedRepository( requestedResource );
668 // Configure Connector (usually done within archiva.xml configuration)
669 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
670 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
671 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
672 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
674 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
675 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
676 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
678 // Proxying 2 repos, both have content, local file updated.
679 assertFetchVersioned( requestedResource );
681 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
682 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
683 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
686 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
689 // The artifactId exists locally (but not on a remote repo)
690 String requestedResource = "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
691 setupTestableManagedRepository( requestedResource );
693 // Configure Connector (usually done within archiva.xml configuration)
694 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
695 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
696 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
697 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
699 assertResourceExists( requestedResource );
700 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
701 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
703 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
704 assertFetchVersioned( requestedResource );
706 // Local metadata exists, repo metadatas should not exist, local file updated.
707 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
708 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
709 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
712 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
715 // The artifactId exists locally (but not on a remote repo)
716 String requestedResource = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
717 setupTestableManagedRepository( requestedResource );
719 // Configure Connector (usually done within archiva.xml configuration)
720 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
721 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
723 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
724 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
726 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
727 assertFetchVersioned( requestedResource );
729 // Local metadata exists, repo metadata exists, local file updated.
730 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
731 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
734 public void testGetGroupMetadataNotProxiedNotLocal()
737 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
738 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
739 setupTestableManagedRepository( requestedResource );
741 assertResourceNotFound( requestedResource );
743 // No proxy setup, nothing fetched, failure expected.
744 assertFetchProjectOrGroupFailed( requestedResource );
746 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
747 assertResourceNotFound( requestedResource );
750 public void testGetGroupMetadataNotProxiedOnLocal()
753 // Project metadata that exists and has multiple versions
754 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
755 setupTestableManagedRepository( requestedResource );
757 assertResourceExists( requestedResource );
759 // No proxy setup, nothing fetched from remote, but local exists.
760 assertFetchProjectOrGroup( requestedResource );
762 // Nothing fetched. Should only contain contents of what is in the repository.
763 // A metadata update is not performed in this use case. Local metadata content is only
764 // updated via the metadata updater consumer.
765 assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
768 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
771 // Project metadata that does not exist locally, but has multiple versions in remote repos
772 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
773 setupTestableManagedRepository( requestedResource );
775 // Configure Connector (usually done within archiva.xml configuration)
776 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
777 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
778 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
779 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
781 assertResourceNotFound( requestedResource );
782 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
783 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
785 // Two proxies setup, metadata fetched from both remotes.
786 assertFetchProjectOrGroup( requestedResource );
788 // Nothing fetched. Should only contain contents of what is in the repository.
789 assertGroupMetadataContents( requestedResource, new String[] { "plugin2", "plugin1" } );
790 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1" } );
791 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin2" } );
794 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
797 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
798 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
799 setupTestableManagedRepository( requestedResource );
801 // Configure Connector (usually done within archiva.xml configuration)
802 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
803 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
804 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
805 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
807 assertResourceNotFound( requestedResource );
808 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
809 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
811 // Two proxies setup, nothing fetched from remotes, local does not exist.
812 assertFetchProjectOrGroupFailed( requestedResource );
814 // Nothing fetched. Nothing should exist.
815 assertResourceNotFound( requestedResource );
816 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
817 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
820 public void testGetGroupMetadataProxiedNotLocalOnRemote()
823 // New project metadata that does not exist locally but exists on remote.
824 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
825 setupTestableManagedRepository( requestedResource );
827 // Configure Connector (usually done within archiva.xml configuration)
828 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
829 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
831 assertResourceNotFound( requestedResource );
832 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
834 // One proxy setup, metadata fetched from remote, local does not exist.
835 assertFetchProjectOrGroup( requestedResource );
837 // Remote fetched. Local created/updated.
838 assertGroupMetadataContents( requestedResource, new String[] { "plugin3" } );
839 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin3" } );
842 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
845 // Project metadata that exist locally, and has multiple versions in remote repos
846 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
847 setupTestableManagedRepository( requestedResource );
849 // Configure Connector (usually done within archiva.xml configuration)
850 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
851 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
852 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
853 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
855 assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
856 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
857 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
859 // Two proxies setup, metadata fetched from both remotes.
860 assertFetchProjectOrGroup( requestedResource );
862 // metadata fetched from both repos, and merged with local version.
863 assertGroupMetadataContents( requestedResource, new String[] { "plugin1", "plugin2", "plugin4" } );
864 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1", "plugin4" } );
865 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin1", "plugin2" } );
868 public void testGetGroupMetadataProxiedOnLocalNotRemote()
871 // Project metadata that exist locally, and does not exist in remote repos.
872 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
873 setupTestableManagedRepository( requestedResource );
875 // Configure Connector (usually done within archiva.xml configuration)
876 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
877 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
878 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
879 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
881 assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
882 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
883 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
885 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
886 assertFetchProjectOrGroup( requestedResource );
888 // metadata not fetched from both repos, and local version exists.
889 // Since there was no updated metadata content from a remote/proxy, a metadata update on
890 // the local file never ran. Local only updates are performed via the metadata updater consumer.
891 assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
892 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
893 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
896 public void testGetGroupMetadataProxiedOnLocalOnRemote()
899 // Project metadata that exist locally and exists on remote.
900 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
901 setupTestableManagedRepository( requestedResource );
903 // Configure Connector (usually done within archiva.xml configuration)
904 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
905 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
907 assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7" } );
908 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
910 // One proxy setup, metadata fetched from remote, local exists.
911 assertFetchProjectOrGroup( requestedResource );
913 // Remote fetched. Local updated.
914 assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7", "plugin4" } );
915 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin7", "plugin4" } );
919 * Transfer the metadata file.
921 * @param requestedResource the requested resource
924 private void assertFetchProjectOrGroup( String requestedResource )
927 File expectedFile = new File( managedDefaultDir, requestedResource );
929 ProjectReference metadata = createProjectReference( requestedResource );
931 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) );
933 assertNotNull( "Should have downloaded a file.", downloadedFile );
934 assertNoTempFiles( expectedFile );
937 private ProjectReference createProjectReference( String path )
938 throws RepositoryMetadataException
940 return metadataTools.toProjectReference( path );
944 * Transfer the metadata file, not expected to succeed.
946 * @param requestedResource the requested resource
949 private void assertFetchProjectOrGroupFailed( String requestedResource )
952 File expectedFile = new File( managedDefaultDir, requestedResource );
953 ProjectReference metadata = createProjectReference( requestedResource );
955 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) );
957 assertNull( downloadedFile );
958 assertNoTempFiles( expectedFile );
962 * Transfer the metadata file.
964 * @param requestedResource the requested resource
967 private void assertFetchVersioned( String requestedResource )
970 File expectedFile = new File( managedDefaultDir, requestedResource );
972 VersionedReference metadata = createVersionedReference( requestedResource );
974 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) );
976 assertNotNull( "Should have downloaded a file.", downloadedFile );
977 assertNoTempFiles( expectedFile );
980 private VersionedReference createVersionedReference( String path )
981 throws RepositoryMetadataException
983 return metadataTools.toVersionedReference( path );
987 * Transfer the metadata file, not expected to succeed.
989 * @param requestedResource the requested resource
992 private void assertFetchVersionedFailed( String requestedResource )
995 File expectedFile = new File( managedDefaultDir, requestedResource );
996 VersionedReference metadata = createVersionedReference( requestedResource );
998 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath(metadata) );
1000 assertNull( downloadedFile );
1001 assertNoTempFiles( expectedFile );
1005 * Test for the existance of the requestedResource in the default managed repository.
1007 * @param requestedResource the requested resource
1010 private void assertResourceExists( String requestedResource )
1013 File actualFile = new File( managedDefaultDir, requestedResource );
1014 assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() );
1017 private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
1020 assertNotNull( "Actual File should not be null.", actualFile );
1022 assertTrue( "Actual file exists.", actualFile.exists() );
1024 StringWriter actualContents = new StringWriter();
1025 ArchivaRepositoryMetadata metadata = RepositoryMetadataReader.read( actualFile );
1026 RepositoryMetadataWriter.write( metadata, actualContents );
1028 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1029 if ( !detailedDiff.similar() )
1031 assertEquals( expectedMetadataXml, actualContents );
1034 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1038 * Ensures that the requested resource is not present in the managed repository.
1040 * @param requestedResource the requested resource
1043 private void assertNoMetadata( String requestedResource )
1046 File expectedFile = new File( managedDefaultDir, requestedResource );
1047 assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() );
1051 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1052 * managed repository.
1053 * @param proxiedRepoId the proxied repository id to validate with.
1054 * @param requestedResource the resource requested.
1056 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1058 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1060 File actualFile = new File( managedDefaultDir, proxiedFile );
1061 assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
1064 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1067 File actualFile = new File( managedDefaultDir, requestedResource );
1068 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1070 ProjectReference actualMetadata = createGroupReference( requestedResource );
1072 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1075 private ProjectReference createGroupReference( String requestedResource )
1076 throws RepositoryMetadataException
1078 ProjectReference projectReference = createProjectReference( requestedResource );
1079 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1080 projectReference.setArtifactId( null );
1081 return projectReference;
1084 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1085 String expectedPlugins[] )
1088 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1090 File actualFile = new File( managedDefaultDir, proxiedFile );
1091 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
1093 ProjectReference actualMetadata = createGroupReference( requestedResource );
1095 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1098 private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1101 // Build expected metadata XML
1102 StringWriter expectedMetadataXml = new StringWriter();
1103 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1104 m.setGroupId( actualMetadata.getGroupId() );
1106 for ( String pluginId : expectedPlugins )
1108 Plugin p = new Plugin();
1109 p.setPrefix( pluginId );
1110 p.setArtifactId( pluginId + "-maven-plugin" );
1111 p.setName( "The " + pluginId + " Plugin" );
1112 m.getPlugins().add( p );
1115 m.setModelEncoding( null );
1116 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1118 // Compare the file to the actual contents.
1119 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1123 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1124 * does it contain the specified list of expected versions?
1126 * @param requestedResource the requested resource
1129 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1130 String latestVersion, String releaseVersion )
1133 File actualFile = new File( managedDefaultDir, requestedResource );
1134 assertTrue( actualFile.exists() );
1136 ProjectReference metadata = createProjectReference( requestedResource );
1138 // Build expected metadata XML
1139 StringWriter expectedMetadataXml = new StringWriter();
1140 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1141 m.setGroupId( metadata.getGroupId() );
1142 m.setArtifactId( metadata.getArtifactId() );
1143 m.setLatestVersion( latestVersion );
1144 m.setReleasedVersion( releaseVersion );
1146 if ( expectedVersions != null )
1148 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1151 m.setModelEncoding( null );
1152 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1154 // Compare the file to the actual contents.
1155 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1159 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1160 * does it contain the expected release maven-metadata.xml contents?
1162 * @param requestedResource the requested resource
1165 private void assertReleaseMetadataContents( String requestedResource )
1168 File actualFile = new File( managedDefaultDir, requestedResource );
1169 assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() );
1171 VersionedReference metadata = createVersionedReference( requestedResource );
1173 // Build expected metadata XML
1174 StringWriter expectedMetadataXml = new StringWriter();
1175 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1176 m.setGroupId( metadata.getGroupId() );
1177 m.setArtifactId( metadata.getArtifactId() );
1178 m.setVersion( metadata.getVersion() );
1179 m.setModelEncoding( null );
1180 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1182 // Compare the file to the actual contents.
1183 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1187 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1188 * does it contain the expected release maven-metadata.xml contents?
1190 * @param requestedResource the requested resource
1191 * @param expectedDate the date in "yyyyMMdd" format
1192 * @param expectedTime the time in "hhmmss" format
1193 * @param expectedBuildnumber the build number
1197 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1198 int expectedBuildnumber )
1201 File actualFile = new File( managedDefaultDir, requestedResource );
1202 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1204 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1206 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1210 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1211 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1213 * @param proxiedRepoId the repository id of the proxied repository.
1214 * @param requestedResource the requested resource
1215 * @param expectedDate the date in "yyyyMMdd" format
1216 * @param expectedTime the time in "hhmmss" format
1217 * @param expectedBuildnumber the build number
1221 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1222 String expectedDate, String expectedTime, int expectedBuildnumber )
1225 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1227 File actualFile = new File( managedDefaultDir, proxiedFile );
1228 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1230 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1232 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1235 private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate,
1236 String expectedTime, int expectedBuildnumber )
1237 throws RepositoryMetadataException, Exception
1239 // Build expected metadata XML
1240 StringWriter expectedMetadataXml = new StringWriter();
1241 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1242 m.setGroupId( actualMetadata.getGroupId() );
1243 m.setArtifactId( actualMetadata.getArtifactId() );
1244 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1246 m.setSnapshotVersion( new SnapshotVersion() );
1248 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1250 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1253 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1255 m.setLastUpdated( expectedDate + expectedTime );
1257 m.setModelEncoding( null );
1258 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1260 // Compare the file to the actual contents.
1261 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1265 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1266 * list of expected versions within.
1267 * @param proxiedRepoId
1268 * @param requestedResource
1269 * @param expectedProxyVersions
1271 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1272 String[] expectedProxyVersions )
1275 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1277 File actualFile = new File( managedDefaultDir, proxiedFile );
1278 assertTrue( actualFile.exists() );
1280 ProjectReference metadata = createProjectReference( requestedResource );
1282 // Build expected metadata XML
1283 StringWriter expectedMetadataXml = new StringWriter();
1284 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1285 m.setGroupId( metadata.getGroupId() );
1286 m.setArtifactId( metadata.getArtifactId() );
1288 if ( expectedProxyVersions != null )
1290 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1293 m.setModelEncoding( null );
1294 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1296 // Compare the file to the actual contents.
1297 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1301 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1302 * list of expected versions within.
1304 * @param proxiedRepoId
1305 * @param requestedResource
1307 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1310 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1312 File actualFile = new File( managedDefaultDir, proxiedFile );
1313 assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() );
1315 VersionedReference metadata = createVersionedReference( requestedResource );
1317 // Build expected metadata XML
1318 StringWriter expectedMetadataXml = new StringWriter();
1319 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1320 m.setGroupId( metadata.getGroupId() );
1321 m.setArtifactId( metadata.getArtifactId() );
1322 m.setVersion( metadata.getVersion() );
1323 m.setModelEncoding( null );
1324 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1326 // Compare the file to the actual contents.
1327 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1331 * Test for the non-existance of the requestedResource in the default managed repository.
1333 * @param requestedResource the requested resource
1336 private void assertResourceNotFound( String requestedResource )
1339 File actualFile = new File( managedDefaultDir, requestedResource );
1340 assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() );
1343 protected void setUp()
1348 metadataTools = (MetadataTools) lookup( MetadataTools.class );