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.maven2.metadata.MavenMetadataReader;
26 import org.apache.archiva.model.ArchivaRepositoryMetadata;
27 import org.apache.archiva.model.Plugin;
28 import org.apache.archiva.model.ProjectReference;
29 import org.apache.archiva.model.SnapshotVersion;
30 import org.apache.archiva.model.VersionedReference;
31 import org.apache.archiva.policies.CachedFailuresPolicy;
32 import org.apache.archiva.policies.ChecksumPolicy;
33 import org.apache.archiva.policies.ReleasesPolicy;
34 import org.apache.archiva.policies.SnapshotsPolicy;
35 import org.apache.archiva.repository.metadata.base.MetadataTools;
36 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
37 import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
38 import org.apache.archiva.repository.storage.FilesystemStorage;
39 import org.apache.archiva.repository.storage.StorageAsset;
40 import org.apache.commons.lang3.StringUtils;
41 import org.apache.maven.wagon.TransferFailedException;
42 import org.custommonkey.xmlunit.DetailedDiff;
43 import org.custommonkey.xmlunit.Diff;
44 import org.easymock.EasyMock;
45 import org.junit.Test;
47 import javax.inject.Inject;
48 import javax.inject.Named;
50 import java.io.StringWriter;
51 import java.nio.file.Files;
52 import java.nio.file.Path;
53 import java.util.ArrayList;
54 import java.util.Arrays;
56 import static org.junit.Assert.*;
59 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
60 * present in the repository.
62 * Test Case Naming is as follows.
65 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
69 * Which should leave the following matrix of test cases.
71 * Metadata | Proxied | Local | Remote
72 * ----------+----------+-------+---------
73 * Release | Not | Not | n/a (1)
74 * Release | Not | On | n/a (1)
75 * Release | | Not | Not
76 * Release | | Not | On
77 * Release | | Not | Multiple
78 * Release | | On | Not
80 * Release | | On | Multiple
81 * Snapshot | Not | Not | n/a (1)
82 * Snapshot | Not | On | n/a (1)
83 * Snapshot | | Not | Not
84 * Snapshot | | Not | On
85 * Snapshot | | Not | Multiple
86 * Snapshot | | On | Not
87 * Snapshot | | On | On
88 * Snapshot | | On | Multiple
89 * Project | Not | Not | n/a (1)
90 * Project | Not | On | n/a (1)
91 * Project | | Not | Not
92 * Project | | Not | On
93 * Project | | Not | Multiple
94 * Project | | On | Not
96 * Project | | On | Multiple
98 * (1) If it isn't proxied, no point in having a remote.
103 public class MetadataTransferTest
104 extends AbstractProxyTestCase
108 @Named(value = "metadataTools#mocked")
109 private MetadataTools metadataTools;
113 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
116 // New project metadata that does not exist locally but exists on remote.
117 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
118 setupTestableManagedRepository( requestedResource );
120 // Configure Connector (usually done within archiva.xml configuration)
121 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
122 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
124 assertResourceNotFound( requestedResource );
125 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
127 Path expectedFile = managedDefaultDir.resolve(requestedResource);
129 ProjectReference metadata = createProjectReference( requestedResource );
131 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
132 managedDefaultRepository.toMetadataPath(
133 metadata ) ).getFile();
135 assertNull( "Should not have downloaded a file.", downloadedFile );
136 assertNoTempFiles( expectedFile );
139 // TODO: same test for other fetch* methods
141 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
144 // Project metadata that does not exist locally, but has multiple versions in remote repos
145 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
146 setupTestableManagedRepository( requestedResource );
148 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default" );
150 // Configure Connector (usually done within archiva.xml configuration)
151 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
152 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
153 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
154 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
156 assertResourceNotFound( requestedResource );
157 assertNoRepoMetadata( "badproxied1", requestedResource );
158 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
160 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
161 Path expectedFile = managedDefaultDir.resolve(
162 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
164 wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
165 EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
168 wagonMockControl.replay();
170 assertFetchProjectOrGroup( requestedResource );
172 wagonMockControl.verify();
174 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
175 assertNoRepoMetadata( "badproxied1", requestedResource );
176 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
180 * Attempt to get the project metadata for non-existant artifact.
182 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
183 * to the requesting client.
186 public void testGetProjectMetadataNotProxiedNotLocal()
189 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
190 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
191 setupTestableManagedRepository( requestedResource );
193 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
195 assertResourceNotFound( requestedResource );
197 // No proxy setup, nothing fetched, failure expected.
198 assertFetchProjectOrGroupFailed( requestedResource );
200 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
201 assertResourceNotFound( requestedResource );
205 public void testGetProjectMetadataNotProxiedOnLocal()
209 // Project metadata that exists and has multiple versions
210 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
211 setupTestableManagedRepository( requestedResource );
213 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
215 assertResourceExists( requestedResource );
217 // No proxy setup, nothing fetched from remote, but local exists.
218 assertFetchProjectOrGroup( requestedResource );
220 // Nothing fetched. Should only contain contents of what is in the repository.
221 // A metadata update is not performed in this use case. Local metadata content is only
222 // updated via the metadata updater consumer.
223 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
227 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
230 // Project metadata that does not exist locally, but has multiple versions in remote repos
231 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
232 setupTestableManagedRepository( requestedResource );
234 // Configure Connector (usually done within archiva.xml configuration)
235 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
236 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
237 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
238 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
240 assertResourceNotFound( requestedResource );
241 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
242 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
244 // Two proxies setup, metadata fetched from both remotes.
245 assertFetchProjectOrGroup( requestedResource );
247 // Nothing fetched. Should only contain contents of what is in the repository.
248 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
249 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
250 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
254 public void testGetProjectMetadataProxiedNotLocalNotRemote()
257 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
258 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
259 setupTestableManagedRepository( requestedResource );
261 // Configure Connector (usually done within archiva.xml configuration)
262 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
263 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
264 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
265 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
267 assertResourceNotFound( requestedResource );
268 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
269 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
271 // Two proxies setup, nothing fetched from remotes, local does not exist.
272 assertFetchProjectOrGroupFailed( requestedResource );
274 // Nothing fetched. Nothing should exist.
275 assertResourceNotFound( requestedResource );
276 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
277 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
281 public void testGetProjectMetadataProxiedNotLocalOnRemote()
284 // New project metadata that does not exist locally but exists on remote.
285 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
286 setupTestableManagedRepository( requestedResource );
288 // Configure Connector (usually done within archiva.xml configuration)
289 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
290 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
292 assertResourceNotFound( requestedResource );
293 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
295 // One proxy setup, metadata fetched from remote, local does not exist.
296 assertFetchProjectOrGroup( requestedResource );
298 // Remote fetched. Local created/updated.
299 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
300 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
304 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
307 // Project metadata that exist locally, and has multiple versions in remote repos
308 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
309 setupTestableManagedRepository( requestedResource );
311 // Configure Connector (usually done within archiva.xml configuration)
312 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
313 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
314 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
315 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
317 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
318 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
319 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
321 // Two proxies setup, metadata fetched from both remotes.
322 assertFetchProjectOrGroup( requestedResource );
324 // metadata fetched from both repos, and merged with local version.
325 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
326 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
327 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
331 public void testGetProjectMetadataProxiedOnLocalNotRemote()
335 // Project metadata that exist locally, and does not exist in remote repos.
336 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
337 setupTestableManagedRepository( requestedResource );
340 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
341 // Configure Connector (usually done within archiva.xml configuration)
342 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
343 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
344 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
345 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
347 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
348 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
349 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
351 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
352 assertFetchProjectOrGroup( requestedResource );
354 // metadata not fetched from both repos, and local version exists.
355 // Since there was no updated metadata content from a remote/proxy, a metadata update on
356 // the local file never ran. Local only updates are performed via the metadata updater consumer.
357 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
358 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
359 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
363 public void testGetProjectMetadataProxiedOnLocalOnRemote()
366 // Project metadata that exist locally and exists on remote.
367 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
368 setupTestableManagedRepository( requestedResource );
370 // Configure Connector (usually done within archiva.xml configuration)
371 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
372 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
374 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
375 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
377 // One proxy setup, metadata fetched from remote, local exists.
378 assertFetchProjectOrGroup( requestedResource );
380 // Remote fetched. Local updated.
381 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
382 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
386 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
387 * repository has no proxied repositories set up.
389 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
390 * to the requesting client.
393 public void testGetReleaseMetadataNotProxiedNotLocal()
396 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
397 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
398 setupTestableManagedRepository( requestedResource );
400 assertNoMetadata( requestedResource );
402 // No proxy setup, nothing fetched, failure expected.
403 assertFetchVersionedFailed( requestedResource );
405 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
406 assertNoMetadata( requestedResource );
410 * A request for a maven-metadata.xml file that does exist locally, and the managed
411 * repository has no proxied repositories set up.
413 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
414 * information, and then returned to the client.
417 public void testGetReleaseMetadataNotProxiedOnLocal()
420 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
421 setupTestableManagedRepository( requestedResource );
423 assertResourceExists( requestedResource );
425 assertFetchVersioned( requestedResource );
427 assertReleaseMetadataContents( requestedResource );
431 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
432 * exists on multiple remote repositories.
434 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
435 * file location on the managed repository, a merge of the contents to the requested
436 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
437 * returned to the client.
440 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
443 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
444 setupTestableManagedRepository( requestedResource );
446 // Configure Connector (usually done within archiva.xml configuration)
447 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
448 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
449 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
450 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
452 assertResourceNotFound( requestedResource );
453 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
454 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
456 assertFetchVersioned( requestedResource );
458 assertReleaseMetadataContents( requestedResource );
459 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
460 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
464 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
465 * proxied repository.
467 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
468 * information, and then return to the client.
471 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
474 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
475 setupTestableManagedRepository( requestedResource );
477 // Configure Connector (usually done within archiva.xml configuration)
478 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
479 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
481 assertResourceNotFound( requestedResource );
483 assertFetchProjectOrGroupFailed( requestedResource );
485 assertResourceNotFound( requestedResource );
486 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
490 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
491 * exists on 1 remote repository.
493 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
494 * file location on the managed repository, a merge of the contents to the requested
495 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
496 * returned to the client.
499 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
502 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
503 setupTestableManagedRepository( requestedResource );
505 // Configure Connector (usually done within archiva.xml configuration)
506 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
507 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
509 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
511 assertFetchVersioned( requestedResource );
513 assertReleaseMetadataContents( requestedResource );
514 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
518 * A request for a maven-metadata.xml file that exists in the managed repository, but
519 * not on any remote repository.
521 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
522 * is not downloaded. There is no repository specific metadata file on the managed
523 * repository. The managed repository maven-metadata.xml is returned to the
527 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
530 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
531 setupTestableManagedRepository( requestedResource );
533 // Configure Connector (usually done within archiva.xml configuration)
534 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
535 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
537 assertReleaseMetadataContents( requestedResource );
539 assertFetchVersioned( requestedResource );
541 assertReleaseMetadataContents( requestedResource );
542 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
546 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
547 * remote repositories.
549 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
550 * and merged into the contents of the existing managed repository copy of
551 * the maven-metadata.xml file.
554 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
557 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
558 setupTestableManagedRepository( requestedResource );
560 // Configure Connector (usually done within archiva.xml configuration)
561 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
562 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
563 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
564 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
566 assertReleaseMetadataContents( requestedResource );
567 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
568 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
570 assertFetchVersioned( requestedResource );
572 assertReleaseMetadataContents( requestedResource );
573 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
574 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
578 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
581 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
582 * and merged into the contents of the existing managed repository copy of
583 * the maven-metadata.xml file.
586 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
589 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
590 setupTestableManagedRepository( requestedResource );
592 // Configure Connector (usually done within archiva.xml configuration)
593 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
594 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
596 assertReleaseMetadataContents( requestedResource );
597 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
599 assertFetchVersioned( requestedResource );
601 assertReleaseMetadataContents( requestedResource );
602 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
606 public void testGetSnapshotMetadataNotProxiedNotLocal()
609 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
610 String requestedResource =
611 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
612 setupTestableManagedRepository( requestedResource );
614 assertNoMetadata( requestedResource );
616 // No proxy setup, nothing fetched, no local file, failure expected.
617 assertFetchVersionedFailed( requestedResource );
619 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
620 assertNoMetadata( requestedResource );
624 public void testGetSnapshotMetadataNotProxiedOnLocal()
627 // The artifactId exists locally (but not on a remote repo)
628 String requestedResource =
629 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
630 setupTestableManagedRepository( requestedResource );
632 assertResourceExists( requestedResource );
634 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
635 assertFetchVersioned( requestedResource );
637 // Local metadata exists, should be updated to reflect the latest release.
638 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
642 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
645 String requestedResource =
646 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
647 setupTestableManagedRepository( requestedResource );
649 // Configure Connector (usually done within archiva.xml configuration)
650 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
651 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
652 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
653 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
655 assertResourceNotFound( requestedResource );
656 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
657 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
659 // Proxying 2 repos, both have content, local file updated.
660 assertFetchVersioned( requestedResource );
662 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
663 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
664 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
668 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
671 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
672 String requestedResource =
673 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
674 setupTestableManagedRepository( requestedResource );
676 // Configure Connector (usually done within archiva.xml configuration)
677 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
678 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
680 assertNoMetadata( requestedResource );
682 // One proxy setup, nothing fetched, no local file, failure expected.
683 assertFetchVersionedFailed( requestedResource );
685 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
686 assertNoMetadata( requestedResource );
687 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
691 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
694 // Artifact exists only in the proxied1 location.
695 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
696 setupTestableManagedRepository( requestedResource );
698 // Configure Connector (usually done within archiva.xml configuration)
699 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
700 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
702 assertResourceNotFound( requestedResource );
704 // One proxy setup, one metadata fetched, local file created/updated.
705 assertFetchVersioned( requestedResource );
707 // Local artifact Id should contain latest (which in this case is from proxied download)
708 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
709 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
713 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
716 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
717 setupTestableManagedRepository( requestedResource );
719 // Configure Connector (usually done within archiva.xml configuration)
720 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
721 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
722 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
723 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
725 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
726 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
727 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
729 // Proxying 2 repos, both have content, local file updated.
730 assertFetchVersioned( requestedResource );
732 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
733 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
734 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
738 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
741 // The artifactId exists locally (but not on a remote repo)
742 String requestedResource =
743 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
744 setupTestableManagedRepository( requestedResource );
746 // Configure Connector (usually done within archiva.xml configuration)
747 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
748 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
749 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
750 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
752 assertResourceExists( requestedResource );
753 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
754 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
756 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
757 assertFetchVersioned( requestedResource );
759 // Local metadata exists, repo metadatas should not exist, local file updated.
760 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
761 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
762 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
766 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
769 // The artifactId exists locally (but not on a remote repo)
770 String requestedResource =
771 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
772 setupTestableManagedRepository( requestedResource );
774 // Configure Connector (usually done within archiva.xml configuration)
775 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
776 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
778 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
779 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
781 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
782 assertFetchVersioned( requestedResource );
784 // Local metadata exists, repo metadata exists, local file updated.
785 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
786 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
790 public void testGetGroupMetadataNotProxiedNotLocal()
793 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
794 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
795 setupTestableManagedRepository( requestedResource );
797 assertResourceNotFound( requestedResource );
799 // No proxy setup, nothing fetched, failure expected.
800 assertFetchProjectOrGroupFailed( requestedResource );
802 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
803 assertResourceNotFound( requestedResource );
807 public void testGetGroupMetadataNotProxiedOnLocal()
810 // Project metadata that exists and has multiple versions
811 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
812 setupTestableManagedRepository( requestedResource );
814 assertResourceExists( requestedResource );
816 // No proxy setup, nothing fetched from remote, but local exists.
817 assertFetchProjectOrGroup( requestedResource );
819 // Nothing fetched. Should only contain contents of what is in the repository.
820 // A metadata update is not performed in this use case. Local metadata content is only
821 // updated via the metadata updater consumer.
822 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
826 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
829 // Project metadata that does not exist locally, but has multiple versions in remote repos
830 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
831 setupTestableManagedRepository( requestedResource );
833 // Configure Connector (usually done within archiva.xml configuration)
834 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
835 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
836 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
837 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
839 assertResourceNotFound( requestedResource );
840 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
841 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
843 // Two proxies setup, metadata fetched from both remotes.
844 assertFetchProjectOrGroup( requestedResource );
846 // Nothing fetched. Should only contain contents of what is in the repository.
847 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
848 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
849 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
853 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
856 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
857 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
858 setupTestableManagedRepository( requestedResource );
860 // Configure Connector (usually done within archiva.xml configuration)
861 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
862 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
863 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
864 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
866 assertResourceNotFound( requestedResource );
867 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
868 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
870 // Two proxies setup, nothing fetched from remotes, local does not exist.
871 assertFetchProjectOrGroupFailed( requestedResource );
873 // Nothing fetched. Nothing should exist.
874 assertResourceNotFound( requestedResource );
875 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
876 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
880 public void testGetGroupMetadataProxiedNotLocalOnRemote()
883 // New project metadata that does not exist locally but exists on remote.
884 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
885 setupTestableManagedRepository( requestedResource );
887 // Configure Connector (usually done within archiva.xml configuration)
888 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
889 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
891 assertResourceNotFound( requestedResource );
892 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
894 // One proxy setup, metadata fetched from remote, local does not exist.
895 assertFetchProjectOrGroup( requestedResource );
897 // Remote fetched. Local created/updated.
898 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
899 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
903 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
906 // Project metadata that exist locally, and has multiple versions in remote repos
907 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
908 setupTestableManagedRepository( requestedResource );
910 // Configure Connector (usually done within archiva.xml configuration)
911 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
912 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
913 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
914 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
916 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
917 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
918 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
920 // Two proxies setup, metadata fetched from both remotes.
921 assertFetchProjectOrGroup( requestedResource );
923 // metadata fetched from both repos, and merged with local version.
924 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
925 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
926 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
930 public void testGetGroupMetadataProxiedOnLocalNotRemote()
933 // Project metadata that exist locally, and does not exist in remote repos.
934 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
935 setupTestableManagedRepository( requestedResource );
937 // Configure Connector (usually done within archiva.xml configuration)
938 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
939 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
940 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
941 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
943 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
944 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
945 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
947 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
948 assertFetchProjectOrGroup( requestedResource );
950 // metadata not fetched from both repos, and local version exists.
951 // Since there was no updated metadata content from a remote/proxy, a metadata update on
952 // the local file never ran. Local only updates are performed via the metadata updater consumer.
953 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
954 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
955 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
959 public void testGetGroupMetadataProxiedOnLocalOnRemote()
962 // Project metadata that exist locally and exists on remote.
963 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
964 setupTestableManagedRepository( requestedResource );
966 // Configure Connector (usually done within archiva.xml configuration)
967 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
968 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
970 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
971 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
973 // One proxy setup, metadata fetched from remote, local exists.
974 assertFetchProjectOrGroup( requestedResource );
976 // Remote fetched. Local updated.
977 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
978 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
982 * Transfer the metadata file.
984 * @param requestedResource the requested resource
987 private void assertFetchProjectOrGroup( String requestedResource )
990 Path expectedFile = managedDefaultDir.resolve(requestedResource);
992 ProjectReference metadata = createProjectReference( requestedResource );
994 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
995 managedDefaultRepository.toMetadataPath(
996 metadata ) ).getFile();
998 assertNotNull( "Should have downloaded a file.", downloadedFile );
999 assertNoTempFiles( expectedFile );
1002 private ProjectReference createProjectReference( String path )
1003 throws RepositoryMetadataException
1005 return metadataTools.toProjectReference( path );
1009 * Transfer the metadata file, not expected to succeed.
1011 * @param requestedResource the requested resource
1014 private void assertFetchProjectOrGroupFailed( String requestedResource )
1017 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1018 ProjectReference metadata = createProjectReference( requestedResource );
1020 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1021 managedDefaultRepository.toMetadataPath(
1022 metadata ) ).getFile();
1024 assertNull( downloadedFile );
1025 assertNoTempFiles( expectedFile );
1029 * Transfer the metadata file.
1031 * @param requestedResource the requested resource
1034 private void assertFetchVersioned( String requestedResource )
1037 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1039 VersionedReference metadata = createVersionedReference( requestedResource );
1041 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1042 managedDefaultRepository.toMetadataPath(
1043 metadata ) ).getFile();
1045 assertNotNull( "Should have downloaded a file.", downloadedFile );
1046 assertNoTempFiles( expectedFile );
1049 private VersionedReference createVersionedReference( String path )
1050 throws RepositoryMetadataException
1052 return metadataTools.toVersionedReference( path );
1056 * Transfer the metadata file, not expected to succeed.
1058 * @param requestedResource the requested resource
1061 private void assertFetchVersionedFailed( String requestedResource )
1064 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1065 VersionedReference metadata = createVersionedReference( requestedResource );
1067 StorageAsset downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository.getRepository(),
1068 managedDefaultRepository.toMetadataPath(
1069 metadata ) ).getFile();
1071 assertNull( downloadedFile );
1072 assertNoTempFiles( expectedFile );
1076 * Test for the existance of the requestedResource in the default managed repository.
1078 * @param requestedResource the requested resource
1081 private void assertResourceExists( String requestedResource )
1084 Path actualFile = managedDefaultDir.resolve(requestedResource);
1085 assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
1088 private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
1091 assertNotNull( "Actual File should not be null.", actualFile );
1093 assertTrue( "Actual file exists.", Files.exists(actualFile) );
1095 StringWriter actualContents = new StringWriter();
1096 FilesystemStorage fsStorage = new FilesystemStorage(actualFile.getParent(), new DefaultFileLockManager());
1097 StorageAsset actualFileAsset = fsStorage.getAsset(actualFile.getFileName().toString());
1098 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFileAsset );
1099 RepositoryMetadataWriter.write( metadata, actualContents );
1101 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1102 if ( !detailedDiff.similar() )
1104 assertEquals( expectedMetadataXml, actualContents );
1107 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1111 * Ensures that the requested resource is not present in the managed repository.
1113 * @param requestedResource the requested resource
1116 private void assertNoMetadata( String requestedResource )
1119 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1120 assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
1124 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1125 * managed repository.
1127 * @param proxiedRepoId the proxied repository id to validate with.
1128 * @param requestedResource the resource requested.
1130 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1132 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1134 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1135 assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
1138 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1141 Path actualFile = managedDefaultDir.resolve(requestedResource);
1142 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1144 ProjectReference actualMetadata = createGroupReference( requestedResource );
1146 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1149 private ProjectReference createGroupReference( String requestedResource )
1150 throws RepositoryMetadataException
1152 ProjectReference projectReference = createProjectReference( requestedResource );
1153 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1154 projectReference.setArtifactId( null );
1155 return projectReference;
1158 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1159 String expectedPlugins[] )
1162 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1164 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1165 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1167 ProjectReference actualMetadata = createGroupReference( requestedResource );
1169 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1172 private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1175 // Build expected metadata XML
1176 StringWriter expectedMetadataXml = new StringWriter();
1177 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1178 m.setGroupId( actualMetadata.getGroupId() );
1180 for ( String pluginId : expectedPlugins )
1182 Plugin p = new Plugin();
1183 p.setPrefix( pluginId );
1184 p.setArtifactId( pluginId + "-maven-plugin" );
1185 p.setName( "The " + pluginId + " Plugin" );
1186 m.getPlugins().add( p );
1189 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1191 // Compare the file to the actual contents.
1192 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1196 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1197 * does it contain the specified list of expected versions?
1199 * @param requestedResource the requested resource
1202 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1203 String latestVersion, String releaseVersion )
1206 Path actualFile = managedDefaultDir.resolve(requestedResource);
1207 assertTrue( Files.exists(actualFile) );
1209 ProjectReference metadata = createProjectReference( requestedResource );
1211 // Build expected metadata XML
1212 StringWriter expectedMetadataXml = new StringWriter();
1213 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1214 m.setGroupId( metadata.getGroupId() );
1215 m.setArtifactId( metadata.getArtifactId() );
1216 m.setLatestVersion( latestVersion );
1217 m.setReleasedVersion( releaseVersion );
1219 if ( expectedVersions != null )
1221 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1224 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1226 // Compare the file to the actual contents.
1227 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1231 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1232 * does it contain the expected release maven-metadata.xml contents?
1234 * @param requestedResource the requested resource
1237 private void assertReleaseMetadataContents( String requestedResource )
1240 Path actualFile = managedDefaultDir.resolve(requestedResource);
1241 assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1243 VersionedReference metadata = createVersionedReference( requestedResource );
1245 // Build expected metadata XML
1246 StringWriter expectedMetadataXml = new StringWriter();
1247 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1248 m.setGroupId( metadata.getGroupId() );
1249 m.setArtifactId( metadata.getArtifactId() );
1250 m.setVersion( metadata.getVersion() );
1251 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1253 // Compare the file to the actual contents.
1254 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1258 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1259 * does it contain the expected release maven-metadata.xml contents?
1261 * @param requestedResource the requested resource
1262 * @param expectedDate the date in "yyyyMMdd" format
1263 * @param expectedTime the time in "hhmmss" format
1264 * @param expectedBuildnumber the build number
1267 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1268 int expectedBuildnumber )
1271 Path actualFile = managedDefaultDir.resolve(requestedResource);
1272 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1274 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1276 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1280 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1281 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1283 * @param proxiedRepoId the repository id of the proxied repository.
1284 * @param requestedResource the requested resource
1285 * @param expectedDate the date in "yyyyMMdd" format
1286 * @param expectedTime the time in "hhmmss" format
1287 * @param expectedBuildnumber the build number
1290 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1291 String expectedDate, String expectedTime, int expectedBuildnumber )
1294 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1296 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1297 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1299 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1301 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1304 private void assertSnapshotMetadata( Path actualFile, VersionedReference actualMetadata, String expectedDate,
1305 String expectedTime, int expectedBuildnumber )
1306 throws RepositoryMetadataException, Exception
1308 // Build expected metadata XML
1309 StringWriter expectedMetadataXml = new StringWriter();
1310 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1311 m.setGroupId( actualMetadata.getGroupId() );
1312 m.setArtifactId( actualMetadata.getArtifactId() );
1313 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1315 m.setSnapshotVersion( new SnapshotVersion() );
1317 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1319 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1322 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1324 m.setLastUpdated( expectedDate + expectedTime );
1326 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1328 // Compare the file to the actual contents.
1329 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1333 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1334 * list of expected versions within.
1336 * @param proxiedRepoId
1337 * @param requestedResource
1338 * @param expectedProxyVersions
1340 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1341 String[] expectedProxyVersions )
1344 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1346 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1347 assertTrue( Files.exists(actualFile) );
1349 ProjectReference metadata = createProjectReference( requestedResource );
1351 // Build expected metadata XML
1352 StringWriter expectedMetadataXml = new StringWriter();
1353 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1354 m.setGroupId( metadata.getGroupId() );
1355 m.setArtifactId( metadata.getArtifactId() );
1357 if ( expectedProxyVersions != null )
1359 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1362 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1364 // Compare the file to the actual contents.
1365 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1369 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1370 * list of expected versions within.
1372 * @param proxiedRepoId
1373 * @param requestedResource
1375 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1378 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1380 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1381 assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
1383 VersionedReference metadata = createVersionedReference( requestedResource );
1385 // Build expected metadata XML
1386 StringWriter expectedMetadataXml = new StringWriter();
1387 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1388 m.setGroupId( metadata.getGroupId() );
1389 m.setArtifactId( metadata.getArtifactId() );
1390 m.setVersion( metadata.getVersion() );
1391 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1393 // Compare the file to the actual contents.
1394 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1398 * Test for the non-existance of the requestedResource in the default managed repository.
1400 * @param requestedResource the requested resource
1403 private void assertResourceNotFound( String requestedResource )
1406 Path actualFile = managedDefaultDir.resolve(requestedResource);
1407 assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );