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.repository.metadata.MetadataTools;
35 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
36 import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
37 import org.apache.commons.lang.StringUtils;
38 import org.apache.maven.wagon.TransferFailedException;
39 import org.custommonkey.xmlunit.DetailedDiff;
40 import org.custommonkey.xmlunit.Diff;
41 import org.junit.Test;
43 import javax.inject.Inject;
44 import javax.inject.Named;
46 import java.io.StringWriter;
47 import java.util.ArrayList;
48 import java.util.Arrays;
50 import static org.junit.Assert.*;
53 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
54 * present in the repository.
56 * Test Case Naming is as follows.
59 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
63 * Which should leave the following matrix of test cases.
65 * Metadata | Proxied | Local | Remote
66 * ----------+----------+-------+---------
67 * Release | Not | Not | n/a (1)
68 * Release | Not | On | n/a (1)
69 * Release | | Not | Not
70 * Release | | Not | On
71 * Release | | Not | Multiple
72 * Release | | On | Not
74 * Release | | On | Multiple
75 * Snapshot | Not | Not | n/a (1)
76 * Snapshot | Not | On | n/a (1)
77 * Snapshot | | Not | Not
78 * Snapshot | | Not | On
79 * Snapshot | | Not | Multiple
80 * Snapshot | | On | Not
81 * Snapshot | | On | On
82 * Snapshot | | On | Multiple
83 * Project | Not | Not | n/a (1)
84 * Project | Not | On | n/a (1)
85 * Project | | Not | Not
86 * Project | | Not | On
87 * Project | | Not | Multiple
88 * Project | | On | Not
90 * Project | | On | Multiple
92 * (1) If it isn't proxied, no point in having a remote.
97 public class MetadataTransferTest
98 extends AbstractProxyTestCase
102 @Named(value = "metadataTools#mocked")
103 private MetadataTools metadataTools;
107 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
110 // New project metadata that does not exist locally but exists on remote.
111 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
112 setupTestableManagedRepository( requestedResource );
114 // Configure Connector (usually done within archiva.xml configuration)
115 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
116 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
118 assertResourceNotFound( requestedResource );
119 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
121 File expectedFile = new File( managedDefaultDir, requestedResource );
123 ProjectReference metadata = createProjectReference( requestedResource );
125 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
126 managedDefaultRepository.toMetadataPath(
129 assertNull( "Should not have downloaded a file.", downloadedFile );
130 assertNoTempFiles( expectedFile );
133 // TODO: same test for other fetch* methods
135 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
138 // Project metadata that does not exist locally, but has multiple versions in remote repos
139 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
140 setupTestableManagedRepository( requestedResource );
142 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
144 // Configure Connector (usually done within archiva.xml configuration)
145 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
146 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
147 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
148 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
150 assertResourceNotFound( requestedResource );
151 assertNoRepoMetadata( "badproxied1", requestedResource );
152 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
154 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
155 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
156 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
157 wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
159 wagonMockControl.setMatcher( customWagonGetMatcher );
161 wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) );
163 wagonMockControl.replay();
165 assertFetchProjectOrGroup( requestedResource );
167 wagonMockControl.verify();
169 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
170 assertNoRepoMetadata( "badproxied1", requestedResource );
171 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
175 * Attempt to get the project metadata for non-existant artifact.
177 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
178 * to the requesting client.
181 public void testGetProjectMetadataNotProxiedNotLocal()
184 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
185 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
186 setupTestableManagedRepository( requestedResource );
188 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
190 assertResourceNotFound( requestedResource );
192 // No proxy setup, nothing fetched, failure expected.
193 assertFetchProjectOrGroupFailed( requestedResource );
195 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
196 assertResourceNotFound( requestedResource );
200 public void testGetProjectMetadataNotProxiedOnLocal()
204 // Project metadata that exists and has multiple versions
205 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
206 setupTestableManagedRepository( requestedResource );
208 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
210 assertResourceExists( requestedResource );
212 // No proxy setup, nothing fetched from remote, but local exists.
213 assertFetchProjectOrGroup( requestedResource );
215 // Nothing fetched. Should only contain contents of what is in the repository.
216 // A metadata update is not performed in this use case. Local metadata content is only
217 // updated via the metadata updater consumer.
218 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
222 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
225 // Project metadata that does not exist locally, but has multiple versions in remote repos
226 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
227 setupTestableManagedRepository( requestedResource );
229 // Configure Connector (usually done within archiva.xml configuration)
230 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
231 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
232 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
233 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
235 assertResourceNotFound( requestedResource );
236 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
237 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
239 // Two proxies setup, metadata fetched from both remotes.
240 assertFetchProjectOrGroup( requestedResource );
242 // Nothing fetched. Should only contain contents of what is in the repository.
243 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
244 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
245 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
249 public void testGetProjectMetadataProxiedNotLocalNotRemote()
252 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
253 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
254 setupTestableManagedRepository( requestedResource );
256 // Configure Connector (usually done within archiva.xml configuration)
257 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
258 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
259 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
260 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
262 assertResourceNotFound( requestedResource );
263 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
264 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
266 // Two proxies setup, nothing fetched from remotes, local does not exist.
267 assertFetchProjectOrGroupFailed( requestedResource );
269 // Nothing fetched. Nothing should exist.
270 assertResourceNotFound( requestedResource );
271 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
272 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
276 public void testGetProjectMetadataProxiedNotLocalOnRemote()
279 // New project metadata that does not exist locally but exists on remote.
280 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
281 setupTestableManagedRepository( requestedResource );
283 // Configure Connector (usually done within archiva.xml configuration)
284 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
285 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
287 assertResourceNotFound( requestedResource );
288 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
290 // One proxy setup, metadata fetched from remote, local does not exist.
291 assertFetchProjectOrGroup( requestedResource );
293 // Remote fetched. Local created/updated.
294 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
295 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
299 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
302 // Project metadata that exist locally, and has multiple versions in remote repos
303 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
304 setupTestableManagedRepository( requestedResource );
306 // Configure Connector (usually done within archiva.xml configuration)
307 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
308 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
309 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
310 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
312 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
313 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
314 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
316 // Two proxies setup, metadata fetched from both remotes.
317 assertFetchProjectOrGroup( requestedResource );
319 // metadata fetched from both repos, and merged with local version.
320 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
321 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
322 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
326 public void testGetProjectMetadataProxiedOnLocalNotRemote()
330 // Project metadata that exist locally, and does not exist in remote repos.
331 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
332 setupTestableManagedRepository( requestedResource );
335 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
336 // Configure Connector (usually done within archiva.xml configuration)
337 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
338 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
339 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
340 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
342 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
343 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
344 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
346 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
347 assertFetchProjectOrGroup( requestedResource );
349 // metadata not fetched from both repos, and local version exists.
350 // Since there was no updated metadata content from a remote/proxy, a metadata update on
351 // the local file never ran. Local only updates are performed via the metadata updater consumer.
352 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
353 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
354 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
358 public void testGetProjectMetadataProxiedOnLocalOnRemote()
361 // Project metadata that exist locally and exists on remote.
362 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
363 setupTestableManagedRepository( requestedResource );
365 // Configure Connector (usually done within archiva.xml configuration)
366 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
367 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
369 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
370 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
372 // One proxy setup, metadata fetched from remote, local exists.
373 assertFetchProjectOrGroup( requestedResource );
375 // Remote fetched. Local updated.
376 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
377 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
381 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
382 * repository has no proxied repositories set up.
384 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
385 * to the requesting client.
388 public void testGetReleaseMetadataNotProxiedNotLocal()
391 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
392 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
393 setupTestableManagedRepository( requestedResource );
395 assertNoMetadata( requestedResource );
397 // No proxy setup, nothing fetched, failure expected.
398 assertFetchVersionedFailed( requestedResource );
400 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
401 assertNoMetadata( requestedResource );
405 * A request for a maven-metadata.xml file that does exist locally, and the managed
406 * repository has no proxied repositories set up.
408 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
409 * information, and then returned to the client.
412 public void testGetReleaseMetadataNotProxiedOnLocal()
415 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
416 setupTestableManagedRepository( requestedResource );
418 assertResourceExists( requestedResource );
420 assertFetchVersioned( requestedResource );
422 assertReleaseMetadataContents( requestedResource );
426 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
427 * exists on multiple remote repositories.
429 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
430 * file location on the managed repository, a merge of the contents to the requested
431 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
432 * returned to the client.
435 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
438 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
439 setupTestableManagedRepository( requestedResource );
441 // Configure Connector (usually done within archiva.xml configuration)
442 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
443 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
444 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
445 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
447 assertResourceNotFound( requestedResource );
448 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
449 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
451 assertFetchVersioned( requestedResource );
453 assertReleaseMetadataContents( requestedResource );
454 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
455 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
459 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
460 * proxied repository.
462 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
463 * information, and then return to the client.
466 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
469 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
470 setupTestableManagedRepository( requestedResource );
472 // Configure Connector (usually done within archiva.xml configuration)
473 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
474 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
476 assertResourceNotFound( requestedResource );
478 assertFetchProjectOrGroupFailed( requestedResource );
480 assertResourceNotFound( requestedResource );
481 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
485 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
486 * exists on 1 remote repository.
488 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
489 * file location on the managed repository, a merge of the contents to the requested
490 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
491 * returned to the client.
494 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
497 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
498 setupTestableManagedRepository( requestedResource );
500 // Configure Connector (usually done within archiva.xml configuration)
501 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
502 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
504 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
506 assertFetchVersioned( requestedResource );
508 assertReleaseMetadataContents( requestedResource );
509 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
513 * A request for a maven-metadata.xml file that exists in the managed repository, but
514 * not on any remote repository.
516 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
517 * is not downloaded. There is no repository specific metadata file on the managed
518 * repository. The managed repository maven-metadata.xml is returned to the
522 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
525 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
526 setupTestableManagedRepository( requestedResource );
528 // Configure Connector (usually done within archiva.xml configuration)
529 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
530 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
532 assertReleaseMetadataContents( requestedResource );
534 assertFetchVersioned( requestedResource );
536 assertReleaseMetadataContents( requestedResource );
537 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
541 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
542 * remote repositories.
544 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
545 * and merged into the contents of the existing managed repository copy of
546 * the maven-metadata.xml file.
549 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
552 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
553 setupTestableManagedRepository( requestedResource );
555 // Configure Connector (usually done within archiva.xml configuration)
556 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
557 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
558 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
559 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
561 assertReleaseMetadataContents( requestedResource );
562 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
563 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
565 assertFetchVersioned( requestedResource );
567 assertReleaseMetadataContents( requestedResource );
568 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
569 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
573 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
576 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
577 * and merged into the contents of the existing managed repository copy of
578 * the maven-metadata.xml file.
581 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
584 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
585 setupTestableManagedRepository( requestedResource );
587 // Configure Connector (usually done within archiva.xml configuration)
588 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
589 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
591 assertReleaseMetadataContents( requestedResource );
592 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
594 assertFetchVersioned( requestedResource );
596 assertReleaseMetadataContents( requestedResource );
597 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
601 public void testGetSnapshotMetadataNotProxiedNotLocal()
604 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
605 String requestedResource =
606 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
607 setupTestableManagedRepository( requestedResource );
609 assertNoMetadata( requestedResource );
611 // No proxy setup, nothing fetched, no local file, failure expected.
612 assertFetchVersionedFailed( requestedResource );
614 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
615 assertNoMetadata( requestedResource );
619 public void testGetSnapshotMetadataNotProxiedOnLocal()
622 // The artifactId exists locally (but not on a remote repo)
623 String requestedResource =
624 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
625 setupTestableManagedRepository( requestedResource );
627 assertResourceExists( requestedResource );
629 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
630 assertFetchVersioned( requestedResource );
632 // Local metadata exists, should be updated to reflect the latest release.
633 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
637 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
640 String requestedResource =
641 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
642 setupTestableManagedRepository( requestedResource );
644 // Configure Connector (usually done within archiva.xml configuration)
645 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
646 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
647 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
648 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
650 assertResourceNotFound( requestedResource );
651 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
652 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
654 // Proxying 2 repos, both have content, local file updated.
655 assertFetchVersioned( requestedResource );
657 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
658 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
659 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
663 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
666 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
667 String requestedResource =
668 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
669 setupTestableManagedRepository( requestedResource );
671 // Configure Connector (usually done within archiva.xml configuration)
672 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
673 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
675 assertNoMetadata( requestedResource );
677 // One proxy setup, nothing fetched, no local file, failure expected.
678 assertFetchVersionedFailed( requestedResource );
680 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
681 assertNoMetadata( requestedResource );
682 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
686 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
689 // Artifact exists only in the proxied1 location.
690 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
691 setupTestableManagedRepository( requestedResource );
693 // Configure Connector (usually done within archiva.xml configuration)
694 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
695 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
697 assertResourceNotFound( requestedResource );
699 // One proxy setup, one metadata fetched, local file created/updated.
700 assertFetchVersioned( requestedResource );
702 // Local artifact Id should contain latest (which in this case is from proxied download)
703 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
704 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
708 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
711 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
712 setupTestableManagedRepository( requestedResource );
714 // Configure Connector (usually done within archiva.xml configuration)
715 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
716 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
717 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
718 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
720 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
721 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
722 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
724 // Proxying 2 repos, both have content, local file updated.
725 assertFetchVersioned( requestedResource );
727 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
728 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
729 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
733 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
736 // The artifactId exists locally (but not on a remote repo)
737 String requestedResource =
738 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
739 setupTestableManagedRepository( requestedResource );
741 // Configure Connector (usually done within archiva.xml configuration)
742 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
743 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
744 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
745 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
747 assertResourceExists( requestedResource );
748 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
749 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
751 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
752 assertFetchVersioned( requestedResource );
754 // Local metadata exists, repo metadatas should not exist, local file updated.
755 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
756 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
757 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
761 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
764 // The artifactId exists locally (but not on a remote repo)
765 String requestedResource =
766 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
767 setupTestableManagedRepository( requestedResource );
769 // Configure Connector (usually done within archiva.xml configuration)
770 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
771 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
773 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
774 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
776 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
777 assertFetchVersioned( requestedResource );
779 // Local metadata exists, repo metadata exists, local file updated.
780 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
781 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
785 public void testGetGroupMetadataNotProxiedNotLocal()
788 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
789 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
790 setupTestableManagedRepository( requestedResource );
792 assertResourceNotFound( requestedResource );
794 // No proxy setup, nothing fetched, failure expected.
795 assertFetchProjectOrGroupFailed( requestedResource );
797 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
798 assertResourceNotFound( requestedResource );
802 public void testGetGroupMetadataNotProxiedOnLocal()
805 // Project metadata that exists and has multiple versions
806 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
807 setupTestableManagedRepository( requestedResource );
809 assertResourceExists( requestedResource );
811 // No proxy setup, nothing fetched from remote, but local exists.
812 assertFetchProjectOrGroup( requestedResource );
814 // Nothing fetched. Should only contain contents of what is in the repository.
815 // A metadata update is not performed in this use case. Local metadata content is only
816 // updated via the metadata updater consumer.
817 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
821 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
824 // Project metadata that does not exist locally, but has multiple versions in remote repos
825 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
826 setupTestableManagedRepository( requestedResource );
828 // Configure Connector (usually done within archiva.xml configuration)
829 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
830 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
831 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
832 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
834 assertResourceNotFound( requestedResource );
835 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
836 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
838 // Two proxies setup, metadata fetched from both remotes.
839 assertFetchProjectOrGroup( requestedResource );
841 // Nothing fetched. Should only contain contents of what is in the repository.
842 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
843 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
844 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
848 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
851 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
852 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
853 setupTestableManagedRepository( requestedResource );
855 // Configure Connector (usually done within archiva.xml configuration)
856 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
857 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
858 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
859 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
861 assertResourceNotFound( requestedResource );
862 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
863 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
865 // Two proxies setup, nothing fetched from remotes, local does not exist.
866 assertFetchProjectOrGroupFailed( requestedResource );
868 // Nothing fetched. Nothing should exist.
869 assertResourceNotFound( requestedResource );
870 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
871 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
875 public void testGetGroupMetadataProxiedNotLocalOnRemote()
878 // New project metadata that does not exist locally but exists on remote.
879 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
880 setupTestableManagedRepository( requestedResource );
882 // Configure Connector (usually done within archiva.xml configuration)
883 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
884 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
886 assertResourceNotFound( requestedResource );
887 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
889 // One proxy setup, metadata fetched from remote, local does not exist.
890 assertFetchProjectOrGroup( requestedResource );
892 // Remote fetched. Local created/updated.
893 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
894 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
898 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
901 // Project metadata that exist locally, and has multiple versions in remote repos
902 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
903 setupTestableManagedRepository( requestedResource );
905 // Configure Connector (usually done within archiva.xml configuration)
906 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
907 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
908 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
909 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
911 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
912 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
913 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
915 // Two proxies setup, metadata fetched from both remotes.
916 assertFetchProjectOrGroup( requestedResource );
918 // metadata fetched from both repos, and merged with local version.
919 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
920 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
921 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
925 public void testGetGroupMetadataProxiedOnLocalNotRemote()
928 // Project metadata that exist locally, and does not exist in remote repos.
929 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
930 setupTestableManagedRepository( requestedResource );
932 // Configure Connector (usually done within archiva.xml configuration)
933 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
934 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
935 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
936 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
938 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
939 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
940 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
942 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
943 assertFetchProjectOrGroup( requestedResource );
945 // metadata not fetched from both repos, and local version exists.
946 // Since there was no updated metadata content from a remote/proxy, a metadata update on
947 // the local file never ran. Local only updates are performed via the metadata updater consumer.
948 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
949 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
950 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
954 public void testGetGroupMetadataProxiedOnLocalOnRemote()
957 // Project metadata that exist locally and exists on remote.
958 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
959 setupTestableManagedRepository( requestedResource );
961 // Configure Connector (usually done within archiva.xml configuration)
962 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
963 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
965 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
966 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
968 // One proxy setup, metadata fetched from remote, local exists.
969 assertFetchProjectOrGroup( requestedResource );
971 // Remote fetched. Local updated.
972 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
973 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
977 * Transfer the metadata file.
979 * @param requestedResource the requested resource
982 private void assertFetchProjectOrGroup( String requestedResource )
985 File expectedFile = new File( managedDefaultDir, requestedResource );
987 ProjectReference metadata = createProjectReference( requestedResource );
989 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
990 managedDefaultRepository.toMetadataPath(
993 assertNotNull( "Should have downloaded a file.", downloadedFile );
994 assertNoTempFiles( expectedFile );
997 private ProjectReference createProjectReference( String path )
998 throws RepositoryMetadataException
1000 return metadataTools.toProjectReference( path );
1004 * Transfer the metadata file, not expected to succeed.
1006 * @param requestedResource the requested resource
1009 private void assertFetchProjectOrGroupFailed( String requestedResource )
1012 File expectedFile = new File( managedDefaultDir, requestedResource );
1013 ProjectReference metadata = createProjectReference( requestedResource );
1015 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1016 managedDefaultRepository.toMetadataPath(
1019 assertNull( downloadedFile );
1020 assertNoTempFiles( expectedFile );
1024 * Transfer the metadata file.
1026 * @param requestedResource the requested resource
1029 private void assertFetchVersioned( String requestedResource )
1032 File expectedFile = new File( managedDefaultDir, requestedResource );
1034 VersionedReference metadata = createVersionedReference( requestedResource );
1036 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1037 managedDefaultRepository.toMetadataPath(
1040 assertNotNull( "Should have downloaded a file.", downloadedFile );
1041 assertNoTempFiles( expectedFile );
1044 private VersionedReference createVersionedReference( String path )
1045 throws RepositoryMetadataException
1047 return metadataTools.toVersionedReference( path );
1051 * Transfer the metadata file, not expected to succeed.
1053 * @param requestedResource the requested resource
1056 private void assertFetchVersionedFailed( String requestedResource )
1059 File expectedFile = new File( managedDefaultDir, requestedResource );
1060 VersionedReference metadata = createVersionedReference( requestedResource );
1062 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1063 managedDefaultRepository.toMetadataPath(
1066 assertNull( downloadedFile );
1067 assertNoTempFiles( expectedFile );
1071 * Test for the existance of the requestedResource in the default managed repository.
1073 * @param requestedResource the requested resource
1076 private void assertResourceExists( String requestedResource )
1079 File actualFile = new File( managedDefaultDir, requestedResource );
1080 assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() );
1083 private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
1086 assertNotNull( "Actual File should not be null.", actualFile );
1088 assertTrue( "Actual file exists.", actualFile.exists() );
1090 StringWriter actualContents = new StringWriter();
1091 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile );
1092 RepositoryMetadataWriter.write( metadata, actualContents );
1094 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1095 if ( !detailedDiff.similar() )
1097 assertEquals( expectedMetadataXml, actualContents );
1100 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1104 * Ensures that the requested resource is not present in the managed repository.
1106 * @param requestedResource the requested resource
1109 private void assertNoMetadata( String requestedResource )
1112 File expectedFile = new File( managedDefaultDir, requestedResource );
1113 assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() );
1117 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1118 * managed repository.
1120 * @param proxiedRepoId the proxied repository id to validate with.
1121 * @param requestedResource the resource requested.
1123 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1125 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1127 File actualFile = new File( managedDefaultDir, proxiedFile );
1128 assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
1131 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1134 File actualFile = new File( managedDefaultDir, requestedResource );
1135 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1137 ProjectReference actualMetadata = createGroupReference( requestedResource );
1139 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1142 private ProjectReference createGroupReference( String requestedResource )
1143 throws RepositoryMetadataException
1145 ProjectReference projectReference = createProjectReference( requestedResource );
1146 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1147 projectReference.setArtifactId( null );
1148 return projectReference;
1151 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1152 String expectedPlugins[] )
1155 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1157 File actualFile = new File( managedDefaultDir, proxiedFile );
1158 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
1160 ProjectReference actualMetadata = createGroupReference( requestedResource );
1162 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1165 private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1168 // Build expected metadata XML
1169 StringWriter expectedMetadataXml = new StringWriter();
1170 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1171 m.setGroupId( actualMetadata.getGroupId() );
1173 for ( String pluginId : expectedPlugins )
1175 Plugin p = new Plugin();
1176 p.setPrefix( pluginId );
1177 p.setArtifactId( pluginId + "-maven-plugin" );
1178 p.setName( "The " + pluginId + " Plugin" );
1179 m.getPlugins().add( p );
1182 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1184 // Compare the file to the actual contents.
1185 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1189 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1190 * does it contain the specified list of expected versions?
1192 * @param requestedResource the requested resource
1195 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1196 String latestVersion, String releaseVersion )
1199 File actualFile = new File( managedDefaultDir, requestedResource );
1200 assertTrue( actualFile.exists() );
1202 ProjectReference metadata = createProjectReference( requestedResource );
1204 // Build expected metadata XML
1205 StringWriter expectedMetadataXml = new StringWriter();
1206 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1207 m.setGroupId( metadata.getGroupId() );
1208 m.setArtifactId( metadata.getArtifactId() );
1209 m.setLatestVersion( latestVersion );
1210 m.setReleasedVersion( releaseVersion );
1212 if ( expectedVersions != null )
1214 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1217 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1219 // Compare the file to the actual contents.
1220 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1224 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1225 * does it contain the expected release maven-metadata.xml contents?
1227 * @param requestedResource the requested resource
1230 private void assertReleaseMetadataContents( String requestedResource )
1233 File actualFile = new File( managedDefaultDir, requestedResource );
1234 assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() );
1236 VersionedReference metadata = createVersionedReference( requestedResource );
1238 // Build expected metadata XML
1239 StringWriter expectedMetadataXml = new StringWriter();
1240 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1241 m.setGroupId( metadata.getGroupId() );
1242 m.setArtifactId( metadata.getArtifactId() );
1243 m.setVersion( metadata.getVersion() );
1244 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1246 // Compare the file to the actual contents.
1247 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1251 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1252 * does it contain the expected release maven-metadata.xml contents?
1254 * @param requestedResource the requested resource
1255 * @param expectedDate the date in "yyyyMMdd" format
1256 * @param expectedTime the time in "hhmmss" format
1257 * @param expectedBuildnumber the build number
1260 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1261 int expectedBuildnumber )
1264 File actualFile = new File( managedDefaultDir, requestedResource );
1265 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1267 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1269 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1273 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1274 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1276 * @param proxiedRepoId the repository id of the proxied repository.
1277 * @param requestedResource the requested resource
1278 * @param expectedDate the date in "yyyyMMdd" format
1279 * @param expectedTime the time in "hhmmss" format
1280 * @param expectedBuildnumber the build number
1283 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1284 String expectedDate, String expectedTime, int expectedBuildnumber )
1287 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1289 File actualFile = new File( managedDefaultDir, proxiedFile );
1290 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1292 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1294 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1297 private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate,
1298 String expectedTime, int expectedBuildnumber )
1299 throws RepositoryMetadataException, Exception
1301 // Build expected metadata XML
1302 StringWriter expectedMetadataXml = new StringWriter();
1303 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1304 m.setGroupId( actualMetadata.getGroupId() );
1305 m.setArtifactId( actualMetadata.getArtifactId() );
1306 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1308 m.setSnapshotVersion( new SnapshotVersion() );
1310 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1312 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1315 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1317 m.setLastUpdated( expectedDate + expectedTime );
1319 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1321 // Compare the file to the actual contents.
1322 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1326 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1327 * list of expected versions within.
1329 * @param proxiedRepoId
1330 * @param requestedResource
1331 * @param expectedProxyVersions
1333 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1334 String[] expectedProxyVersions )
1337 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1339 File actualFile = new File( managedDefaultDir, proxiedFile );
1340 assertTrue( actualFile.exists() );
1342 ProjectReference metadata = createProjectReference( requestedResource );
1344 // Build expected metadata XML
1345 StringWriter expectedMetadataXml = new StringWriter();
1346 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1347 m.setGroupId( metadata.getGroupId() );
1348 m.setArtifactId( metadata.getArtifactId() );
1350 if ( expectedProxyVersions != null )
1352 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1355 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1357 // Compare the file to the actual contents.
1358 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1362 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1363 * list of expected versions within.
1365 * @param proxiedRepoId
1366 * @param requestedResource
1368 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1371 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1373 File actualFile = new File( managedDefaultDir, proxiedFile );
1374 assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() );
1376 VersionedReference metadata = createVersionedReference( requestedResource );
1378 // Build expected metadata XML
1379 StringWriter expectedMetadataXml = new StringWriter();
1380 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1381 m.setGroupId( metadata.getGroupId() );
1382 m.setArtifactId( metadata.getArtifactId() );
1383 m.setVersion( metadata.getVersion() );
1384 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1386 // Compare the file to the actual contents.
1387 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1391 * Test for the non-existance of the requestedResource in the default managed repository.
1393 * @param requestedResource the requested resource
1396 private void assertResourceNotFound( String requestedResource )
1399 File actualFile = new File( managedDefaultDir, requestedResource );
1400 assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() );