1 package org.apache.archiva.maven.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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.DefaultFileLockManager;
22 import org.apache.archiva.common.utils.VersionUtil;
23 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
24 import org.apache.archiva.model.ArchivaRepositoryMetadata;
25 import org.apache.archiva.model.Plugin;
26 import org.apache.archiva.model.SnapshotVersion;
27 import org.apache.archiva.policies.CachedFailuresPolicy;
28 import org.apache.archiva.policies.ChecksumPolicy;
29 import org.apache.archiva.policies.ReleasesPolicy;
30 import org.apache.archiva.policies.SnapshotsPolicy;
31 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
32 import org.apache.archiva.repository.content.ContentItem;
33 import org.apache.archiva.repository.content.DataItem;
34 import org.apache.archiva.repository.content.ItemSelector;
35 import org.apache.archiva.repository.content.Project;
36 import org.apache.archiva.repository.content.Version;
37 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
38 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
39 import org.apache.archiva.repository.metadata.base.MetadataTools;
40 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
41 import org.apache.archiva.repository.storage.StorageAsset;
42 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
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);
132 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
133 ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
134 Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
135 assertNotNull( project );
136 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
137 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
138 metaPath ).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 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
998 ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
999 Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
1000 assertNotNull( project );
1001 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
1003 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1004 metaPath ).getFile();
1006 assertNotNull( "Should have downloaded a file.", downloadedFile );
1007 assertNoTempFiles( expectedFile );
1012 * Transfer the metadata file, not expected to succeed.
1014 * @param requestedResource the requested resource
1017 private void assertFetchProjectOrGroupFailed( String requestedResource )
1020 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1022 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1023 ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
1024 Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
1025 assertNotNull( project );
1026 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
1027 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1028 metaPath ).getFile();
1030 assertNull( downloadedFile );
1031 assertNoTempFiles( expectedFile );
1035 * Transfer the metadata file.
1037 * @param requestedResource the requested resource
1040 private void assertFetchVersioned( String requestedResource )
1043 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1045 ContentItem item = managedDefaultRepository.toItem( requestedResource );
1046 if (item instanceof DataItem) {
1047 item = managedDefaultRepository.getParent( item );
1049 assertNotNull( item );
1050 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1051 Version version = layout.adaptItem( Version.class, item );
1052 assertNotNull( version );
1053 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem(
1056 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1057 metaPath).getFile();
1059 assertNotNull( "Should have downloaded a file.", downloadedFile );
1060 assertNoTempFiles( expectedFile );
1065 * Transfer the metadata file, not expected to succeed.
1067 * @param requestedResource the requested resource
1070 private void assertFetchVersionedFailed( String requestedResource )
1073 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1074 ContentItem item = managedDefaultRepository.toItem( requestedResource );
1075 assertNotNull( item );
1076 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1077 Version version = layout.adaptItem( Version.class, item );
1078 assertNotNull( version );
1079 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem(
1081 assertNotNull( metaPath );
1082 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1083 metaPath ).getFile();
1085 assertNull( downloadedFile );
1086 assertNoTempFiles( expectedFile );
1090 * Test for the existance of the requestedResource in the default managed repository.
1092 * @param requestedResource the requested resource
1095 private void assertResourceExists( String requestedResource )
1098 Path actualFile = managedDefaultDir.resolve(requestedResource);
1099 assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
1102 private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
1105 assertNotNull( "Actual File should not be null.", actualFile );
1107 assertTrue( "Actual file exists.", Files.exists(actualFile) );
1109 StringWriter actualContents = new StringWriter();
1110 FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
1111 StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
1112 ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader( null ).read( actualFileAsset );
1113 RepositoryMetadataWriter.write( metadata, actualContents );
1115 Diff detailedDiff = DiffBuilder.compare( expectedMetadataXml).withTest( actualContents.toString() ).checkForSimilar().build();
1116 if ( detailedDiff.hasDifferences() )
1118 for ( Difference diff : detailedDiff.getDifferences() )
1120 System.out.println( diff );
1122 assertEquals( expectedMetadataXml, actualContents );
1125 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1129 * Ensures that the requested resource is not present in the managed repository.
1131 * @param requestedResource the requested resource
1134 private void assertNoMetadata( String requestedResource )
1137 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1138 assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
1142 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1143 * managed repository.
1145 * @param proxiedRepoId the proxied repository id to validate with.
1146 * @param requestedResource the resource requested.
1148 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1150 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1152 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1153 assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
1156 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1159 Path actualFile = managedDefaultDir.resolve(requestedResource);
1160 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1162 ItemSelector actualMetadata = createGroupSelector( requestedResource );
1164 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1167 private ItemSelector createProjectSelector(String path) throws RepositoryMetadataException
1169 return metadataTools.toProjectSelector( path );
1172 private ItemSelector createVersionedSelector(String path) throws RepositoryMetadataException
1174 return metadataTools.toVersionedSelector( path );
1177 private ItemSelector createGroupSelector( String requestedResource )
1178 throws RepositoryMetadataException
1180 ItemSelector projectSelector = createProjectSelector( requestedResource );
1181 ArchivaItemSelector.Builder projectReference = ArchivaItemSelector.builder( ).withSelector( projectSelector );
1182 projectReference.withNamespace( projectSelector.getNamespace() + "." + projectSelector.getProjectId() );
1183 projectReference.withArtifactId( null );
1184 projectReference.withProjectId( null );
1185 return projectReference.build();
1188 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1189 String expectedPlugins[] )
1192 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1194 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1195 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1197 ItemSelector actualMetadata = createGroupSelector( requestedResource );
1199 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1202 private void assertGroupMetadata( Path actualFile, ItemSelector actualMetadata, String expectedPlugins[] )
1205 // Build expected metadata XML
1206 StringWriter expectedMetadataXml = new StringWriter();
1207 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1208 m.setGroupId( actualMetadata.getNamespace() );
1210 for ( String pluginId : expectedPlugins )
1212 Plugin p = new Plugin();
1213 p.setPrefix( pluginId );
1214 p.setArtifactId( pluginId + "-maven-plugin" );
1215 p.setName( "The " + pluginId + " Plugin" );
1216 m.getPlugins().add( p );
1219 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1221 // Compare the file to the actual contents.
1222 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1226 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1227 * does it contain the specified list of expected versions?
1229 * @param requestedResource the requested resource
1232 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1233 String latestVersion, String releaseVersion )
1236 Path actualFile = managedDefaultDir.resolve(requestedResource);
1237 assertTrue( Files.exists(actualFile) );
1239 ItemSelector metadata = createProjectSelector( requestedResource );
1241 // Build expected metadata XML
1242 StringWriter expectedMetadataXml = new StringWriter();
1243 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1244 m.setGroupId( metadata.getNamespace() );
1245 m.setArtifactId( metadata.getArtifactId() );
1246 m.setLatestVersion( latestVersion );
1247 m.setReleasedVersion( releaseVersion );
1249 if ( expectedVersions != null )
1251 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1254 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1256 // Compare the file to the actual contents.
1257 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1261 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1262 * does it contain the expected release maven-metadata.xml contents?
1264 * @param requestedResource the requested resource
1267 private void assertReleaseMetadataContents( String requestedResource )
1270 Path actualFile = managedDefaultDir.resolve(requestedResource);
1271 assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1273 ItemSelector metadata = createVersionedSelector( requestedResource );
1275 // Build expected metadata XML
1276 StringWriter expectedMetadataXml = new StringWriter();
1277 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1278 m.setGroupId( metadata.getNamespace() );
1279 m.setArtifactId( metadata.getArtifactId() );
1280 m.setVersion( metadata.getVersion() );
1281 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1283 // Compare the file to the actual contents.
1284 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1288 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1289 * does it contain the expected release maven-metadata.xml contents?
1291 * @param requestedResource the requested resource
1292 * @param expectedDate the date in "yyyyMMdd" format
1293 * @param expectedTime the time in "hhmmss" format
1294 * @param expectedBuildnumber the build number
1297 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1298 int expectedBuildnumber )
1301 Path actualFile = managedDefaultDir.resolve(requestedResource);
1302 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1304 ItemSelector actualMetadata = createVersionedSelector( requestedResource );
1306 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1310 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1311 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1313 * @param proxiedRepoId the repository id of the proxied repository.
1314 * @param requestedResource the requested resource
1315 * @param expectedDate the date in "yyyyMMdd" format
1316 * @param expectedTime the time in "hhmmss" format
1317 * @param expectedBuildnumber the build number
1320 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1321 String expectedDate, String expectedTime, int expectedBuildnumber )
1324 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1326 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1327 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1329 ItemSelector actualMetadata = createVersionedSelector( requestedResource );
1331 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1334 private void assertSnapshotMetadata( Path actualFile, ItemSelector actualMetadata, String expectedDate,
1335 String expectedTime, int expectedBuildnumber )
1336 throws RepositoryMetadataException, Exception
1338 // Build expected metadata XML
1339 StringWriter expectedMetadataXml = new StringWriter();
1340 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1341 m.setGroupId( actualMetadata.getNamespace() );
1342 m.setArtifactId( actualMetadata.getArtifactId() );
1343 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1345 m.setSnapshotVersion( new SnapshotVersion() );
1347 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1349 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1352 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1354 m.setLastUpdated( expectedDate + expectedTime );
1356 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1358 // Compare the file to the actual contents.
1359 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1363 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1364 * list of expected versions within.
1366 * @param proxiedRepoId
1367 * @param requestedResource
1368 * @param expectedProxyVersions
1370 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1371 String[] expectedProxyVersions )
1374 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1376 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1377 assertTrue( Files.exists(actualFile) );
1379 ItemSelector metadata = createProjectSelector( requestedResource );
1381 // Build expected metadata XML
1382 StringWriter expectedMetadataXml = new StringWriter();
1383 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1384 m.setGroupId( metadata.getNamespace() );
1385 m.setArtifactId( metadata.getArtifactId() );
1387 if ( expectedProxyVersions != null )
1389 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1392 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1394 // Compare the file to the actual contents.
1395 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1399 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1400 * list of expected versions within.
1402 * @param proxiedRepoId
1403 * @param requestedResource
1405 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1408 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1410 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1411 assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
1413 ItemSelector metadata = createVersionedSelector( requestedResource );
1415 // Build expected metadata XML
1416 StringWriter expectedMetadataXml = new StringWriter();
1417 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1418 m.setGroupId( metadata.getNamespace() );
1419 m.setArtifactId( metadata.getArtifactId() );
1420 m.setVersion( metadata.getVersion() );
1421 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1423 // Compare the file to the actual contents.
1424 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1428 * Test for the non-existance of the requestedResource in the default managed repository.
1430 * @param requestedResource the requested resource
1433 private void assertResourceNotFound( String requestedResource )
1436 Path actualFile = managedDefaultDir.resolve(requestedResource);
1437 assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );