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.metadata.base.MetadataTools;
36 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
37 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
38 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
39 import org.apache.archiva.repository.storage.StorageAsset;
40 import org.apache.commons.lang3.StringUtils;
41 import org.apache.maven.wagon.TransferFailedException;
42 import org.easymock.EasyMock;
43 import org.junit.Test;
44 import org.xmlunit.builder.DiffBuilder;
45 import org.xmlunit.diff.Diff;
46 import org.xmlunit.diff.Difference;
48 import javax.inject.Inject;
49 import javax.inject.Named;
51 import java.io.StringWriter;
52 import java.nio.file.Files;
53 import java.nio.file.Path;
54 import java.util.ArrayList;
55 import java.util.Arrays;
57 import static org.junit.Assert.*;
60 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
61 * present in the repository.
63 * Test Case Naming is as follows.
66 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
70 * Which should leave the following matrix of test cases.
72 * Metadata | Proxied | Local | Remote
73 * ----------+----------+-------+---------
74 * Release | Not | Not | n/a (1)
75 * Release | Not | On | n/a (1)
76 * Release | | Not | Not
77 * Release | | Not | On
78 * Release | | Not | Multiple
79 * Release | | On | Not
81 * Release | | On | Multiple
82 * Snapshot | Not | Not | n/a (1)
83 * Snapshot | Not | On | n/a (1)
84 * Snapshot | | Not | Not
85 * Snapshot | | Not | On
86 * Snapshot | | Not | Multiple
87 * Snapshot | | On | Not
88 * Snapshot | | On | On
89 * Snapshot | | On | Multiple
90 * Project | Not | Not | n/a (1)
91 * Project | Not | On | n/a (1)
92 * Project | | Not | Not
93 * Project | | Not | On
94 * Project | | Not | Multiple
95 * Project | | On | Not
97 * Project | | On | Multiple
99 * (1) If it isn't proxied, no point in having a remote.
104 public class MetadataTransferTest
105 extends AbstractProxyTestCase
109 @Named(value = "metadataTools#mocked")
110 private MetadataTools metadataTools;
114 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
117 // New project metadata that does not exist locally but exists on remote.
118 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
119 setupTestableManagedRepository( requestedResource );
121 // Configure Connector (usually done within archiva.xml configuration)
122 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
123 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
125 assertResourceNotFound( requestedResource );
126 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
128 Path expectedFile = managedDefaultDir.resolve(requestedResource);
130 ProjectReference metadata = createProjectReference( requestedResource );
132 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
133 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
134 layout.toMetadataPath(
135 metadata ) ).getFile();
137 assertNull( "Should not have downloaded a file.", downloadedFile );
138 assertNoTempFiles( expectedFile );
141 // TODO: same test for other fetch* methods
143 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
146 // Project metadata that does not exist locally, but has multiple versions in remote repos
147 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
148 setupTestableManagedRepository( requestedResource );
150 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
152 // Configure Connector (usually done within archiva.xml configuration)
153 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
154 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
155 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
156 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
158 assertResourceNotFound( requestedResource );
159 assertNoRepoMetadata( "badproxied1", requestedResource );
160 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
162 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
163 Path expectedFile = managedDefaultDir.resolve(
164 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
166 wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
167 EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
170 wagonMockControl.replay();
172 assertFetchProjectOrGroup( requestedResource );
174 wagonMockControl.verify();
176 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
177 assertNoRepoMetadata( "badproxied1", requestedResource );
178 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
182 * Attempt to get the project metadata for non-existant artifact.
184 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
185 * to the requesting client.
188 public void testGetProjectMetadataNotProxiedNotLocal()
191 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
192 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
193 setupTestableManagedRepository( requestedResource );
195 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
197 assertResourceNotFound( requestedResource );
199 // No proxy setup, nothing fetched, failure expected.
200 assertFetchProjectOrGroupFailed( requestedResource );
202 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
203 assertResourceNotFound( requestedResource );
207 public void testGetProjectMetadataNotProxiedOnLocal()
211 // Project metadata that exists and has multiple versions
212 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
213 setupTestableManagedRepository( requestedResource );
215 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
217 assertResourceExists( requestedResource );
219 // No proxy setup, nothing fetched from remote, but local exists.
220 assertFetchProjectOrGroup( requestedResource );
222 // Nothing fetched. Should only contain contents of what is in the repository.
223 // A metadata update is not performed in this use case. Local metadata content is only
224 // updated via the metadata updater consumer.
225 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
229 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
232 // Project metadata that does not exist locally, but has multiple versions in remote repos
233 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
234 setupTestableManagedRepository( requestedResource );
236 // Configure Connector (usually done within archiva.xml configuration)
237 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
238 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
239 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
240 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
242 assertResourceNotFound( requestedResource );
243 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
244 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
246 // Two proxies setup, metadata fetched from both remotes.
247 assertFetchProjectOrGroup( requestedResource );
249 // Nothing fetched. Should only contain contents of what is in the repository.
250 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
251 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
252 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
256 public void testGetProjectMetadataProxiedNotLocalNotRemote()
259 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
260 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
261 setupTestableManagedRepository( requestedResource );
263 // Configure Connector (usually done within archiva.xml configuration)
264 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
265 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
266 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
267 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
269 assertResourceNotFound( requestedResource );
270 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
271 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
273 // Two proxies setup, nothing fetched from remotes, local does not exist.
274 assertFetchProjectOrGroupFailed( requestedResource );
276 // Nothing fetched. Nothing should exist.
277 assertResourceNotFound( requestedResource );
278 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
279 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
283 public void testGetProjectMetadataProxiedNotLocalOnRemote()
286 // New project metadata that does not exist locally but exists on remote.
287 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
288 setupTestableManagedRepository( requestedResource );
290 // Configure Connector (usually done within archiva.xml configuration)
291 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
292 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
294 assertResourceNotFound( requestedResource );
295 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
297 // One proxy setup, metadata fetched from remote, local does not exist.
298 assertFetchProjectOrGroup( requestedResource );
300 // Remote fetched. Local created/updated.
301 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
302 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
306 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
309 // Project metadata that exist locally, and has multiple versions in remote repos
310 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
311 setupTestableManagedRepository( requestedResource );
313 // Configure Connector (usually done within archiva.xml configuration)
314 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
315 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
316 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
317 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
319 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
320 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
321 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
323 // Two proxies setup, metadata fetched from both remotes.
324 assertFetchProjectOrGroup( requestedResource );
326 // metadata fetched from both repos, and merged with local version.
327 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
328 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
329 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
333 public void testGetProjectMetadataProxiedOnLocalNotRemote()
337 // Project metadata that exist locally, and does not exist in remote repos.
338 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
339 setupTestableManagedRepository( requestedResource );
342 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
343 // Configure Connector (usually done within archiva.xml configuration)
344 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
345 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
346 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
347 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
349 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
350 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
351 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
353 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
354 assertFetchProjectOrGroup( requestedResource );
356 // metadata not fetched from both repos, and local version exists.
357 // Since there was no updated metadata content from a remote/proxy, a metadata update on
358 // the local file never ran. Local only updates are performed via the metadata updater consumer.
359 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
360 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
361 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
365 public void testGetProjectMetadataProxiedOnLocalOnRemote()
368 // Project metadata that exist locally and exists on remote.
369 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
370 setupTestableManagedRepository( requestedResource );
372 // Configure Connector (usually done within archiva.xml configuration)
373 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
374 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
376 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
377 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
379 // One proxy setup, metadata fetched from remote, local exists.
380 assertFetchProjectOrGroup( requestedResource );
382 // Remote fetched. Local updated.
383 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
384 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
388 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
389 * repository has no proxied repositories set up.
391 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
392 * to the requesting client.
395 public void testGetReleaseMetadataNotProxiedNotLocal()
398 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
399 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
400 setupTestableManagedRepository( requestedResource );
402 assertNoMetadata( requestedResource );
404 // No proxy setup, nothing fetched, failure expected.
405 assertFetchVersionedFailed( requestedResource );
407 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
408 assertNoMetadata( requestedResource );
412 * A request for a maven-metadata.xml file that does exist locally, and the managed
413 * repository has no proxied repositories set up.
415 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
416 * information, and then returned to the client.
419 public void testGetReleaseMetadataNotProxiedOnLocal()
422 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
423 setupTestableManagedRepository( requestedResource );
425 assertResourceExists( requestedResource );
427 assertFetchVersioned( requestedResource );
429 assertReleaseMetadataContents( requestedResource );
433 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
434 * exists on multiple remote repositories.
436 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
437 * file location on the managed repository, a merge of the contents to the requested
438 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
439 * returned to the client.
442 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
445 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
446 setupTestableManagedRepository( requestedResource );
448 // Configure Connector (usually done within archiva.xml configuration)
449 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
450 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
451 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
452 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
454 assertResourceNotFound( requestedResource );
455 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
456 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
458 assertFetchVersioned( requestedResource );
460 assertReleaseMetadataContents( requestedResource );
461 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
462 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
466 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
467 * proxied repository.
469 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
470 * information, and then return to the client.
473 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
476 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
477 setupTestableManagedRepository( requestedResource );
479 // Configure Connector (usually done within archiva.xml configuration)
480 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
481 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
483 assertResourceNotFound( requestedResource );
485 assertFetchProjectOrGroupFailed( requestedResource );
487 assertResourceNotFound( requestedResource );
488 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
492 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
493 * exists on 1 remote repository.
495 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
496 * file location on the managed repository, a merge of the contents to the requested
497 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
498 * returned to the client.
501 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
504 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
505 setupTestableManagedRepository( requestedResource );
507 // Configure Connector (usually done within archiva.xml configuration)
508 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
509 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
511 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
513 assertFetchVersioned( requestedResource );
515 assertReleaseMetadataContents( requestedResource );
516 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
520 * A request for a maven-metadata.xml file that exists in the managed repository, but
521 * not on any remote repository.
523 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
524 * is not downloaded. There is no repository specific metadata file on the managed
525 * repository. The managed repository maven-metadata.xml is returned to the
529 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
532 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
533 setupTestableManagedRepository( requestedResource );
535 // Configure Connector (usually done within archiva.xml configuration)
536 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
537 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
539 assertReleaseMetadataContents( requestedResource );
541 assertFetchVersioned( requestedResource );
543 assertReleaseMetadataContents( requestedResource );
544 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
548 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
549 * remote repositories.
551 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
552 * and merged into the contents of the existing managed repository copy of
553 * the maven-metadata.xml file.
556 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
559 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
560 setupTestableManagedRepository( requestedResource );
562 // Configure Connector (usually done within archiva.xml configuration)
563 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
564 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
565 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
566 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
568 assertReleaseMetadataContents( requestedResource );
569 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
570 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
572 assertFetchVersioned( requestedResource );
574 assertReleaseMetadataContents( requestedResource );
575 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
576 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
580 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
583 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
584 * and merged into the contents of the existing managed repository copy of
585 * the maven-metadata.xml file.
588 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
591 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
592 setupTestableManagedRepository( requestedResource );
594 // Configure Connector (usually done within archiva.xml configuration)
595 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
596 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
598 assertReleaseMetadataContents( requestedResource );
599 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
601 assertFetchVersioned( requestedResource );
603 assertReleaseMetadataContents( requestedResource );
604 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
608 public void testGetSnapshotMetadataNotProxiedNotLocal()
611 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
612 String requestedResource =
613 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
614 setupTestableManagedRepository( requestedResource );
616 assertNoMetadata( requestedResource );
618 // No proxy setup, nothing fetched, no local file, failure expected.
619 assertFetchVersionedFailed( requestedResource );
621 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
622 assertNoMetadata( requestedResource );
626 public void testGetSnapshotMetadataNotProxiedOnLocal()
629 // The artifactId exists locally (but not on a remote repo)
630 String requestedResource =
631 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
632 setupTestableManagedRepository( requestedResource );
634 assertResourceExists( requestedResource );
636 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
637 assertFetchVersioned( requestedResource );
639 // Local metadata exists, should be updated to reflect the latest release.
640 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
644 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
647 String requestedResource =
648 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
649 setupTestableManagedRepository( requestedResource );
651 // Configure Connector (usually done within archiva.xml configuration)
652 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
653 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
654 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
655 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
657 assertResourceNotFound( requestedResource );
658 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
659 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
661 // Proxying 2 repos, both have content, local file updated.
662 assertFetchVersioned( requestedResource );
664 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
665 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
666 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
670 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
673 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
674 String requestedResource =
675 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
676 setupTestableManagedRepository( requestedResource );
678 // Configure Connector (usually done within archiva.xml configuration)
679 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
680 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
682 assertNoMetadata( requestedResource );
684 // One proxy setup, nothing fetched, no local file, failure expected.
685 assertFetchVersionedFailed( requestedResource );
687 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
688 assertNoMetadata( requestedResource );
689 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
693 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
696 // Artifact exists only in the proxied1 location.
697 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
698 setupTestableManagedRepository( requestedResource );
700 // Configure Connector (usually done within archiva.xml configuration)
701 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
702 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
704 assertResourceNotFound( requestedResource );
706 // One proxy setup, one metadata fetched, local file created/updated.
707 assertFetchVersioned( requestedResource );
709 // Local artifact Id should contain latest (which in this case is from proxied download)
710 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
711 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
715 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
718 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
719 setupTestableManagedRepository( requestedResource );
721 // Configure Connector (usually done within archiva.xml configuration)
722 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
723 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
724 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
725 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
727 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
728 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
729 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
731 // Proxying 2 repos, both have content, local file updated.
732 assertFetchVersioned( requestedResource );
734 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
735 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
736 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
740 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
743 // The artifactId exists locally (but not on a remote repo)
744 String requestedResource =
745 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
746 setupTestableManagedRepository( requestedResource );
748 // Configure Connector (usually done within archiva.xml configuration)
749 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
750 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
751 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
752 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
754 assertResourceExists( requestedResource );
755 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
756 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
758 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
759 assertFetchVersioned( requestedResource );
761 // Local metadata exists, repo metadatas should not exist, local file updated.
762 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
763 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
764 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
768 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
771 // The artifactId exists locally (but not on a remote repo)
772 String requestedResource =
773 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
774 setupTestableManagedRepository( requestedResource );
776 // Configure Connector (usually done within archiva.xml configuration)
777 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
778 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
780 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
781 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
783 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
784 assertFetchVersioned( requestedResource );
786 // Local metadata exists, repo metadata exists, local file updated.
787 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
788 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
792 public void testGetGroupMetadataNotProxiedNotLocal()
795 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
796 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
797 setupTestableManagedRepository( requestedResource );
799 assertResourceNotFound( requestedResource );
801 // No proxy setup, nothing fetched, failure expected.
802 assertFetchProjectOrGroupFailed( requestedResource );
804 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
805 assertResourceNotFound( requestedResource );
809 public void testGetGroupMetadataNotProxiedOnLocal()
812 // Project metadata that exists and has multiple versions
813 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
814 setupTestableManagedRepository( requestedResource );
816 assertResourceExists( requestedResource );
818 // No proxy setup, nothing fetched from remote, but local exists.
819 assertFetchProjectOrGroup( requestedResource );
821 // Nothing fetched. Should only contain contents of what is in the repository.
822 // A metadata update is not performed in this use case. Local metadata content is only
823 // updated via the metadata updater consumer.
824 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
828 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
831 // Project metadata that does not exist locally, but has multiple versions in remote repos
832 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
833 setupTestableManagedRepository( requestedResource );
835 // Configure Connector (usually done within archiva.xml configuration)
836 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
837 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
838 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
839 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
841 assertResourceNotFound( requestedResource );
842 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
843 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
845 // Two proxies setup, metadata fetched from both remotes.
846 assertFetchProjectOrGroup( requestedResource );
848 // Nothing fetched. Should only contain contents of what is in the repository.
849 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
850 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
851 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
855 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
858 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
859 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
860 setupTestableManagedRepository( requestedResource );
862 // Configure Connector (usually done within archiva.xml configuration)
863 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
864 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
865 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
866 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
868 assertResourceNotFound( requestedResource );
869 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
870 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
872 // Two proxies setup, nothing fetched from remotes, local does not exist.
873 assertFetchProjectOrGroupFailed( requestedResource );
875 // Nothing fetched. Nothing should exist.
876 assertResourceNotFound( requestedResource );
877 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
878 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
882 public void testGetGroupMetadataProxiedNotLocalOnRemote()
885 // New project metadata that does not exist locally but exists on remote.
886 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
887 setupTestableManagedRepository( requestedResource );
889 // Configure Connector (usually done within archiva.xml configuration)
890 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
891 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
893 assertResourceNotFound( requestedResource );
894 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
896 // One proxy setup, metadata fetched from remote, local does not exist.
897 assertFetchProjectOrGroup( requestedResource );
899 // Remote fetched. Local created/updated.
900 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
901 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
905 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
908 // Project metadata that exist locally, and has multiple versions in remote repos
909 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
910 setupTestableManagedRepository( requestedResource );
912 // Configure Connector (usually done within archiva.xml configuration)
913 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
914 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
915 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
916 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
918 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
919 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
920 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
922 // Two proxies setup, metadata fetched from both remotes.
923 assertFetchProjectOrGroup( requestedResource );
925 // metadata fetched from both repos, and merged with local version.
926 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
927 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
928 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
932 public void testGetGroupMetadataProxiedOnLocalNotRemote()
935 // Project metadata that exist locally, and does not exist in remote repos.
936 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
937 setupTestableManagedRepository( requestedResource );
939 // Configure Connector (usually done within archiva.xml configuration)
940 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
941 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
942 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
943 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
945 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
946 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
947 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
949 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
950 assertFetchProjectOrGroup( requestedResource );
952 // metadata not fetched from both repos, and local version exists.
953 // Since there was no updated metadata content from a remote/proxy, a metadata update on
954 // the local file never ran. Local only updates are performed via the metadata updater consumer.
955 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
956 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
957 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
961 public void testGetGroupMetadataProxiedOnLocalOnRemote()
964 // Project metadata that exist locally and exists on remote.
965 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
966 setupTestableManagedRepository( requestedResource );
968 // Configure Connector (usually done within archiva.xml configuration)
969 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
970 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
972 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
973 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
975 // One proxy setup, metadata fetched from remote, local exists.
976 assertFetchProjectOrGroup( requestedResource );
978 // Remote fetched. Local updated.
979 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
980 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
984 * Transfer the metadata file.
986 * @param requestedResource the requested resource
989 private void assertFetchProjectOrGroup( String requestedResource )
992 Path expectedFile = managedDefaultDir.resolve(requestedResource);
994 ProjectReference metadata = createProjectReference( requestedResource );
996 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
998 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
999 layout.toMetadataPath(
1000 metadata ) ).getFile();
1002 assertNotNull( "Should have downloaded a file.", downloadedFile );
1003 assertNoTempFiles( expectedFile );
1006 private ProjectReference createProjectReference( String path )
1007 throws RepositoryMetadataException
1009 return metadataTools.toProjectReference( path );
1013 * Transfer the metadata file, not expected to succeed.
1015 * @param requestedResource the requested resource
1018 private void assertFetchProjectOrGroupFailed( String requestedResource )
1021 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1022 ProjectReference metadata = createProjectReference( requestedResource );
1024 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1025 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1026 layout.toMetadataPath(
1027 metadata ) ).getFile();
1029 assertNull( downloadedFile );
1030 assertNoTempFiles( expectedFile );
1034 * Transfer the metadata file.
1036 * @param requestedResource the requested resource
1039 private void assertFetchVersioned( String requestedResource )
1042 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1044 VersionedReference metadata = createVersionedReference( requestedResource );
1046 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1047 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1048 layout.toMetadataPath(
1049 metadata ) ).getFile();
1051 assertNotNull( "Should have downloaded a file.", downloadedFile );
1052 assertNoTempFiles( expectedFile );
1055 private VersionedReference createVersionedReference( String path )
1056 throws RepositoryMetadataException
1058 return metadataTools.toVersionedReference( path );
1062 * Transfer the metadata file, not expected to succeed.
1064 * @param requestedResource the requested resource
1067 private void assertFetchVersionedFailed( String requestedResource )
1070 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1071 VersionedReference metadata = createVersionedReference( requestedResource );
1073 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1074 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1075 layout.toMetadataPath(
1076 metadata ) ).getFile();
1078 assertNull( downloadedFile );
1079 assertNoTempFiles( expectedFile );
1083 * Test for the existance of the requestedResource in the default managed repository.
1085 * @param requestedResource the requested resource
1088 private void assertResourceExists( String requestedResource )
1091 Path actualFile = managedDefaultDir.resolve(requestedResource);
1092 assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
1095 private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
1098 assertNotNull( "Actual File should not be null.", actualFile );
1100 assertTrue( "Actual file exists.", Files.exists(actualFile) );
1102 StringWriter actualContents = new StringWriter();
1103 FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
1104 StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
1105 ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader( null ).read( actualFileAsset );
1106 RepositoryMetadataWriter.write( metadata, actualContents );
1108 Diff detailedDiff = DiffBuilder.compare( expectedMetadataXml).withTest( actualContents.toString() ).checkForSimilar().build();
1109 if ( detailedDiff.hasDifferences() )
1111 for ( Difference diff : detailedDiff.getDifferences() )
1113 System.out.println( diff );
1115 assertEquals( expectedMetadataXml, actualContents );
1118 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1122 * Ensures that the requested resource is not present in the managed repository.
1124 * @param requestedResource the requested resource
1127 private void assertNoMetadata( String requestedResource )
1130 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1131 assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
1135 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1136 * managed repository.
1138 * @param proxiedRepoId the proxied repository id to validate with.
1139 * @param requestedResource the resource requested.
1141 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1143 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1145 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1146 assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
1149 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1152 Path actualFile = managedDefaultDir.resolve(requestedResource);
1153 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1155 ProjectReference actualMetadata = createGroupReference( requestedResource );
1157 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1160 private ProjectReference createGroupReference( String requestedResource )
1161 throws RepositoryMetadataException
1163 ProjectReference projectReference = createProjectReference( requestedResource );
1164 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1165 projectReference.setArtifactId( null );
1166 return projectReference;
1169 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1170 String expectedPlugins[] )
1173 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1175 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1176 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1178 ProjectReference actualMetadata = createGroupReference( requestedResource );
1180 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1183 private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1186 // Build expected metadata XML
1187 StringWriter expectedMetadataXml = new StringWriter();
1188 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1189 m.setGroupId( actualMetadata.getGroupId() );
1191 for ( String pluginId : expectedPlugins )
1193 Plugin p = new Plugin();
1194 p.setPrefix( pluginId );
1195 p.setArtifactId( pluginId + "-maven-plugin" );
1196 p.setName( "The " + pluginId + " Plugin" );
1197 m.getPlugins().add( p );
1200 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1202 // Compare the file to the actual contents.
1203 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1207 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1208 * does it contain the specified list of expected versions?
1210 * @param requestedResource the requested resource
1213 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1214 String latestVersion, String releaseVersion )
1217 Path actualFile = managedDefaultDir.resolve(requestedResource);
1218 assertTrue( Files.exists(actualFile) );
1220 ProjectReference metadata = createProjectReference( requestedResource );
1222 // Build expected metadata XML
1223 StringWriter expectedMetadataXml = new StringWriter();
1224 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1225 m.setGroupId( metadata.getGroupId() );
1226 m.setArtifactId( metadata.getArtifactId() );
1227 m.setLatestVersion( latestVersion );
1228 m.setReleasedVersion( releaseVersion );
1230 if ( expectedVersions != null )
1232 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1235 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1237 // Compare the file to the actual contents.
1238 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1242 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1243 * does it contain the expected release maven-metadata.xml contents?
1245 * @param requestedResource the requested resource
1248 private void assertReleaseMetadataContents( String requestedResource )
1251 Path actualFile = managedDefaultDir.resolve(requestedResource);
1252 assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1254 VersionedReference metadata = createVersionedReference( requestedResource );
1256 // Build expected metadata XML
1257 StringWriter expectedMetadataXml = new StringWriter();
1258 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1259 m.setGroupId( metadata.getGroupId() );
1260 m.setArtifactId( metadata.getArtifactId() );
1261 m.setVersion( metadata.getVersion() );
1262 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1264 // Compare the file to the actual contents.
1265 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1269 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1270 * does it contain the expected release maven-metadata.xml contents?
1272 * @param requestedResource the requested resource
1273 * @param expectedDate the date in "yyyyMMdd" format
1274 * @param expectedTime the time in "hhmmss" format
1275 * @param expectedBuildnumber the build number
1278 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1279 int expectedBuildnumber )
1282 Path actualFile = managedDefaultDir.resolve(requestedResource);
1283 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1285 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1287 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1291 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1292 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1294 * @param proxiedRepoId the repository id of the proxied repository.
1295 * @param requestedResource the requested resource
1296 * @param expectedDate the date in "yyyyMMdd" format
1297 * @param expectedTime the time in "hhmmss" format
1298 * @param expectedBuildnumber the build number
1301 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1302 String expectedDate, String expectedTime, int expectedBuildnumber )
1305 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1307 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1308 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1310 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1312 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1315 private void assertSnapshotMetadata( Path actualFile, VersionedReference actualMetadata, String expectedDate,
1316 String expectedTime, int expectedBuildnumber )
1317 throws RepositoryMetadataException, Exception
1319 // Build expected metadata XML
1320 StringWriter expectedMetadataXml = new StringWriter();
1321 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1322 m.setGroupId( actualMetadata.getGroupId() );
1323 m.setArtifactId( actualMetadata.getArtifactId() );
1324 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1326 m.setSnapshotVersion( new SnapshotVersion() );
1328 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1330 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1333 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1335 m.setLastUpdated( expectedDate + expectedTime );
1337 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1339 // Compare the file to the actual contents.
1340 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1344 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1345 * list of expected versions within.
1347 * @param proxiedRepoId
1348 * @param requestedResource
1349 * @param expectedProxyVersions
1351 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1352 String[] expectedProxyVersions )
1355 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1357 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1358 assertTrue( Files.exists(actualFile) );
1360 ProjectReference metadata = createProjectReference( requestedResource );
1362 // Build expected metadata XML
1363 StringWriter expectedMetadataXml = new StringWriter();
1364 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1365 m.setGroupId( metadata.getGroupId() );
1366 m.setArtifactId( metadata.getArtifactId() );
1368 if ( expectedProxyVersions != null )
1370 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1373 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1375 // Compare the file to the actual contents.
1376 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1380 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1381 * list of expected versions within.
1383 * @param proxiedRepoId
1384 * @param requestedResource
1386 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1389 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1391 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1392 assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
1394 VersionedReference metadata = createVersionedReference( requestedResource );
1396 // Build expected metadata XML
1397 StringWriter expectedMetadataXml = new StringWriter();
1398 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1399 m.setGroupId( metadata.getGroupId() );
1400 m.setArtifactId( metadata.getArtifactId() );
1401 m.setVersion( metadata.getVersion() );
1402 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1404 // Compare the file to the actual contents.
1405 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1409 * Test for the non-existance of the requestedResource in the default managed repository.
1411 * @param requestedResource the requested resource
1414 private void assertResourceNotFound( String requestedResource )
1417 Path actualFile = managedDefaultDir.resolve(requestedResource);
1418 assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );