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.utils.VersionUtil;
23 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
24 import org.apache.archiva.maven2.metadata.MavenMetadataReader;
25 import org.apache.archiva.model.ArchivaRepositoryMetadata;
26 import org.apache.archiva.model.Plugin;
27 import org.apache.archiva.model.ProjectReference;
28 import org.apache.archiva.model.SnapshotVersion;
29 import org.apache.archiva.model.VersionedReference;
30 import org.apache.archiva.policies.CachedFailuresPolicy;
31 import org.apache.archiva.policies.ChecksumPolicy;
32 import org.apache.archiva.policies.ReleasesPolicy;
33 import org.apache.archiva.policies.SnapshotsPolicy;
34 import org.apache.archiva.proxy.model.ProxyFetchResult;
35 import org.apache.archiva.repository.metadata.MetadataTools;
36 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
37 import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
38 import org.apache.commons.lang.StringUtils;
39 import org.apache.maven.wagon.ResourceDoesNotExistException;
40 import org.apache.maven.wagon.TransferFailedException;
41 import org.custommonkey.xmlunit.DetailedDiff;
42 import org.custommonkey.xmlunit.Diff;
43 import org.easymock.EasyMock;
44 import org.junit.Test;
46 import javax.inject.Inject;
47 import javax.inject.Named;
49 import java.io.StringWriter;
50 import java.nio.file.Files;
51 import java.nio.file.Path;
52 import java.util.ArrayList;
53 import java.util.Arrays;
55 import static org.junit.Assert.*;
58 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
59 * present in the repository.
61 * Test Case Naming is as follows.
64 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
68 * Which should leave the following matrix of test cases.
70 * Metadata | Proxied | Local | Remote
71 * ----------+----------+-------+---------
72 * Release | Not | Not | n/a (1)
73 * Release | Not | On | n/a (1)
74 * Release | | Not | Not
75 * Release | | Not | On
76 * Release | | Not | Multiple
77 * Release | | On | Not
79 * Release | | On | Multiple
80 * Snapshot | Not | Not | n/a (1)
81 * Snapshot | Not | On | n/a (1)
82 * Snapshot | | Not | Not
83 * Snapshot | | Not | On
84 * Snapshot | | Not | Multiple
85 * Snapshot | | On | Not
86 * Snapshot | | On | On
87 * Snapshot | | On | Multiple
88 * Project | Not | Not | n/a (1)
89 * Project | Not | On | n/a (1)
90 * Project | | Not | Not
91 * Project | | Not | On
92 * Project | | Not | Multiple
93 * Project | | On | Not
95 * Project | | On | Multiple
97 * (1) If it isn't proxied, no point in having a remote.
102 public class MetadataTransferTest
103 extends AbstractProxyTestCase
107 @Named(value = "metadataTools#mocked")
108 private MetadataTools metadataTools;
112 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
115 // New project metadata that does not exist locally but exists on remote.
116 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
117 setupTestableManagedRepository( requestedResource );
119 // Configure Connector (usually done within archiva.xml configuration)
120 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
121 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
123 assertResourceNotFound( requestedResource );
124 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
126 Path expectedFile = managedDefaultDir.resolve(requestedResource);
128 ProjectReference metadata = createProjectReference( requestedResource );
130 Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
131 managedDefaultRepository.toMetadataPath(
132 metadata ) ).getFile();
134 assertNull( "Should not have downloaded a file.", downloadedFile );
135 assertNoTempFiles( expectedFile );
138 // TODO: same test for other fetch* methods
140 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
143 // Project metadata that does not exist locally, but has multiple versions in remote repos
144 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
145 setupTestableManagedRepository( requestedResource );
147 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
149 // Configure Connector (usually done within archiva.xml configuration)
150 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
151 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
152 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
153 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
155 assertResourceNotFound( requestedResource );
156 assertNoRepoMetadata( "badproxied1", requestedResource );
157 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
159 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
160 Path expectedFile = managedDefaultDir.resolve(
161 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
163 wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
164 EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
167 wagonMockControl.replay();
169 assertFetchProjectOrGroup( requestedResource );
171 wagonMockControl.verify();
173 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
174 assertNoRepoMetadata( "badproxied1", requestedResource );
175 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
179 * Attempt to get the project metadata for non-existant artifact.
181 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
182 * to the requesting client.
185 public void testGetProjectMetadataNotProxiedNotLocal()
188 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
189 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
190 setupTestableManagedRepository( requestedResource );
192 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
194 assertResourceNotFound( requestedResource );
196 // No proxy setup, nothing fetched, failure expected.
197 assertFetchProjectOrGroupFailed( requestedResource );
199 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
200 assertResourceNotFound( requestedResource );
204 public void testGetProjectMetadataNotProxiedOnLocal()
208 // Project metadata that exists and has multiple versions
209 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
210 setupTestableManagedRepository( requestedResource );
212 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
214 assertResourceExists( requestedResource );
216 // No proxy setup, nothing fetched from remote, but local exists.
217 assertFetchProjectOrGroup( requestedResource );
219 // Nothing fetched. Should only contain contents of what is in the repository.
220 // A metadata update is not performed in this use case. Local metadata content is only
221 // updated via the metadata updater consumer.
222 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
226 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
229 // Project metadata that does not exist locally, but has multiple versions in remote repos
230 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
231 setupTestableManagedRepository( requestedResource );
233 // Configure Connector (usually done within archiva.xml configuration)
234 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
235 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
236 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
237 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
239 assertResourceNotFound( requestedResource );
240 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
241 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
243 // Two proxies setup, metadata fetched from both remotes.
244 assertFetchProjectOrGroup( requestedResource );
246 // Nothing fetched. Should only contain contents of what is in the repository.
247 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
248 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
249 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
253 public void testGetProjectMetadataProxiedNotLocalNotRemote()
256 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
257 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
258 setupTestableManagedRepository( requestedResource );
260 // Configure Connector (usually done within archiva.xml configuration)
261 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
262 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
263 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
264 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
266 assertResourceNotFound( requestedResource );
267 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
268 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
270 // Two proxies setup, nothing fetched from remotes, local does not exist.
271 assertFetchProjectOrGroupFailed( requestedResource );
273 // Nothing fetched. Nothing should exist.
274 assertResourceNotFound( requestedResource );
275 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
276 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
280 public void testGetProjectMetadataProxiedNotLocalOnRemote()
283 // New project metadata that does not exist locally but exists on remote.
284 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
285 setupTestableManagedRepository( requestedResource );
287 // Configure Connector (usually done within archiva.xml configuration)
288 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
289 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
291 assertResourceNotFound( requestedResource );
292 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
294 // One proxy setup, metadata fetched from remote, local does not exist.
295 assertFetchProjectOrGroup( requestedResource );
297 // Remote fetched. Local created/updated.
298 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
299 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
303 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
306 // Project metadata that exist locally, and has multiple versions in remote repos
307 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
308 setupTestableManagedRepository( requestedResource );
310 // Configure Connector (usually done within archiva.xml configuration)
311 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
312 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
313 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
314 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
316 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
317 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
318 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
320 // Two proxies setup, metadata fetched from both remotes.
321 assertFetchProjectOrGroup( requestedResource );
323 // metadata fetched from both repos, and merged with local version.
324 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
325 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
326 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
330 public void testGetProjectMetadataProxiedOnLocalNotRemote()
334 // Project metadata that exist locally, and does not exist in remote repos.
335 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
336 setupTestableManagedRepository( requestedResource );
339 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
340 // Configure Connector (usually done within archiva.xml configuration)
341 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
342 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
343 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
344 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
346 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
347 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
348 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
350 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
351 assertFetchProjectOrGroup( requestedResource );
353 // metadata not fetched from both repos, and local version exists.
354 // Since there was no updated metadata content from a remote/proxy, a metadata update on
355 // the local file never ran. Local only updates are performed via the metadata updater consumer.
356 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
357 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
358 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
362 public void testGetProjectMetadataProxiedOnLocalOnRemote()
365 // Project metadata that exist locally and exists on remote.
366 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
367 setupTestableManagedRepository( requestedResource );
369 // Configure Connector (usually done within archiva.xml configuration)
370 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
371 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
373 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
374 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
376 // One proxy setup, metadata fetched from remote, local exists.
377 assertFetchProjectOrGroup( requestedResource );
379 // Remote fetched. Local updated.
380 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
381 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
385 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
386 * repository has no proxied repositories set up.
388 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
389 * to the requesting client.
392 public void testGetReleaseMetadataNotProxiedNotLocal()
395 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
396 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
397 setupTestableManagedRepository( requestedResource );
399 assertNoMetadata( requestedResource );
401 // No proxy setup, nothing fetched, failure expected.
402 assertFetchVersionedFailed( requestedResource );
404 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
405 assertNoMetadata( requestedResource );
409 * A request for a maven-metadata.xml file that does exist locally, and the managed
410 * repository has no proxied repositories set up.
412 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
413 * information, and then returned to the client.
416 public void testGetReleaseMetadataNotProxiedOnLocal()
419 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
420 setupTestableManagedRepository( requestedResource );
422 assertResourceExists( requestedResource );
424 assertFetchVersioned( requestedResource );
426 assertReleaseMetadataContents( requestedResource );
430 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
431 * exists on multiple remote repositories.
433 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
434 * file location on the managed repository, a merge of the contents to the requested
435 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
436 * returned to the client.
439 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
442 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
443 setupTestableManagedRepository( requestedResource );
445 // Configure Connector (usually done within archiva.xml configuration)
446 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
447 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
448 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
449 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
451 assertResourceNotFound( requestedResource );
452 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
453 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
455 assertFetchVersioned( requestedResource );
457 assertReleaseMetadataContents( requestedResource );
458 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
459 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
463 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
464 * proxied repository.
466 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
467 * information, and then return to the client.
470 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
473 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
474 setupTestableManagedRepository( requestedResource );
476 // Configure Connector (usually done within archiva.xml configuration)
477 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
478 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
480 assertResourceNotFound( requestedResource );
482 assertFetchProjectOrGroupFailed( requestedResource );
484 assertResourceNotFound( requestedResource );
485 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
489 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
490 * exists on 1 remote repository.
492 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
493 * file location on the managed repository, a merge of the contents to the requested
494 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
495 * returned to the client.
498 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
501 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
502 setupTestableManagedRepository( requestedResource );
504 // Configure Connector (usually done within archiva.xml configuration)
505 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
506 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
508 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
510 assertFetchVersioned( requestedResource );
512 assertReleaseMetadataContents( requestedResource );
513 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
517 * A request for a maven-metadata.xml file that exists in the managed repository, but
518 * not on any remote repository.
520 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
521 * is not downloaded. There is no repository specific metadata file on the managed
522 * repository. The managed repository maven-metadata.xml is returned to the
526 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
529 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
530 setupTestableManagedRepository( requestedResource );
532 // Configure Connector (usually done within archiva.xml configuration)
533 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
534 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
536 assertReleaseMetadataContents( requestedResource );
538 assertFetchVersioned( requestedResource );
540 assertReleaseMetadataContents( requestedResource );
541 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
545 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
546 * remote repositories.
548 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
549 * and merged into the contents of the existing managed repository copy of
550 * the maven-metadata.xml file.
553 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
556 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
557 setupTestableManagedRepository( requestedResource );
559 // Configure Connector (usually done within archiva.xml configuration)
560 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
561 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
562 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
563 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
565 assertReleaseMetadataContents( requestedResource );
566 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
567 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
569 assertFetchVersioned( requestedResource );
571 assertReleaseMetadataContents( requestedResource );
572 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
573 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
577 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
580 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
581 * and merged into the contents of the existing managed repository copy of
582 * the maven-metadata.xml file.
585 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
588 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
589 setupTestableManagedRepository( requestedResource );
591 // Configure Connector (usually done within archiva.xml configuration)
592 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
593 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
595 assertReleaseMetadataContents( requestedResource );
596 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
598 assertFetchVersioned( requestedResource );
600 assertReleaseMetadataContents( requestedResource );
601 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
605 public void testGetSnapshotMetadataNotProxiedNotLocal()
608 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
609 String requestedResource =
610 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
611 setupTestableManagedRepository( requestedResource );
613 assertNoMetadata( requestedResource );
615 // No proxy setup, nothing fetched, no local file, failure expected.
616 assertFetchVersionedFailed( requestedResource );
618 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
619 assertNoMetadata( requestedResource );
623 public void testGetSnapshotMetadataNotProxiedOnLocal()
626 // The artifactId exists locally (but not on a remote repo)
627 String requestedResource =
628 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
629 setupTestableManagedRepository( requestedResource );
631 assertResourceExists( requestedResource );
633 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
634 assertFetchVersioned( requestedResource );
636 // Local metadata exists, should be updated to reflect the latest release.
637 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
641 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
644 String requestedResource =
645 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
646 setupTestableManagedRepository( requestedResource );
648 // Configure Connector (usually done within archiva.xml configuration)
649 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
650 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
651 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
652 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
654 assertResourceNotFound( requestedResource );
655 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
656 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
658 // Proxying 2 repos, both have content, local file updated.
659 assertFetchVersioned( requestedResource );
661 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
662 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
663 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
667 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
670 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
671 String requestedResource =
672 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
673 setupTestableManagedRepository( requestedResource );
675 // Configure Connector (usually done within archiva.xml configuration)
676 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
677 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
679 assertNoMetadata( requestedResource );
681 // One proxy setup, nothing fetched, no local file, failure expected.
682 assertFetchVersionedFailed( requestedResource );
684 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
685 assertNoMetadata( requestedResource );
686 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
690 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
693 // Artifact exists only in the proxied1 location.
694 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
695 setupTestableManagedRepository( requestedResource );
697 // Configure Connector (usually done within archiva.xml configuration)
698 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
699 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
701 assertResourceNotFound( requestedResource );
703 // One proxy setup, one metadata fetched, local file created/updated.
704 assertFetchVersioned( requestedResource );
706 // Local artifact Id should contain latest (which in this case is from proxied download)
707 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
708 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
712 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
715 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
716 setupTestableManagedRepository( requestedResource );
718 // Configure Connector (usually done within archiva.xml configuration)
719 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
720 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
721 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
722 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
724 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
725 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
726 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
728 // Proxying 2 repos, both have content, local file updated.
729 assertFetchVersioned( requestedResource );
731 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
732 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
733 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
737 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
740 // The artifactId exists locally (but not on a remote repo)
741 String requestedResource =
742 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
743 setupTestableManagedRepository( requestedResource );
745 // Configure Connector (usually done within archiva.xml configuration)
746 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
747 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
748 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
749 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
751 assertResourceExists( requestedResource );
752 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
753 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
755 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
756 assertFetchVersioned( requestedResource );
758 // Local metadata exists, repo metadatas should not exist, local file updated.
759 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
760 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
761 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
765 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
768 // The artifactId exists locally (but not on a remote repo)
769 String requestedResource =
770 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
771 setupTestableManagedRepository( requestedResource );
773 // Configure Connector (usually done within archiva.xml configuration)
774 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
775 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
777 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
778 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
780 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
781 assertFetchVersioned( requestedResource );
783 // Local metadata exists, repo metadata exists, local file updated.
784 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
785 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
789 public void testGetGroupMetadataNotProxiedNotLocal()
792 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
793 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
794 setupTestableManagedRepository( requestedResource );
796 assertResourceNotFound( requestedResource );
798 // No proxy setup, nothing fetched, failure expected.
799 assertFetchProjectOrGroupFailed( requestedResource );
801 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
802 assertResourceNotFound( requestedResource );
806 public void testGetGroupMetadataNotProxiedOnLocal()
809 // Project metadata that exists and has multiple versions
810 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
811 setupTestableManagedRepository( requestedResource );
813 assertResourceExists( requestedResource );
815 // No proxy setup, nothing fetched from remote, but local exists.
816 assertFetchProjectOrGroup( requestedResource );
818 // Nothing fetched. Should only contain contents of what is in the repository.
819 // A metadata update is not performed in this use case. Local metadata content is only
820 // updated via the metadata updater consumer.
821 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
825 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
828 // Project metadata that does not exist locally, but has multiple versions in remote repos
829 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
830 setupTestableManagedRepository( requestedResource );
832 // Configure Connector (usually done within archiva.xml configuration)
833 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
834 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
835 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
836 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
838 assertResourceNotFound( requestedResource );
839 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
840 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
842 // Two proxies setup, metadata fetched from both remotes.
843 assertFetchProjectOrGroup( requestedResource );
845 // Nothing fetched. Should only contain contents of what is in the repository.
846 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
847 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
848 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
852 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
855 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
856 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
857 setupTestableManagedRepository( requestedResource );
859 // Configure Connector (usually done within archiva.xml configuration)
860 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
861 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
862 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
863 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
865 assertResourceNotFound( requestedResource );
866 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
867 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
869 // Two proxies setup, nothing fetched from remotes, local does not exist.
870 assertFetchProjectOrGroupFailed( requestedResource );
872 // Nothing fetched. Nothing should exist.
873 assertResourceNotFound( requestedResource );
874 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
875 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
879 public void testGetGroupMetadataProxiedNotLocalOnRemote()
882 // New project metadata that does not exist locally but exists on remote.
883 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
884 setupTestableManagedRepository( requestedResource );
886 // Configure Connector (usually done within archiva.xml configuration)
887 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
888 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
890 assertResourceNotFound( requestedResource );
891 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
893 // One proxy setup, metadata fetched from remote, local does not exist.
894 assertFetchProjectOrGroup( requestedResource );
896 // Remote fetched. Local created/updated.
897 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
898 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
902 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
905 // Project metadata that exist locally, and has multiple versions in remote repos
906 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
907 setupTestableManagedRepository( requestedResource );
909 // Configure Connector (usually done within archiva.xml configuration)
910 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
911 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
912 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
913 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
915 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
916 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
917 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
919 // Two proxies setup, metadata fetched from both remotes.
920 assertFetchProjectOrGroup( requestedResource );
922 // metadata fetched from both repos, and merged with local version.
923 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
924 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
925 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
929 public void testGetGroupMetadataProxiedOnLocalNotRemote()
932 // Project metadata that exist locally, and does not exist in remote repos.
933 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
934 setupTestableManagedRepository( requestedResource );
936 // Configure Connector (usually done within archiva.xml configuration)
937 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
938 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
939 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
940 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
942 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
943 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
944 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
946 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
947 assertFetchProjectOrGroup( requestedResource );
949 // metadata not fetched from both repos, and local version exists.
950 // Since there was no updated metadata content from a remote/proxy, a metadata update on
951 // the local file never ran. Local only updates are performed via the metadata updater consumer.
952 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
953 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
954 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
958 public void testGetGroupMetadataProxiedOnLocalOnRemote()
961 // Project metadata that exist locally and exists on remote.
962 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
963 setupTestableManagedRepository( requestedResource );
965 // Configure Connector (usually done within archiva.xml configuration)
966 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
967 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
969 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
970 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
972 // One proxy setup, metadata fetched from remote, local exists.
973 assertFetchProjectOrGroup( requestedResource );
975 // Remote fetched. Local updated.
976 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
977 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
981 * Transfer the metadata file.
983 * @param requestedResource the requested resource
986 private void assertFetchProjectOrGroup( String requestedResource )
989 Path expectedFile = managedDefaultDir.resolve(requestedResource);
991 ProjectReference metadata = createProjectReference( requestedResource );
993 Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
994 managedDefaultRepository.toMetadataPath(
995 metadata ) ).getFile();
997 assertNotNull( "Should have downloaded a file.", downloadedFile );
998 assertNoTempFiles( expectedFile );
1001 private ProjectReference createProjectReference( String path )
1002 throws RepositoryMetadataException
1004 return metadataTools.toProjectReference( path );
1008 * Transfer the metadata file, not expected to succeed.
1010 * @param requestedResource the requested resource
1013 private void assertFetchProjectOrGroupFailed( String requestedResource )
1016 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1017 ProjectReference metadata = createProjectReference( requestedResource );
1019 Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
1020 managedDefaultRepository.toMetadataPath(
1021 metadata ) ).getFile();
1023 assertNull( downloadedFile );
1024 assertNoTempFiles( expectedFile );
1028 * Transfer the metadata file.
1030 * @param requestedResource the requested resource
1033 private void assertFetchVersioned( String requestedResource )
1036 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1038 VersionedReference metadata = createVersionedReference( requestedResource );
1040 Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
1041 managedDefaultRepository.toMetadataPath(
1042 metadata ) ).getFile();
1044 assertNotNull( "Should have downloaded a file.", downloadedFile );
1045 assertNoTempFiles( expectedFile );
1048 private VersionedReference createVersionedReference( String path )
1049 throws RepositoryMetadataException
1051 return metadataTools.toVersionedReference( path );
1055 * Transfer the metadata file, not expected to succeed.
1057 * @param requestedResource the requested resource
1060 private void assertFetchVersionedFailed( String requestedResource )
1063 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1064 VersionedReference metadata = createVersionedReference( requestedResource );
1066 Path downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
1067 managedDefaultRepository.toMetadataPath(
1068 metadata ) ).getFile();
1070 assertNull( downloadedFile );
1071 assertNoTempFiles( expectedFile );
1075 * Test for the existance of the requestedResource in the default managed repository.
1077 * @param requestedResource the requested resource
1080 private void assertResourceExists( String requestedResource )
1083 Path actualFile = managedDefaultDir.resolve(requestedResource);
1084 assertTrue( "Resource should exist: " + requestedResource, Files.exists(actualFile) );
1087 private void assertMetadataEquals( String expectedMetadataXml, Path actualFile )
1090 assertNotNull( "Actual File should not be null.", actualFile );
1092 assertTrue( "Actual file exists.", Files.exists(actualFile) );
1094 StringWriter actualContents = new StringWriter();
1095 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile.toFile() );
1096 RepositoryMetadataWriter.write( metadata, actualContents );
1098 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1099 if ( !detailedDiff.similar() )
1101 assertEquals( expectedMetadataXml, actualContents );
1104 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1108 * Ensures that the requested resource is not present in the managed repository.
1110 * @param requestedResource the requested resource
1113 private void assertNoMetadata( String requestedResource )
1116 Path expectedFile = managedDefaultDir.resolve(requestedResource);
1117 assertFalse( "metadata should not exist: " + expectedFile, Files.exists(expectedFile) );
1121 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1122 * managed repository.
1124 * @param proxiedRepoId the proxied repository id to validate with.
1125 * @param requestedResource the resource requested.
1127 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1129 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1131 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1132 assertFalse( "Repo specific metadata should not exist: " + actualFile, Files.exists(actualFile) );
1135 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1138 Path actualFile = managedDefaultDir.resolve(requestedResource);
1139 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1141 ProjectReference actualMetadata = createGroupReference( requestedResource );
1143 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1146 private ProjectReference createGroupReference( String requestedResource )
1147 throws RepositoryMetadataException
1149 ProjectReference projectReference = createProjectReference( requestedResource );
1150 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1151 projectReference.setArtifactId( null );
1152 return projectReference;
1155 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1156 String expectedPlugins[] )
1159 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1161 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1162 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1164 ProjectReference actualMetadata = createGroupReference( requestedResource );
1166 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1169 private void assertGroupMetadata( Path actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1172 // Build expected metadata XML
1173 StringWriter expectedMetadataXml = new StringWriter();
1174 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1175 m.setGroupId( actualMetadata.getGroupId() );
1177 for ( String pluginId : expectedPlugins )
1179 Plugin p = new Plugin();
1180 p.setPrefix( pluginId );
1181 p.setArtifactId( pluginId + "-maven-plugin" );
1182 p.setName( "The " + pluginId + " Plugin" );
1183 m.getPlugins().add( p );
1186 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1188 // Compare the file to the actual contents.
1189 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1193 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1194 * does it contain the specified list of expected versions?
1196 * @param requestedResource the requested resource
1199 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1200 String latestVersion, String releaseVersion )
1203 Path actualFile = managedDefaultDir.resolve(requestedResource);
1204 assertTrue( Files.exists(actualFile) );
1206 ProjectReference metadata = createProjectReference( requestedResource );
1208 // Build expected metadata XML
1209 StringWriter expectedMetadataXml = new StringWriter();
1210 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1211 m.setGroupId( metadata.getGroupId() );
1212 m.setArtifactId( metadata.getArtifactId() );
1213 m.setLatestVersion( latestVersion );
1214 m.setReleasedVersion( releaseVersion );
1216 if ( expectedVersions != null )
1218 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1221 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1223 // Compare the file to the actual contents.
1224 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1228 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1229 * does it contain the expected release maven-metadata.xml contents?
1231 * @param requestedResource the requested resource
1234 private void assertReleaseMetadataContents( String requestedResource )
1237 Path actualFile = managedDefaultDir.resolve(requestedResource);
1238 assertTrue( "Release Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1240 VersionedReference metadata = createVersionedReference( requestedResource );
1242 // Build expected metadata XML
1243 StringWriter expectedMetadataXml = new StringWriter();
1244 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1245 m.setGroupId( metadata.getGroupId() );
1246 m.setArtifactId( metadata.getArtifactId() );
1247 m.setVersion( metadata.getVersion() );
1248 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1250 // Compare the file to the actual contents.
1251 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1255 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1256 * does it contain the expected release maven-metadata.xml contents?
1258 * @param requestedResource the requested resource
1259 * @param expectedDate the date in "yyyyMMdd" format
1260 * @param expectedTime the time in "hhmmss" format
1261 * @param expectedBuildnumber the build number
1264 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1265 int expectedBuildnumber )
1268 Path actualFile = managedDefaultDir.resolve(requestedResource);
1269 assertTrue( "Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1271 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1273 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1277 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1278 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1280 * @param proxiedRepoId the repository id of the proxied repository.
1281 * @param requestedResource the requested resource
1282 * @param expectedDate the date in "yyyyMMdd" format
1283 * @param expectedTime the time in "hhmmss" format
1284 * @param expectedBuildnumber the build number
1287 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1288 String expectedDate, String expectedTime, int expectedBuildnumber )
1291 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1293 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1294 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, Files.exists(actualFile) );
1296 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1298 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1301 private void assertSnapshotMetadata( Path actualFile, VersionedReference actualMetadata, String expectedDate,
1302 String expectedTime, int expectedBuildnumber )
1303 throws RepositoryMetadataException, Exception
1305 // Build expected metadata XML
1306 StringWriter expectedMetadataXml = new StringWriter();
1307 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1308 m.setGroupId( actualMetadata.getGroupId() );
1309 m.setArtifactId( actualMetadata.getArtifactId() );
1310 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1312 m.setSnapshotVersion( new SnapshotVersion() );
1314 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1316 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1319 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1321 m.setLastUpdated( expectedDate + expectedTime );
1323 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1325 // Compare the file to the actual contents.
1326 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1330 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1331 * list of expected versions within.
1333 * @param proxiedRepoId
1334 * @param requestedResource
1335 * @param expectedProxyVersions
1337 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1338 String[] expectedProxyVersions )
1341 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1343 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1344 assertTrue( Files.exists(actualFile) );
1346 ProjectReference metadata = createProjectReference( requestedResource );
1348 // Build expected metadata XML
1349 StringWriter expectedMetadataXml = new StringWriter();
1350 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1351 m.setGroupId( metadata.getGroupId() );
1352 m.setArtifactId( metadata.getArtifactId() );
1354 if ( expectedProxyVersions != null )
1356 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1359 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1361 // Compare the file to the actual contents.
1362 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1366 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1367 * list of expected versions within.
1369 * @param proxiedRepoId
1370 * @param requestedResource
1372 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1375 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1377 Path actualFile = managedDefaultDir.resolve(proxiedFile);
1378 assertTrue( "Release metadata for repo should exist: " + actualFile, Files.exists(actualFile) );
1380 VersionedReference metadata = createVersionedReference( requestedResource );
1382 // Build expected metadata XML
1383 StringWriter expectedMetadataXml = new StringWriter();
1384 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1385 m.setGroupId( metadata.getGroupId() );
1386 m.setArtifactId( metadata.getArtifactId() );
1387 m.setVersion( metadata.getVersion() );
1388 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1390 // Compare the file to the actual contents.
1391 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1395 * Test for the non-existance of the requestedResource in the default managed repository.
1397 * @param requestedResource the requested resource
1400 private void assertResourceNotFound( String requestedResource )
1403 Path actualFile = managedDefaultDir.resolve(requestedResource);
1404 assertFalse( "Resource should not exist: " + requestedResource, Files.exists(actualFile) );