1 package org.apache.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.archiva.common.filelock.DefaultFileLockManager;
23 import org.apache.archiva.common.utils.VersionUtil;
24 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
25 import org.apache.archiva.model.ArchivaRepositoryMetadata;
26 import org.apache.archiva.model.Plugin;
27 import org.apache.archiva.model.ProjectReference;
28 import org.apache.archiva.model.SnapshotVersion;
29 import org.apache.archiva.model.VersionedReference;
30 import org.apache.archiva.policies.CachedFailuresPolicy;
31 import org.apache.archiva.policies.ChecksumPolicy;
32 import org.apache.archiva.policies.ReleasesPolicy;
33 import org.apache.archiva.policies.SnapshotsPolicy;
34 import org.apache.archiva.repository.BaseRepositoryContentLayout;
35 import org.apache.archiva.repository.content.ContentItem;
36 import org.apache.archiva.repository.content.DataItem;
37 import org.apache.archiva.repository.content.Version;
38 import org.apache.archiva.repository.metadata.base.MetadataTools;
39 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
40 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
41 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
42 import org.apache.archiva.repository.storage.StorageAsset;
43 import org.apache.commons.lang3.StringUtils;
44 import org.apache.maven.wagon.TransferFailedException;
45 import org.easymock.EasyMock;
46 import org.junit.Test;
47 import org.xmlunit.builder.DiffBuilder;
48 import org.xmlunit.diff.Diff;
49 import org.xmlunit.diff.Difference;
51 import javax.inject.Inject;
52 import javax.inject.Named;
54 import java.io.StringWriter;
55 import java.nio.file.Files;
56 import java.nio.file.Path;
57 import java.util.ArrayList;
58 import java.util.Arrays;
60 import static org.junit.Assert.*;
63 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
64 * present in the repository.
66 * Test Case Naming is as follows.
69 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
73 * Which should leave the following matrix of test cases.
75 * Metadata | Proxied | Local | Remote
76 * ----------+----------+-------+---------
77 * Release | Not | Not | n/a (1)
78 * Release | Not | On | n/a (1)
79 * Release | | Not | Not
80 * Release | | Not | On
81 * Release | | Not | Multiple
82 * Release | | On | Not
84 * Release | | On | Multiple
85 * Snapshot | Not | Not | n/a (1)
86 * Snapshot | Not | On | n/a (1)
87 * Snapshot | | Not | Not
88 * Snapshot | | Not | On
89 * Snapshot | | Not | Multiple
90 * Snapshot | | On | Not
91 * Snapshot | | On | On
92 * Snapshot | | On | Multiple
93 * Project | Not | Not | n/a (1)
94 * Project | Not | On | n/a (1)
95 * Project | | Not | Not
96 * Project | | Not | On
97 * Project | | Not | Multiple
98 * Project | | On | Not
100 * Project | | On | Multiple
102 * (1) If it isn't proxied, no point in having a remote.
107 public class MetadataTransferTest
108 extends AbstractProxyTestCase
112 @Named(value = "metadataTools#mocked")
113 private MetadataTools metadataTools;
117 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
120 // New project metadata that does not exist locally but exists on remote.
121 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
122 setupTestableManagedRepository( requestedResource );
124 // Configure Connector (usually done within archiva.xml configuration)
125 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
126 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
128 assertResourceNotFound( requestedResource );
129 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
131 Path expectedFile = managedDefaultDir.resolve(requestedResource);
133 ProjectReference metadata = createProjectReference( requestedResource );
135 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
136 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
137 layout.toMetadataPath(
138 metadata ) ).getFile();
140 assertNull( "Should not have downloaded a file.", downloadedFile );
141 assertNoTempFiles( expectedFile );
144 // TODO: same test for other fetch* methods
146 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
149 // Project metadata that does not exist locally, but has multiple versions in remote repos
150 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
151 setupTestableManagedRepository( requestedResource );
153 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
155 // Configure Connector (usually done within archiva.xml configuration)
156 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
157 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
158 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
159 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
161 assertResourceNotFound( requestedResource );
162 assertNoRepoMetadata( "badproxied1", requestedResource );
163 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
165 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
166 Path expectedFile = managedDefaultDir.resolve(
167 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
169 wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
170 EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
173 wagonMockControl.replay();
175 assertFetchProjectOrGroup( requestedResource );
177 wagonMockControl.verify();
179 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
180 assertNoRepoMetadata( "badproxied1", requestedResource );
181 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
185 * Attempt to get the project metadata for non-existant artifact.
187 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
188 * to the requesting client.
191 public void testGetProjectMetadataNotProxiedNotLocal()
194 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
195 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
196 setupTestableManagedRepository( requestedResource );
198 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
200 assertResourceNotFound( requestedResource );
202 // No proxy setup, nothing fetched, failure expected.
203 assertFetchProjectOrGroupFailed( requestedResource );
205 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
206 assertResourceNotFound( requestedResource );
210 public void testGetProjectMetadataNotProxiedOnLocal()
214 // Project metadata that exists and has multiple versions
215 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
216 setupTestableManagedRepository( requestedResource );
218 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
220 assertResourceExists( requestedResource );
222 // No proxy setup, nothing fetched from remote, but local exists.
223 assertFetchProjectOrGroup( requestedResource );
225 // Nothing fetched. Should only contain contents of what is in the repository.
226 // A metadata update is not performed in this use case. Local metadata content is only
227 // updated via the metadata updater consumer.
228 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
232 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
235 // Project metadata that does not exist locally, but has multiple versions in remote repos
236 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
237 setupTestableManagedRepository( requestedResource );
239 // Configure Connector (usually done within archiva.xml configuration)
240 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
241 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
242 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
243 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
245 assertResourceNotFound( requestedResource );
246 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
247 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
249 // Two proxies setup, metadata fetched from both remotes.
250 assertFetchProjectOrGroup( requestedResource );
252 // Nothing fetched. Should only contain contents of what is in the repository.
253 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
254 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
255 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
259 public void testGetProjectMetadataProxiedNotLocalNotRemote()
262 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
263 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
264 setupTestableManagedRepository( requestedResource );
266 // Configure Connector (usually done within archiva.xml configuration)
267 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
268 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
269 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
270 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
272 assertResourceNotFound( requestedResource );
273 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
274 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
276 // Two proxies setup, nothing fetched from remotes, local does not exist.
277 assertFetchProjectOrGroupFailed( requestedResource );
279 // Nothing fetched. Nothing should exist.
280 assertResourceNotFound( requestedResource );
281 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
282 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
286 public void testGetProjectMetadataProxiedNotLocalOnRemote()
289 // New project metadata that does not exist locally but exists on remote.
290 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
291 setupTestableManagedRepository( requestedResource );
293 // Configure Connector (usually done within archiva.xml configuration)
294 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
295 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
297 assertResourceNotFound( requestedResource );
298 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
300 // One proxy setup, metadata fetched from remote, local does not exist.
301 assertFetchProjectOrGroup( requestedResource );
303 // Remote fetched. Local created/updated.
304 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
305 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
309 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
312 // Project metadata that exist locally, and has multiple versions in remote repos
313 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
314 setupTestableManagedRepository( requestedResource );
316 // Configure Connector (usually done within archiva.xml configuration)
317 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
318 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
319 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
320 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
322 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
323 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
324 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
326 // Two proxies setup, metadata fetched from both remotes.
327 assertFetchProjectOrGroup( requestedResource );
329 // metadata fetched from both repos, and merged with local version.
330 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
331 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
332 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
336 public void testGetProjectMetadataProxiedOnLocalNotRemote()
340 // Project metadata that exist locally, and does not exist in remote repos.
341 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
342 setupTestableManagedRepository( requestedResource );
345 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
346 // Configure Connector (usually done within archiva.xml configuration)
347 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
348 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
349 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
350 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
352 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
353 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
354 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
356 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
357 assertFetchProjectOrGroup( requestedResource );
359 // metadata not fetched from both repos, and local version exists.
360 // Since there was no updated metadata content from a remote/proxy, a metadata update on
361 // the local file never ran. Local only updates are performed via the metadata updater consumer.
362 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
363 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
364 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
368 public void testGetProjectMetadataProxiedOnLocalOnRemote()
371 // Project metadata that exist locally and exists on remote.
372 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
373 setupTestableManagedRepository( requestedResource );
375 // Configure Connector (usually done within archiva.xml configuration)
376 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
377 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
379 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
380 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
382 // One proxy setup, metadata fetched from remote, local exists.
383 assertFetchProjectOrGroup( requestedResource );
385 // Remote fetched. Local updated.
386 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
387 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
391 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
392 * repository has no proxied repositories set up.
394 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
395 * to the requesting client.
398 public void testGetReleaseMetadataNotProxiedNotLocal()
401 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
402 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
403 setupTestableManagedRepository( requestedResource );
405 assertNoMetadata( requestedResource );
407 // No proxy setup, nothing fetched, failure expected.
408 assertFetchVersionedFailed( requestedResource );
410 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
411 assertNoMetadata( requestedResource );
415 * A request for a maven-metadata.xml file that does exist locally, and the managed
416 * repository has no proxied repositories set up.
418 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
419 * information, and then returned to the client.
422 public void testGetReleaseMetadataNotProxiedOnLocal()
425 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
426 setupTestableManagedRepository( requestedResource );
428 assertResourceExists( requestedResource );
430 assertFetchVersioned( requestedResource );
432 assertReleaseMetadataContents( requestedResource );
436 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
437 * exists on multiple remote repositories.
439 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
440 * file location on the managed repository, a merge of the contents to the requested
441 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
442 * returned to the client.
445 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
448 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
449 setupTestableManagedRepository( requestedResource );
451 // Configure Connector (usually done within archiva.xml configuration)
452 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
453 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
454 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
455 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
457 assertResourceNotFound( requestedResource );
458 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
459 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
461 assertFetchVersioned( requestedResource );
463 assertReleaseMetadataContents( requestedResource );
464 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
465 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
469 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
470 * proxied repository.
472 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
473 * information, and then return to the client.
476 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
479 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
480 setupTestableManagedRepository( requestedResource );
482 // Configure Connector (usually done within archiva.xml configuration)
483 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
484 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
486 assertResourceNotFound( requestedResource );
488 assertFetchProjectOrGroupFailed( requestedResource );
490 assertResourceNotFound( requestedResource );
491 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
495 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
496 * exists on 1 remote repository.
498 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
499 * file location on the managed repository, a merge of the contents to the requested
500 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
501 * returned to the client.
504 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
507 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
508 setupTestableManagedRepository( requestedResource );
510 // Configure Connector (usually done within archiva.xml configuration)
511 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
512 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
514 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
516 assertFetchVersioned( requestedResource );
518 assertReleaseMetadataContents( requestedResource );
519 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
523 * A request for a maven-metadata.xml file that exists in the managed repository, but
524 * not on any remote repository.
526 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
527 * is not downloaded. There is no repository specific metadata file on the managed
528 * repository. The managed repository maven-metadata.xml is returned to the
532 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
535 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
536 setupTestableManagedRepository( requestedResource );
538 // Configure Connector (usually done within archiva.xml configuration)
539 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
540 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
542 assertReleaseMetadataContents( requestedResource );
544 assertFetchVersioned( requestedResource );
546 assertReleaseMetadataContents( requestedResource );
547 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
551 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
552 * remote repositories.
554 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
555 * and merged into the contents of the existing managed repository copy of
556 * the maven-metadata.xml file.
559 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
562 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
563 setupTestableManagedRepository( requestedResource );
565 // Configure Connector (usually done within archiva.xml configuration)
566 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
567 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
568 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
569 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
571 assertReleaseMetadataContents( requestedResource );
572 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
573 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
575 assertFetchVersioned( requestedResource );
577 assertReleaseMetadataContents( requestedResource );
578 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
579 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
583 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
586 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
587 * and merged into the contents of the existing managed repository copy of
588 * the maven-metadata.xml file.
591 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
594 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
595 setupTestableManagedRepository( requestedResource );
597 // Configure Connector (usually done within archiva.xml configuration)
598 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
599 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
601 assertReleaseMetadataContents( requestedResource );
602 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
604 assertFetchVersioned( requestedResource );
606 assertReleaseMetadataContents( requestedResource );
607 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
611 public void testGetSnapshotMetadataNotProxiedNotLocal()
614 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
615 String requestedResource =
616 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
617 setupTestableManagedRepository( requestedResource );
619 assertNoMetadata( requestedResource );
621 // No proxy setup, nothing fetched, no local file, failure expected.
622 assertFetchVersionedFailed( requestedResource );
624 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
625 assertNoMetadata( requestedResource );
629 public void testGetSnapshotMetadataNotProxiedOnLocal()
632 // The artifactId exists locally (but not on a remote repo)
633 String requestedResource =
634 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
635 setupTestableManagedRepository( requestedResource );
637 assertResourceExists( requestedResource );
639 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
640 assertFetchVersioned( requestedResource );
642 // Local metadata exists, should be updated to reflect the latest release.
643 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
647 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
650 String requestedResource =
651 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
652 setupTestableManagedRepository( requestedResource );
654 // Configure Connector (usually done within archiva.xml configuration)
655 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
656 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
657 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
658 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
660 assertResourceNotFound( requestedResource );
661 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
662 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
664 // Proxying 2 repos, both have content, local file updated.
665 assertFetchVersioned( requestedResource );
667 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
668 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
669 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
673 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
676 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
677 String requestedResource =
678 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
679 setupTestableManagedRepository( requestedResource );
681 // Configure Connector (usually done within archiva.xml configuration)
682 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
683 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
685 assertNoMetadata( requestedResource );
687 // One proxy setup, nothing fetched, no local file, failure expected.
688 assertFetchVersionedFailed( requestedResource );
690 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
691 assertNoMetadata( requestedResource );
692 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
696 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
699 // Artifact exists only in the proxied1 location.
700 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
701 setupTestableManagedRepository( requestedResource );
703 // Configure Connector (usually done within archiva.xml configuration)
704 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
705 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
707 assertResourceNotFound( requestedResource );
709 // One proxy setup, one metadata fetched, local file created/updated.
710 assertFetchVersioned( requestedResource );
712 // Local artifact Id should contain latest (which in this case is from proxied download)
713 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
714 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
718 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
721 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
722 setupTestableManagedRepository( requestedResource );
724 // Configure Connector (usually done within archiva.xml configuration)
725 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
726 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
727 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
728 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
730 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
731 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
732 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
734 // Proxying 2 repos, both have content, local file updated.
735 assertFetchVersioned( requestedResource );
737 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
738 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
739 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
743 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
746 // The artifactId exists locally (but not on a remote repo)
747 String requestedResource =
748 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
749 setupTestableManagedRepository( requestedResource );
751 // Configure Connector (usually done within archiva.xml configuration)
752 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
753 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
754 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
755 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
757 assertResourceExists( requestedResource );
758 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
759 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
761 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
762 assertFetchVersioned( requestedResource );
764 // Local metadata exists, repo metadatas should not exist, local file updated.
765 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
766 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
767 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
771 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
774 // The artifactId exists locally (but not on a remote repo)
775 String requestedResource =
776 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
777 setupTestableManagedRepository( requestedResource );
779 // Configure Connector (usually done within archiva.xml configuration)
780 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
781 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
783 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
784 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
786 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
787 assertFetchVersioned( requestedResource );
789 // Local metadata exists, repo metadata exists, local file updated.
790 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
791 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
795 public void testGetGroupMetadataNotProxiedNotLocal()
798 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
799 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
800 setupTestableManagedRepository( requestedResource );
802 assertResourceNotFound( requestedResource );
804 // No proxy setup, nothing fetched, failure expected.
805 assertFetchProjectOrGroupFailed( requestedResource );
807 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
808 assertResourceNotFound( requestedResource );
812 public void testGetGroupMetadataNotProxiedOnLocal()
815 // Project metadata that exists and has multiple versions
816 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
817 setupTestableManagedRepository( requestedResource );
819 assertResourceExists( requestedResource );
821 // No proxy setup, nothing fetched from remote, but local exists.
822 assertFetchProjectOrGroup( requestedResource );
824 // Nothing fetched. Should only contain contents of what is in the repository.
825 // A metadata update is not performed in this use case. Local metadata content is only
826 // updated via the metadata updater consumer.
827 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
831 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
834 // Project metadata that does not exist locally, but has multiple versions in remote repos
835 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
836 setupTestableManagedRepository( requestedResource );
838 // Configure Connector (usually done within archiva.xml configuration)
839 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
840 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
841 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
842 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
844 assertResourceNotFound( requestedResource );
845 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
846 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
848 // Two proxies setup, metadata fetched from both remotes.
849 assertFetchProjectOrGroup( requestedResource );
851 // Nothing fetched. Should only contain contents of what is in the repository.
852 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
853 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
854 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
858 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
861 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
862 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
863 setupTestableManagedRepository( requestedResource );
865 // Configure Connector (usually done within archiva.xml configuration)
866 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
867 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
868 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
869 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
871 assertResourceNotFound( requestedResource );
872 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
873 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
875 // Two proxies setup, nothing fetched from remotes, local does not exist.
876 assertFetchProjectOrGroupFailed( requestedResource );
878 // Nothing fetched. Nothing should exist.
879 assertResourceNotFound( requestedResource );
880 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
881 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
885 public void testGetGroupMetadataProxiedNotLocalOnRemote()
888 // New project metadata that does not exist locally but exists on remote.
889 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
890 setupTestableManagedRepository( requestedResource );
892 // Configure Connector (usually done within archiva.xml configuration)
893 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
894 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
896 assertResourceNotFound( requestedResource );
897 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
899 // One proxy setup, metadata fetched from remote, local does not exist.
900 assertFetchProjectOrGroup( requestedResource );
902 // Remote fetched. Local created/updated.
903 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
904 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
908 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
911 // Project metadata that exist locally, and has multiple versions in remote repos
912 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
913 setupTestableManagedRepository( requestedResource );
915 // Configure Connector (usually done within archiva.xml configuration)
916 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
917 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
918 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
919 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
921 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
922 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
923 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
925 // Two proxies setup, metadata fetched from both remotes.
926 assertFetchProjectOrGroup( requestedResource );
928 // metadata fetched from both repos, and merged with local version.
929 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
930 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
931 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
935 public void testGetGroupMetadataProxiedOnLocalNotRemote()
938 // Project metadata that exist locally, and does not exist in remote repos.
939 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
940 setupTestableManagedRepository( requestedResource );
942 // Configure Connector (usually done within archiva.xml configuration)
943 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
944 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
945 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
946 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
948 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
949 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
950 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
952 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
953 assertFetchProjectOrGroup( requestedResource );
955 // metadata not fetched from both repos, and local version exists.
956 // Since there was no updated metadata content from a remote/proxy, a metadata update on
957 // the local file never ran. Local only updates are performed via the metadata updater consumer.
958 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
959 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
960 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
964 public void testGetGroupMetadataProxiedOnLocalOnRemote()
967 // Project metadata that exist locally and exists on remote.
968 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
969 setupTestableManagedRepository( requestedResource );
971 // Configure Connector (usually done within archiva.xml configuration)
972 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
973 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
975 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
976 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
978 // One proxy setup, metadata fetched from remote, local exists.
979 assertFetchProjectOrGroup( requestedResource );
981 // Remote fetched. Local updated.
982 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
983 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
987 * Transfer the metadata file.
989 * @param requestedResource the requested resource
992 private void assertFetchProjectOrGroup( String requestedResource )
995 Path expectedFile = managedDefaultDir.resolve(requestedResource);
997 ProjectReference metadata = createProjectReference( requestedResource );
999 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1001 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1002 layout.toMetadataPath(
1003 metadata ) ).getFile();
1005 assertNotNull( "Should have downloaded a file.", downloadedFile );
1006 assertNoTempFiles( expectedFile );
1009 private ProjectReference createProjectReference( String path )
1010 throws RepositoryMetadataException
1012 return metadataTools.toProjectReference( path );
1016 * Transfer the metadata file, not expected to succeed.
1018 * @param requestedResource the requested resource
1021 private void assertFetchProjectOrGroupFailed( String requestedResource )
1024 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1025 ProjectReference metadata = createProjectReference( requestedResource );
1027 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1028 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1029 layout.toMetadataPath(
1030 metadata ) ).getFile();
1032 assertNull( downloadedFile );
1033 assertNoTempFiles( expectedFile );
1037 * Transfer the metadata file.
1039 * @param requestedResource the requested resource
1042 private void assertFetchVersioned( String requestedResource )
1045 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1047 ContentItem item = managedDefaultRepository.toItem( requestedResource );
1048 if (item instanceof DataItem) {
1049 item = managedDefaultRepository.getParent( item );
1051 assertNotNull( item );
1052 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1053 Version version = layout.adaptItem( Version.class, item );
1054 assertNotNull( version );
1055 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem(
1058 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1059 metaPath).getFile();
1061 assertNotNull( "Should have downloaded a file.", downloadedFile );
1062 assertNoTempFiles( expectedFile );
1065 private VersionedReference createVersionedReference( String path )
1066 throws RepositoryMetadataException
1068 return metadataTools.toVersionedReference( path );
1072 * Transfer the metadata file, not expected to succeed.
1074 * @param requestedResource the requested resource
1077 private void assertFetchVersionedFailed( String requestedResource )
1080 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1081 ContentItem item = managedDefaultRepository.toItem( requestedResource );
1082 assertNotNull( item );
1083 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1084 Version version = layout.adaptItem( Version.class, item );
1085 assertNotNull( version );
1086 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem(
1088 assertNotNull( metaPath );
1089 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1090 metaPath ).getFile();
1092 assertNull( downloadedFile );
1093 assertNoTempFiles( expectedFile );
1097 * Test for the existance of the requestedResource in the default managed repository.
1099 * @param requestedResource the requested resource
1102 private void assertResourceExists( String requestedResource )
1105 Path actualFile = managedDefaultDir.resolve(requestedResource);
1106 assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
1109 private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
1112 assertNotNull( "Actual File should not be null.", actualFile );
1114 assertTrue( "Actual file exists.", Files.exists(actualFile) );
1116 StringWriter actualContents = new StringWriter();
1117 FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
1118 StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
1119 ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader( null ).read( actualFileAsset );
1120 RepositoryMetadataWriter.write( metadata, actualContents );
1122 Diff detailedDiff = DiffBuilder.compare( expectedMetadataXml).withTest( actualContents.toString() ).checkForSimilar().build();
1123 if ( detailedDiff.hasDifferences() )
1125 for ( Difference diff : detailedDiff.getDifferences() )
1127 System.out.println( diff );
1129 assertEquals( expectedMetadataXml, actualContents );
1132 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1136 * Ensures that the requested resource is not present in the managed repository.
1138 * @param requestedResource the requested resource
1141 private void assertNoMetadata( String requestedResource )
1144 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1145 assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
1149 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1150 * managed repository.
1152 * @param proxiedRepoId the proxied repository id to validate with.
1153 * @param requestedResource the resource requested.
1155 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1157 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1159 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1160 assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
1163 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1166 Path actualFile = managedDefaultDir.resolve(requestedResource);
1167 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1169 ProjectReference actualMetadata = createGroupReference( requestedResource );
1171 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1174 private ProjectReference createGroupReference( String requestedResource )
1175 throws RepositoryMetadataException
1177 ProjectReference projectReference = createProjectReference( requestedResource );
1178 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1179 projectReference.setArtifactId( null );
1180 return projectReference;
1183 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1184 String expectedPlugins[] )
1187 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1189 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1190 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1192 ProjectReference actualMetadata = createGroupReference( requestedResource );
1194 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1197 private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1200 // Build expected metadata XML
1201 StringWriter expectedMetadataXml = new StringWriter();
1202 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1203 m.setGroupId( actualMetadata.getGroupId() );
1205 for ( String pluginId : expectedPlugins )
1207 Plugin p = new Plugin();
1208 p.setPrefix( pluginId );
1209 p.setArtifactId( pluginId + "-maven-plugin" );
1210 p.setName( "The " + pluginId + " Plugin" );
1211 m.getPlugins().add( p );
1214 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1216 // Compare the file to the actual contents.
1217 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1221 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1222 * does it contain the specified list of expected versions?
1224 * @param requestedResource the requested resource
1227 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1228 String latestVersion, String releaseVersion )
1231 Path actualFile = managedDefaultDir.resolve(requestedResource);
1232 assertTrue( Files.exists(actualFile) );
1234 ProjectReference metadata = createProjectReference( requestedResource );
1236 // Build expected metadata XML
1237 StringWriter expectedMetadataXml = new StringWriter();
1238 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1239 m.setGroupId( metadata.getGroupId() );
1240 m.setArtifactId( metadata.getArtifactId() );
1241 m.setLatestVersion( latestVersion );
1242 m.setReleasedVersion( releaseVersion );
1244 if ( expectedVersions != null )
1246 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1249 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1251 // Compare the file to the actual contents.
1252 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1256 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1257 * does it contain the expected release maven-metadata.xml contents?
1259 * @param requestedResource the requested resource
1262 private void assertReleaseMetadataContents( String requestedResource )
1265 Path actualFile = managedDefaultDir.resolve(requestedResource);
1266 assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1268 VersionedReference metadata = createVersionedReference( requestedResource );
1270 // Build expected metadata XML
1271 StringWriter expectedMetadataXml = new StringWriter();
1272 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1273 m.setGroupId( metadata.getGroupId() );
1274 m.setArtifactId( metadata.getArtifactId() );
1275 m.setVersion( metadata.getVersion() );
1276 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1278 // Compare the file to the actual contents.
1279 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1283 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1284 * does it contain the expected release maven-metadata.xml contents?
1286 * @param requestedResource the requested resource
1287 * @param expectedDate the date in "yyyyMMdd" format
1288 * @param expectedTime the time in "hhmmss" format
1289 * @param expectedBuildnumber the build number
1292 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1293 int expectedBuildnumber )
1296 Path actualFile = managedDefaultDir.resolve(requestedResource);
1297 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1299 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1301 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1305 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1306 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1308 * @param proxiedRepoId the repository id of the proxied repository.
1309 * @param requestedResource the requested resource
1310 * @param expectedDate the date in "yyyyMMdd" format
1311 * @param expectedTime the time in "hhmmss" format
1312 * @param expectedBuildnumber the build number
1315 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1316 String expectedDate, String expectedTime, int expectedBuildnumber )
1319 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1321 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1322 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1324 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1326 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1329 private void assertSnapshotMetadata( Path actualFile, VersionedReference actualMetadata, String expectedDate,
1330 String expectedTime, int expectedBuildnumber )
1331 throws RepositoryMetadataException, Exception
1333 // Build expected metadata XML
1334 StringWriter expectedMetadataXml = new StringWriter();
1335 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1336 m.setGroupId( actualMetadata.getGroupId() );
1337 m.setArtifactId( actualMetadata.getArtifactId() );
1338 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1340 m.setSnapshotVersion( new SnapshotVersion() );
1342 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1344 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1347 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1349 m.setLastUpdated( expectedDate + expectedTime );
1351 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1353 // Compare the file to the actual contents.
1354 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1358 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1359 * list of expected versions within.
1361 * @param proxiedRepoId
1362 * @param requestedResource
1363 * @param expectedProxyVersions
1365 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1366 String[] expectedProxyVersions )
1369 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1371 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1372 assertTrue( Files.exists(actualFile) );
1374 ProjectReference metadata = createProjectReference( requestedResource );
1376 // Build expected metadata XML
1377 StringWriter expectedMetadataXml = new StringWriter();
1378 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1379 m.setGroupId( metadata.getGroupId() );
1380 m.setArtifactId( metadata.getArtifactId() );
1382 if ( expectedProxyVersions != null )
1384 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1387 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1389 // Compare the file to the actual contents.
1390 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1394 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1395 * list of expected versions within.
1397 * @param proxiedRepoId
1398 * @param requestedResource
1400 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1403 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1405 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1406 assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
1408 VersionedReference metadata = createVersionedReference( requestedResource );
1410 // Build expected metadata XML
1411 StringWriter expectedMetadataXml = new StringWriter();
1412 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1413 m.setGroupId( metadata.getGroupId() );
1414 m.setArtifactId( metadata.getArtifactId() );
1415 m.setVersion( metadata.getVersion() );
1416 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1418 // Compare the file to the actual contents.
1419 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1423 * Test for the non-existance of the requestedResource in the default managed repository.
1425 * @param requestedResource the requested resource
1428 private void assertResourceNotFound( String requestedResource )
1431 Path actualFile = managedDefaultDir.resolve(requestedResource);
1432 assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );