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.SnapshotVersion;
28 import org.apache.archiva.policies.CachedFailuresPolicy;
29 import org.apache.archiva.policies.ChecksumPolicy;
30 import org.apache.archiva.policies.ReleasesPolicy;
31 import org.apache.archiva.policies.SnapshotsPolicy;
32 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
33 import org.apache.archiva.repository.content.ContentItem;
34 import org.apache.archiva.repository.content.DataItem;
35 import org.apache.archiva.repository.content.ItemSelector;
36 import org.apache.archiva.repository.content.Project;
37 import org.apache.archiva.repository.content.Version;
38 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
39 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
40 import org.apache.archiva.repository.metadata.base.MetadataTools;
41 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
42 import org.apache.archiva.repository.storage.StorageAsset;
43 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
44 import org.apache.commons.lang3.StringUtils;
45 import org.apache.maven.wagon.TransferFailedException;
46 import org.easymock.EasyMock;
47 import org.junit.Test;
48 import org.xmlunit.builder.DiffBuilder;
49 import org.xmlunit.diff.Diff;
50 import org.xmlunit.diff.Difference;
52 import javax.inject.Inject;
53 import javax.inject.Named;
55 import java.io.StringWriter;
56 import java.nio.file.Files;
57 import java.nio.file.Path;
58 import java.util.ArrayList;
59 import java.util.Arrays;
61 import static org.junit.Assert.*;
64 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
65 * present in the repository.
67 * Test Case Naming is as follows.
70 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
74 * Which should leave the following matrix of test cases.
76 * Metadata | Proxied | Local | Remote
77 * ----------+----------+-------+---------
78 * Release | Not | Not | n/a (1)
79 * Release | Not | On | n/a (1)
80 * Release | | Not | Not
81 * Release | | Not | On
82 * Release | | Not | Multiple
83 * Release | | On | Not
85 * Release | | On | Multiple
86 * Snapshot | Not | Not | n/a (1)
87 * Snapshot | Not | On | n/a (1)
88 * Snapshot | | Not | Not
89 * Snapshot | | Not | On
90 * Snapshot | | Not | Multiple
91 * Snapshot | | On | Not
92 * Snapshot | | On | On
93 * Snapshot | | On | Multiple
94 * Project | Not | Not | n/a (1)
95 * Project | Not | On | n/a (1)
96 * Project | | Not | Not
97 * Project | | Not | On
98 * Project | | Not | Multiple
99 * Project | | On | Not
100 * Project | | On | On
101 * Project | | On | Multiple
103 * (1) If it isn't proxied, no point in having a remote.
108 public class MetadataTransferTest
109 extends AbstractProxyTestCase
113 @Named(value = "metadataTools#mocked")
114 private MetadataTools metadataTools;
118 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
121 // New project metadata that does not exist locally but exists on remote.
122 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
123 setupTestableManagedRepository( requestedResource );
125 // Configure Connector (usually done within archiva.xml configuration)
126 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
127 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
129 assertResourceNotFound( requestedResource );
130 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
132 Path expectedFile = managedDefaultDir.resolve(requestedResource);
133 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
134 ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
135 Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
136 assertNotNull( project );
137 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
138 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
139 metaPath ).getFile();
141 assertNull( "Should not have downloaded a file.", downloadedFile );
142 assertNoTempFiles( expectedFile );
145 // TODO: same test for other fetch* methods
147 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
150 // Project metadata that does not exist locally, but has multiple versions in remote repos
151 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
152 setupTestableManagedRepository( requestedResource );
154 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
156 // Configure Connector (usually done within archiva.xml configuration)
157 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
158 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
159 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
160 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
162 assertResourceNotFound( requestedResource );
163 assertNoRepoMetadata( "badproxied1", requestedResource );
164 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
166 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
167 Path expectedFile = managedDefaultDir.resolve(
168 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
170 wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
171 EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
174 wagonMockControl.replay();
176 assertFetchProjectOrGroup( requestedResource );
178 wagonMockControl.verify();
180 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
181 assertNoRepoMetadata( "badproxied1", requestedResource );
182 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
186 * Attempt to get the project metadata for non-existant artifact.
188 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
189 * to the requesting client.
192 public void testGetProjectMetadataNotProxiedNotLocal()
195 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
196 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
197 setupTestableManagedRepository( requestedResource );
199 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
201 assertResourceNotFound( requestedResource );
203 // No proxy setup, nothing fetched, failure expected.
204 assertFetchProjectOrGroupFailed( requestedResource );
206 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
207 assertResourceNotFound( requestedResource );
211 public void testGetProjectMetadataNotProxiedOnLocal()
215 // Project metadata that exists and has multiple versions
216 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
217 setupTestableManagedRepository( requestedResource );
219 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
221 assertResourceExists( requestedResource );
223 // No proxy setup, nothing fetched from remote, but local exists.
224 assertFetchProjectOrGroup( requestedResource );
226 // Nothing fetched. Should only contain contents of what is in the repository.
227 // A metadata update is not performed in this use case. Local metadata content is only
228 // updated via the metadata updater consumer.
229 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
233 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
236 // Project metadata that does not exist locally, but has multiple versions in remote repos
237 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
238 setupTestableManagedRepository( requestedResource );
240 // Configure Connector (usually done within archiva.xml configuration)
241 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
242 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
243 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
244 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
246 assertResourceNotFound( requestedResource );
247 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
248 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
250 // Two proxies setup, metadata fetched from both remotes.
251 assertFetchProjectOrGroup( requestedResource );
253 // Nothing fetched. Should only contain contents of what is in the repository.
254 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
255 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
256 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
260 public void testGetProjectMetadataProxiedNotLocalNotRemote()
263 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
264 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
265 setupTestableManagedRepository( requestedResource );
267 // Configure Connector (usually done within archiva.xml configuration)
268 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
269 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
270 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
271 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
273 assertResourceNotFound( requestedResource );
274 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
275 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
277 // Two proxies setup, nothing fetched from remotes, local does not exist.
278 assertFetchProjectOrGroupFailed( requestedResource );
280 // Nothing fetched. Nothing should exist.
281 assertResourceNotFound( requestedResource );
282 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
283 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
287 public void testGetProjectMetadataProxiedNotLocalOnRemote()
290 // New project metadata that does not exist locally but exists on remote.
291 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
292 setupTestableManagedRepository( requestedResource );
294 // Configure Connector (usually done within archiva.xml configuration)
295 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
296 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
298 assertResourceNotFound( requestedResource );
299 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
301 // One proxy setup, metadata fetched from remote, local does not exist.
302 assertFetchProjectOrGroup( requestedResource );
304 // Remote fetched. Local created/updated.
305 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
306 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
310 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
313 // Project metadata that exist locally, and has multiple versions in remote repos
314 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
315 setupTestableManagedRepository( requestedResource );
317 // Configure Connector (usually done within archiva.xml configuration)
318 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
319 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
320 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
321 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
323 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
324 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
325 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
327 // Two proxies setup, metadata fetched from both remotes.
328 assertFetchProjectOrGroup( requestedResource );
330 // metadata fetched from both repos, and merged with local version.
331 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
332 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
333 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
337 public void testGetProjectMetadataProxiedOnLocalNotRemote()
341 // Project metadata that exist locally, and does not exist in remote repos.
342 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
343 setupTestableManagedRepository( requestedResource );
346 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
347 // Configure Connector (usually done within archiva.xml configuration)
348 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
349 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
350 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
351 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
353 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
354 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
355 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
357 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
358 assertFetchProjectOrGroup( requestedResource );
360 // metadata not fetched from both repos, and local version exists.
361 // Since there was no updated metadata content from a remote/proxy, a metadata update on
362 // the local file never ran. Local only updates are performed via the metadata updater consumer.
363 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
364 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
365 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
369 public void testGetProjectMetadataProxiedOnLocalOnRemote()
372 // Project metadata that exist locally and exists on remote.
373 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
374 setupTestableManagedRepository( requestedResource );
376 // Configure Connector (usually done within archiva.xml configuration)
377 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
378 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
380 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
381 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
383 // One proxy setup, metadata fetched from remote, local exists.
384 assertFetchProjectOrGroup( requestedResource );
386 // Remote fetched. Local updated.
387 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
388 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
392 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
393 * repository has no proxied repositories set up.
395 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
396 * to the requesting client.
399 public void testGetReleaseMetadataNotProxiedNotLocal()
402 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
403 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
404 setupTestableManagedRepository( requestedResource );
406 assertNoMetadata( requestedResource );
408 // No proxy setup, nothing fetched, failure expected.
409 assertFetchVersionedFailed( requestedResource );
411 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
412 assertNoMetadata( requestedResource );
416 * A request for a maven-metadata.xml file that does exist locally, and the managed
417 * repository has no proxied repositories set up.
419 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
420 * information, and then returned to the client.
423 public void testGetReleaseMetadataNotProxiedOnLocal()
426 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
427 setupTestableManagedRepository( requestedResource );
429 assertResourceExists( requestedResource );
431 assertFetchVersioned( requestedResource );
433 assertReleaseMetadataContents( requestedResource );
437 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
438 * exists on multiple remote repositories.
440 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
441 * file location on the managed repository, a merge of the contents to the requested
442 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
443 * returned to the client.
446 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
449 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
450 setupTestableManagedRepository( requestedResource );
452 // Configure Connector (usually done within archiva.xml configuration)
453 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
454 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
455 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
456 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
458 assertResourceNotFound( requestedResource );
459 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
460 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
462 assertFetchVersioned( requestedResource );
464 assertReleaseMetadataContents( requestedResource );
465 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
466 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
470 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
471 * proxied repository.
473 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
474 * information, and then return to the client.
477 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
480 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
481 setupTestableManagedRepository( requestedResource );
483 // Configure Connector (usually done within archiva.xml configuration)
484 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
485 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
487 assertResourceNotFound( requestedResource );
489 assertFetchProjectOrGroupFailed( requestedResource );
491 assertResourceNotFound( requestedResource );
492 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
496 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
497 * exists on 1 remote repository.
499 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
500 * file location on the managed repository, a merge of the contents to the requested
501 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
502 * returned to the client.
505 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
508 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
509 setupTestableManagedRepository( requestedResource );
511 // Configure Connector (usually done within archiva.xml configuration)
512 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
513 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
515 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
517 assertFetchVersioned( requestedResource );
519 assertReleaseMetadataContents( requestedResource );
520 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
524 * A request for a maven-metadata.xml file that exists in the managed repository, but
525 * not on any remote repository.
527 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
528 * is not downloaded. There is no repository specific metadata file on the managed
529 * repository. The managed repository maven-metadata.xml is returned to the
533 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
536 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
537 setupTestableManagedRepository( requestedResource );
539 // Configure Connector (usually done within archiva.xml configuration)
540 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
541 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
543 assertReleaseMetadataContents( requestedResource );
545 assertFetchVersioned( requestedResource );
547 assertReleaseMetadataContents( requestedResource );
548 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
552 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
553 * remote repositories.
555 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
556 * and merged into the contents of the existing managed repository copy of
557 * the maven-metadata.xml file.
560 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
563 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
564 setupTestableManagedRepository( requestedResource );
566 // Configure Connector (usually done within archiva.xml configuration)
567 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
568 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
569 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
570 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
572 assertReleaseMetadataContents( requestedResource );
573 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
574 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
576 assertFetchVersioned( requestedResource );
578 assertReleaseMetadataContents( requestedResource );
579 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
580 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
584 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
587 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
588 * and merged into the contents of the existing managed repository copy of
589 * the maven-metadata.xml file.
592 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
595 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
596 setupTestableManagedRepository( requestedResource );
598 // Configure Connector (usually done within archiva.xml configuration)
599 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
600 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
602 assertReleaseMetadataContents( requestedResource );
603 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
605 assertFetchVersioned( requestedResource );
607 assertReleaseMetadataContents( requestedResource );
608 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
612 public void testGetSnapshotMetadataNotProxiedNotLocal()
615 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
616 String requestedResource =
617 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
618 setupTestableManagedRepository( requestedResource );
620 assertNoMetadata( requestedResource );
622 // No proxy setup, nothing fetched, no local file, failure expected.
623 assertFetchVersionedFailed( requestedResource );
625 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
626 assertNoMetadata( requestedResource );
630 public void testGetSnapshotMetadataNotProxiedOnLocal()
633 // The artifactId exists locally (but not on a remote repo)
634 String requestedResource =
635 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
636 setupTestableManagedRepository( requestedResource );
638 assertResourceExists( requestedResource );
640 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
641 assertFetchVersioned( requestedResource );
643 // Local metadata exists, should be updated to reflect the latest release.
644 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
648 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
651 String requestedResource =
652 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
653 setupTestableManagedRepository( requestedResource );
655 // Configure Connector (usually done within archiva.xml configuration)
656 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
657 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
658 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
659 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
661 assertResourceNotFound( requestedResource );
662 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
663 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
665 // Proxying 2 repos, both have content, local file updated.
666 assertFetchVersioned( requestedResource );
668 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
669 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
670 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
674 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
677 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
678 String requestedResource =
679 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
680 setupTestableManagedRepository( requestedResource );
682 // Configure Connector (usually done within archiva.xml configuration)
683 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
684 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
686 assertNoMetadata( requestedResource );
688 // One proxy setup, nothing fetched, no local file, failure expected.
689 assertFetchVersionedFailed( requestedResource );
691 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
692 assertNoMetadata( requestedResource );
693 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
697 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
700 // Artifact exists only in the proxied1 location.
701 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
702 setupTestableManagedRepository( requestedResource );
704 // Configure Connector (usually done within archiva.xml configuration)
705 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
706 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
708 assertResourceNotFound( requestedResource );
710 // One proxy setup, one metadata fetched, local file created/updated.
711 assertFetchVersioned( requestedResource );
713 // Local artifact Id should contain latest (which in this case is from proxied download)
714 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
715 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
719 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
722 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
723 setupTestableManagedRepository( requestedResource );
725 // Configure Connector (usually done within archiva.xml configuration)
726 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
727 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
728 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
729 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
731 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
732 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
733 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
735 // Proxying 2 repos, both have content, local file updated.
736 assertFetchVersioned( requestedResource );
738 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
739 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
740 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
744 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
747 // The artifactId exists locally (but not on a remote repo)
748 String requestedResource =
749 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
750 setupTestableManagedRepository( requestedResource );
752 // Configure Connector (usually done within archiva.xml configuration)
753 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
754 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
755 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
756 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
758 assertResourceExists( requestedResource );
759 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
760 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
762 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
763 assertFetchVersioned( requestedResource );
765 // Local metadata exists, repo metadatas should not exist, local file updated.
766 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
767 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
768 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
772 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
775 // The artifactId exists locally (but not on a remote repo)
776 String requestedResource =
777 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
778 setupTestableManagedRepository( requestedResource );
780 // Configure Connector (usually done within archiva.xml configuration)
781 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
782 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
784 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
785 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
787 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
788 assertFetchVersioned( requestedResource );
790 // Local metadata exists, repo metadata exists, local file updated.
791 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
792 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
796 public void testGetGroupMetadataNotProxiedNotLocal()
799 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
800 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
801 setupTestableManagedRepository( requestedResource );
803 assertResourceNotFound( requestedResource );
805 // No proxy setup, nothing fetched, failure expected.
806 assertFetchProjectOrGroupFailed( requestedResource );
808 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
809 assertResourceNotFound( requestedResource );
813 public void testGetGroupMetadataNotProxiedOnLocal()
816 // Project metadata that exists and has multiple versions
817 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
818 setupTestableManagedRepository( requestedResource );
820 assertResourceExists( requestedResource );
822 // No proxy setup, nothing fetched from remote, but local exists.
823 assertFetchProjectOrGroup( requestedResource );
825 // Nothing fetched. Should only contain contents of what is in the repository.
826 // A metadata update is not performed in this use case. Local metadata content is only
827 // updated via the metadata updater consumer.
828 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
832 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
835 // Project metadata that does not exist locally, but has multiple versions in remote repos
836 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
837 setupTestableManagedRepository( requestedResource );
839 // Configure Connector (usually done within archiva.xml configuration)
840 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
841 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
842 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
843 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
845 assertResourceNotFound( requestedResource );
846 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
847 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
849 // Two proxies setup, metadata fetched from both remotes.
850 assertFetchProjectOrGroup( requestedResource );
852 // Nothing fetched. Should only contain contents of what is in the repository.
853 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
854 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
855 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
859 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
862 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
863 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
864 setupTestableManagedRepository( requestedResource );
866 // Configure Connector (usually done within archiva.xml configuration)
867 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
868 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
869 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
870 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
872 assertResourceNotFound( requestedResource );
873 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
874 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
876 // Two proxies setup, nothing fetched from remotes, local does not exist.
877 assertFetchProjectOrGroupFailed( requestedResource );
879 // Nothing fetched. Nothing should exist.
880 assertResourceNotFound( requestedResource );
881 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
882 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
886 public void testGetGroupMetadataProxiedNotLocalOnRemote()
889 // New project metadata that does not exist locally but exists on remote.
890 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
891 setupTestableManagedRepository( requestedResource );
893 // Configure Connector (usually done within archiva.xml configuration)
894 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
895 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
897 assertResourceNotFound( requestedResource );
898 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
900 // One proxy setup, metadata fetched from remote, local does not exist.
901 assertFetchProjectOrGroup( requestedResource );
903 // Remote fetched. Local created/updated.
904 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
905 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
909 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
912 // Project metadata that exist locally, and has multiple versions in remote repos
913 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
914 setupTestableManagedRepository( requestedResource );
916 // Configure Connector (usually done within archiva.xml configuration)
917 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
918 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
919 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
920 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
922 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
923 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
924 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
926 // Two proxies setup, metadata fetched from both remotes.
927 assertFetchProjectOrGroup( requestedResource );
929 // metadata fetched from both repos, and merged with local version.
930 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
931 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
932 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
936 public void testGetGroupMetadataProxiedOnLocalNotRemote()
939 // Project metadata that exist locally, and does not exist in remote repos.
940 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
941 setupTestableManagedRepository( requestedResource );
943 // Configure Connector (usually done within archiva.xml configuration)
944 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
945 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
946 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
947 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
949 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
950 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
951 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
953 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
954 assertFetchProjectOrGroup( requestedResource );
956 // metadata not fetched from both repos, and local version exists.
957 // Since there was no updated metadata content from a remote/proxy, a metadata update on
958 // the local file never ran. Local only updates are performed via the metadata updater consumer.
959 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
960 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
961 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
965 public void testGetGroupMetadataProxiedOnLocalOnRemote()
968 // Project metadata that exist locally and exists on remote.
969 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
970 setupTestableManagedRepository( requestedResource );
972 // Configure Connector (usually done within archiva.xml configuration)
973 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
974 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
976 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
977 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
979 // One proxy setup, metadata fetched from remote, local exists.
980 assertFetchProjectOrGroup( requestedResource );
982 // Remote fetched. Local updated.
983 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
984 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
988 * Transfer the metadata file.
990 * @param requestedResource the requested resource
993 private void assertFetchProjectOrGroup( String requestedResource )
996 Path expectedFile = managedDefaultDir.resolve(requestedResource);
998 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
999 ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
1000 Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
1001 assertNotNull( project );
1002 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
1004 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1005 metaPath ).getFile();
1007 assertNotNull( "Should have downloaded a file.", downloadedFile );
1008 assertNoTempFiles( expectedFile );
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);
1023 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1024 ContentItem metaItem = managedDefaultRepository.toItem( requestedResource );
1025 Project project = layout.adaptItem( Project.class, managedDefaultRepository.getParent( metaItem ) );
1026 assertNotNull( project );
1027 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem( project ) );
1028 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1029 metaPath ).getFile();
1031 assertNull( downloadedFile );
1032 assertNoTempFiles( expectedFile );
1036 * Transfer the metadata file.
1038 * @param requestedResource the requested resource
1041 private void assertFetchVersioned( String requestedResource )
1044 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1046 ContentItem item = managedDefaultRepository.toItem( requestedResource );
1047 if (item instanceof DataItem) {
1048 item = managedDefaultRepository.getParent( item );
1050 assertNotNull( item );
1051 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1052 Version version = layout.adaptItem( Version.class, item );
1053 assertNotNull( version );
1054 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem(
1057 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1058 metaPath).getFile();
1060 assertNotNull( "Should have downloaded a file.", downloadedFile );
1061 assertNoTempFiles( expectedFile );
1066 * Transfer the metadata file, not expected to succeed.
1068 * @param requestedResource the requested resource
1071 private void assertFetchVersionedFailed( String requestedResource )
1074 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1075 ContentItem item = managedDefaultRepository.toItem( requestedResource );
1076 assertNotNull( item );
1077 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
1078 Version version = layout.adaptItem( Version.class, item );
1079 assertNotNull( version );
1080 String metaPath = managedDefaultRepository.toPath( layout.getMetadataItem(
1082 assertNotNull( metaPath );
1083 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1084 metaPath ).getFile();
1086 assertNull( downloadedFile );
1087 assertNoTempFiles( expectedFile );
1091 * Test for the existance of the requestedResource in the default managed repository.
1093 * @param requestedResource the requested resource
1096 private void assertResourceExists( String requestedResource )
1099 Path actualFile = managedDefaultDir.resolve(requestedResource);
1100 assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
1103 private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
1106 assertNotNull( "Actual File should not be null.", actualFile );
1108 assertTrue( "Actual file exists.", Files.exists(actualFile) );
1110 StringWriter actualContents = new StringWriter();
1111 FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
1112 StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
1113 ArchivaRepositoryMetadata metadata = metadataTools.getMetadataReader( null ).read( actualFileAsset );
1114 RepositoryMetadataWriter.write( metadata, actualContents );
1116 Diff detailedDiff = DiffBuilder.compare( expectedMetadataXml).withTest( actualContents.toString() ).checkForSimilar().build();
1117 if ( detailedDiff.hasDifferences() )
1119 for ( Difference diff : detailedDiff.getDifferences() )
1121 System.out.println( diff );
1123 assertEquals( expectedMetadataXml, actualContents );
1126 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1130 * Ensures that the requested resource is not present in the managed repository.
1132 * @param requestedResource the requested resource
1135 private void assertNoMetadata( String requestedResource )
1138 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1139 assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
1143 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1144 * managed repository.
1146 * @param proxiedRepoId the proxied repository id to validate with.
1147 * @param requestedResource the resource requested.
1149 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1151 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1153 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1154 assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
1157 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1160 Path actualFile = managedDefaultDir.resolve(requestedResource);
1161 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1163 ItemSelector actualMetadata = createGroupSelector( requestedResource );
1165 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1168 private ItemSelector createProjectSelector(String path) throws RepositoryMetadataException
1170 return metadataTools.toProjectSelector( path );
1173 private ItemSelector createVersionedSelector(String path) throws RepositoryMetadataException
1175 return metadataTools.toVersionedSelector( path );
1178 private ItemSelector createGroupSelector( String requestedResource )
1179 throws RepositoryMetadataException
1181 ItemSelector projectSelector = createProjectSelector( requestedResource );
1182 ArchivaItemSelector.Builder projectReference = ArchivaItemSelector.builder( ).withSelector( projectSelector );
1183 projectReference.withNamespace( projectSelector.getNamespace() + "." + projectSelector.getProjectId() );
1184 projectReference.withArtifactId( null );
1185 projectReference.withProjectId( null );
1186 return projectReference.build();
1189 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1190 String expectedPlugins[] )
1193 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1195 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1196 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1198 ItemSelector actualMetadata = createGroupSelector( requestedResource );
1200 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1203 private void assertGroupMetadata( Path actualFile, ItemSelector actualMetadata, String expectedPlugins[] )
1206 // Build expected metadata XML
1207 StringWriter expectedMetadataXml = new StringWriter();
1208 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1209 m.setGroupId( actualMetadata.getNamespace() );
1211 for ( String pluginId : expectedPlugins )
1213 Plugin p = new Plugin();
1214 p.setPrefix( pluginId );
1215 p.setArtifactId( pluginId + "-maven-plugin" );
1216 p.setName( "The " + pluginId + " Plugin" );
1217 m.getPlugins().add( p );
1220 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1222 // Compare the file to the actual contents.
1223 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1227 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1228 * does it contain the specified list of expected versions?
1230 * @param requestedResource the requested resource
1233 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1234 String latestVersion, String releaseVersion )
1237 Path actualFile = managedDefaultDir.resolve(requestedResource);
1238 assertTrue( Files.exists(actualFile) );
1240 ItemSelector metadata = createProjectSelector( requestedResource );
1242 // Build expected metadata XML
1243 StringWriter expectedMetadataXml = new StringWriter();
1244 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1245 m.setGroupId( metadata.getNamespace() );
1246 m.setArtifactId( metadata.getArtifactId() );
1247 m.setLatestVersion( latestVersion );
1248 m.setReleasedVersion( releaseVersion );
1250 if ( expectedVersions != null )
1252 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1255 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1257 // Compare the file to the actual contents.
1258 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1262 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1263 * does it contain the expected release maven-metadata.xml contents?
1265 * @param requestedResource the requested resource
1268 private void assertReleaseMetadataContents( String requestedResource )
1271 Path actualFile = managedDefaultDir.resolve(requestedResource);
1272 assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1274 ItemSelector metadata = createVersionedSelector( requestedResource );
1276 // Build expected metadata XML
1277 StringWriter expectedMetadataXml = new StringWriter();
1278 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1279 m.setGroupId( metadata.getNamespace() );
1280 m.setArtifactId( metadata.getArtifactId() );
1281 m.setVersion( metadata.getVersion() );
1282 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1284 // Compare the file to the actual contents.
1285 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1289 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1290 * does it contain the expected release maven-metadata.xml contents?
1292 * @param requestedResource the requested resource
1293 * @param expectedDate the date in "yyyyMMdd" format
1294 * @param expectedTime the time in "hhmmss" format
1295 * @param expectedBuildnumber the build number
1298 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1299 int expectedBuildnumber )
1302 Path actualFile = managedDefaultDir.resolve(requestedResource);
1303 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1305 ItemSelector actualMetadata = createVersionedSelector( requestedResource );
1307 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1311 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1312 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1314 * @param proxiedRepoId the repository id of the proxied repository.
1315 * @param requestedResource the requested resource
1316 * @param expectedDate the date in "yyyyMMdd" format
1317 * @param expectedTime the time in "hhmmss" format
1318 * @param expectedBuildnumber the build number
1321 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1322 String expectedDate, String expectedTime, int expectedBuildnumber )
1325 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1327 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1328 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1330 ItemSelector actualMetadata = createVersionedSelector( requestedResource );
1332 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1335 private void assertSnapshotMetadata( Path actualFile, ItemSelector actualMetadata, String expectedDate,
1336 String expectedTime, int expectedBuildnumber )
1337 throws RepositoryMetadataException, Exception
1339 // Build expected metadata XML
1340 StringWriter expectedMetadataXml = new StringWriter();
1341 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1342 m.setGroupId( actualMetadata.getNamespace() );
1343 m.setArtifactId( actualMetadata.getArtifactId() );
1344 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1346 m.setSnapshotVersion( new SnapshotVersion() );
1348 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1350 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1353 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1355 m.setLastUpdated( expectedDate + expectedTime );
1357 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1359 // Compare the file to the actual contents.
1360 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1364 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1365 * list of expected versions within.
1367 * @param proxiedRepoId
1368 * @param requestedResource
1369 * @param expectedProxyVersions
1371 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1372 String[] expectedProxyVersions )
1375 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1377 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1378 assertTrue( Files.exists(actualFile) );
1380 ItemSelector metadata = createProjectSelector( requestedResource );
1382 // Build expected metadata XML
1383 StringWriter expectedMetadataXml = new StringWriter();
1384 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1385 m.setGroupId( metadata.getNamespace() );
1386 m.setArtifactId( metadata.getArtifactId() );
1388 if ( expectedProxyVersions != null )
1390 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1393 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1395 // Compare the file to the actual contents.
1396 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1400 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1401 * list of expected versions within.
1403 * @param proxiedRepoId
1404 * @param requestedResource
1406 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1409 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1411 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1412 assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
1414 ItemSelector metadata = createVersionedSelector( requestedResource );
1416 // Build expected metadata XML
1417 StringWriter expectedMetadataXml = new StringWriter();
1418 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1419 m.setGroupId( metadata.getNamespace() );
1420 m.setArtifactId( metadata.getArtifactId() );
1421 m.setVersion( metadata.getVersion() );
1422 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1424 // Compare the file to the actual contents.
1425 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1429 * Test for the non-existance of the requestedResource in the default managed repository.
1431 * @param requestedResource the requested resource
1434 private void assertResourceNotFound( String requestedResource )
1437 Path actualFile = managedDefaultDir.resolve(requestedResource);
1438 assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );