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.commons.lang.StringUtils;
23 import org.apache.archiva.common.utils.VersionUtil;
24 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
25 import org.apache.archiva.model.ArchivaRepositoryMetadata;
26 import org.apache.archiva.model.Plugin;
27 import org.apache.archiva.model.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.RepositoryMetadataReader;
37 import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
38 import org.apache.maven.wagon.TransferFailedException;
39 import org.custommonkey.xmlunit.DetailedDiff;
40 import org.custommonkey.xmlunit.Diff;
41 import org.junit.Before;
42 import org.junit.Test;
45 import java.io.StringWriter;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import javax.inject.Inject;
49 import javax.inject.Named;
51 import static org.junit.Assert.*;
54 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
55 * present in the repository.
57 * Test Case Naming is as follows.
60 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
64 * Which should leave the following matrix of test cases.
66 * Metadata | Proxied | Local | Remote
67 * ----------+----------+-------+---------
68 * Release | Not | Not | n/a (1)
69 * Release | Not | On | n/a (1)
70 * Release | | Not | Not
71 * Release | | Not | On
72 * Release | | Not | Multiple
73 * Release | | On | Not
75 * Release | | On | Multiple
76 * Snapshot | Not | Not | n/a (1)
77 * Snapshot | Not | On | n/a (1)
78 * Snapshot | | Not | Not
79 * Snapshot | | Not | On
80 * Snapshot | | Not | Multiple
81 * Snapshot | | On | Not
82 * Snapshot | | On | On
83 * Snapshot | | On | Multiple
84 * Project | Not | Not | n/a (1)
85 * Project | Not | On | n/a (1)
86 * Project | | Not | Not
87 * Project | | Not | On
88 * Project | | Not | Multiple
89 * Project | | On | Not
91 * Project | | On | Multiple
93 * (1) If it isn't proxied, no point in having a remote.
98 public class MetadataTransferTest
99 extends AbstractProxyTestCase
103 @Named(value = "metadataTools#mocked")
104 private MetadataTools metadataTools;
111 //metadataTools = applicationContext.getBean( MetadataTools.class );
115 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
118 // New project metadata that does not exist locally but exists on remote.
119 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
120 setupTestableManagedRepository( requestedResource );
122 // Configure Connector (usually done within archiva.xml configuration)
123 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
124 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
126 assertResourceNotFound( requestedResource );
127 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
129 File expectedFile = new File( managedDefaultDir, requestedResource );
131 ProjectReference metadata = createProjectReference( requestedResource );
133 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
134 managedDefaultRepository.toMetadataPath(
137 assertNull( "Should not have downloaded a file.", downloadedFile );
138 assertNoTempFiles( expectedFile );
141 // TODO: same test for other fetch* methods
143 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
146 // Project metadata that does not exist locally, but has multiple versions in remote repos
147 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
148 setupTestableManagedRepository( requestedResource );
150 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
152 // Configure Connector (usually done within archiva.xml configuration)
153 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
154 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
155 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
156 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
158 assertResourceNotFound( requestedResource );
159 assertNoRepoMetadata( "badproxied1", requestedResource );
160 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
162 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
163 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
164 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
165 wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
167 wagonMockControl.setMatcher( customWagonGetMatcher );
169 wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) );
171 wagonMockControl.replay();
173 assertFetchProjectOrGroup( requestedResource );
175 wagonMockControl.verify();
177 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
178 assertNoRepoMetadata( "badproxied1", requestedResource );
179 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
183 * Attempt to get the project metadata for non-existant artifact.
185 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
186 * to the requesting client.
189 public void testGetProjectMetadataNotProxiedNotLocal()
192 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
193 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
194 setupTestableManagedRepository( requestedResource );
196 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
198 assertResourceNotFound( requestedResource );
200 // No proxy setup, nothing fetched, failure expected.
201 assertFetchProjectOrGroupFailed( requestedResource );
203 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
204 assertResourceNotFound( requestedResource );
208 public void testGetProjectMetadataNotProxiedOnLocal()
212 // Project metadata that exists and has multiple versions
213 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
214 setupTestableManagedRepository( requestedResource );
216 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
218 assertResourceExists( requestedResource );
220 // No proxy setup, nothing fetched from remote, but local exists.
221 assertFetchProjectOrGroup( requestedResource );
223 // Nothing fetched. Should only contain contents of what is in the repository.
224 // A metadata update is not performed in this use case. Local metadata content is only
225 // updated via the metadata updater consumer.
226 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
230 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
233 // Project metadata that does not exist locally, but has multiple versions in remote repos
234 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
235 setupTestableManagedRepository( requestedResource );
237 // Configure Connector (usually done within archiva.xml configuration)
238 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
239 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
240 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
241 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
243 assertResourceNotFound( requestedResource );
244 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
245 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
247 // Two proxies setup, metadata fetched from both remotes.
248 assertFetchProjectOrGroup( requestedResource );
250 // Nothing fetched. Should only contain contents of what is in the repository.
251 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
252 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
253 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
257 public void testGetProjectMetadataProxiedNotLocalNotRemote()
260 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
261 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
262 setupTestableManagedRepository( requestedResource );
264 // Configure Connector (usually done within archiva.xml configuration)
265 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
266 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
267 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
268 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
270 assertResourceNotFound( requestedResource );
271 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
272 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
274 // Two proxies setup, nothing fetched from remotes, local does not exist.
275 assertFetchProjectOrGroupFailed( requestedResource );
277 // Nothing fetched. Nothing should exist.
278 assertResourceNotFound( requestedResource );
279 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
280 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
284 public void testGetProjectMetadataProxiedNotLocalOnRemote()
287 // New project metadata that does not exist locally but exists on remote.
288 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
289 setupTestableManagedRepository( requestedResource );
291 // Configure Connector (usually done within archiva.xml configuration)
292 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
293 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
295 assertResourceNotFound( requestedResource );
296 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
298 // One proxy setup, metadata fetched from remote, local does not exist.
299 assertFetchProjectOrGroup( requestedResource );
301 // Remote fetched. Local created/updated.
302 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
303 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
307 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
310 // Project metadata that exist locally, and has multiple versions in remote repos
311 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
312 setupTestableManagedRepository( requestedResource );
314 // Configure Connector (usually done within archiva.xml configuration)
315 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
316 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
317 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
318 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
320 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
321 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
322 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
324 // Two proxies setup, metadata fetched from both remotes.
325 assertFetchProjectOrGroup( requestedResource );
327 // metadata fetched from both repos, and merged with local version.
328 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
329 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
330 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
334 public void testGetProjectMetadataProxiedOnLocalNotRemote()
338 // Project metadata that exist locally, and does not exist in remote repos.
339 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
340 setupTestableManagedRepository( requestedResource );
343 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
344 // Configure Connector (usually done within archiva.xml configuration)
345 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
346 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
347 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
348 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
350 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
351 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
352 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
354 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
355 assertFetchProjectOrGroup( requestedResource );
357 // metadata not fetched from both repos, and local version exists.
358 // Since there was no updated metadata content from a remote/proxy, a metadata update on
359 // the local file never ran. Local only updates are performed via the metadata updater consumer.
360 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
361 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
362 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
366 public void testGetProjectMetadataProxiedOnLocalOnRemote()
369 // Project metadata that exist locally and exists on remote.
370 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
371 setupTestableManagedRepository( requestedResource );
373 // Configure Connector (usually done within archiva.xml configuration)
374 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
375 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
377 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
378 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
380 // One proxy setup, metadata fetched from remote, local exists.
381 assertFetchProjectOrGroup( requestedResource );
383 // Remote fetched. Local updated.
384 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
385 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
389 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
390 * repository has no proxied repositories set up.
392 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
393 * to the requesting client.
396 public void testGetReleaseMetadataNotProxiedNotLocal()
399 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
400 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
401 setupTestableManagedRepository( requestedResource );
403 assertNoMetadata( requestedResource );
405 // No proxy setup, nothing fetched, failure expected.
406 assertFetchVersionedFailed( requestedResource );
408 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
409 assertNoMetadata( requestedResource );
413 * A request for a maven-metadata.xml file that does exist locally, and the managed
414 * repository has no proxied repositories set up.
416 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
417 * information, and then returned to the client.
420 public void testGetReleaseMetadataNotProxiedOnLocal()
423 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
424 setupTestableManagedRepository( requestedResource );
426 assertResourceExists( requestedResource );
428 assertFetchVersioned( requestedResource );
430 assertReleaseMetadataContents( requestedResource );
434 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
435 * exists on multiple remote repositories.
437 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
438 * file location on the managed repository, a merge of the contents to the requested
439 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
440 * returned to the client.
443 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
446 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
447 setupTestableManagedRepository( requestedResource );
449 // Configure Connector (usually done within archiva.xml configuration)
450 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
451 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
452 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
453 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
455 assertResourceNotFound( requestedResource );
456 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
457 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
459 assertFetchVersioned( requestedResource );
461 assertReleaseMetadataContents( requestedResource );
462 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
463 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
467 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
468 * proxied repository.
470 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
471 * information, and then return to the client.
474 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
477 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
478 setupTestableManagedRepository( requestedResource );
480 // Configure Connector (usually done within archiva.xml configuration)
481 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
482 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
484 assertResourceNotFound( requestedResource );
486 assertFetchProjectOrGroupFailed( requestedResource );
488 assertResourceNotFound( requestedResource );
489 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
493 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
494 * exists on 1 remote repository.
496 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
497 * file location on the managed repository, a merge of the contents to the requested
498 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
499 * returned to the client.
502 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
505 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
506 setupTestableManagedRepository( requestedResource );
508 // Configure Connector (usually done within archiva.xml configuration)
509 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
510 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
512 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
514 assertFetchVersioned( requestedResource );
516 assertReleaseMetadataContents( requestedResource );
517 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
521 * A request for a maven-metadata.xml file that exists in the managed repository, but
522 * not on any remote repository.
524 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
525 * is not downloaded. There is no repository specific metadata file on the managed
526 * repository. The managed repository maven-metadata.xml is returned to the
530 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
533 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
534 setupTestableManagedRepository( requestedResource );
536 // Configure Connector (usually done within archiva.xml configuration)
537 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
538 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
540 assertReleaseMetadataContents( requestedResource );
542 assertFetchVersioned( requestedResource );
544 assertReleaseMetadataContents( requestedResource );
545 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
549 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
550 * remote repositories.
552 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
553 * and merged into the contents of the existing managed repository copy of
554 * the maven-metadata.xml file.
557 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
560 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
561 setupTestableManagedRepository( requestedResource );
563 // Configure Connector (usually done within archiva.xml configuration)
564 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
565 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
566 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
567 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
569 assertReleaseMetadataContents( requestedResource );
570 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
571 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
573 assertFetchVersioned( requestedResource );
575 assertReleaseMetadataContents( requestedResource );
576 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
577 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
581 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
584 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
585 * and merged into the contents of the existing managed repository copy of
586 * the maven-metadata.xml file.
589 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
592 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
593 setupTestableManagedRepository( requestedResource );
595 // Configure Connector (usually done within archiva.xml configuration)
596 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
597 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
599 assertReleaseMetadataContents( requestedResource );
600 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
602 assertFetchVersioned( requestedResource );
604 assertReleaseMetadataContents( requestedResource );
605 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
609 public void testGetSnapshotMetadataNotProxiedNotLocal()
612 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
613 String requestedResource =
614 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
615 setupTestableManagedRepository( requestedResource );
617 assertNoMetadata( requestedResource );
619 // No proxy setup, nothing fetched, no local file, failure expected.
620 assertFetchVersionedFailed( requestedResource );
622 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
623 assertNoMetadata( requestedResource );
627 public void testGetSnapshotMetadataNotProxiedOnLocal()
630 // The artifactId exists locally (but not on a remote repo)
631 String requestedResource =
632 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
633 setupTestableManagedRepository( requestedResource );
635 assertResourceExists( requestedResource );
637 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
638 assertFetchVersioned( requestedResource );
640 // Local metadata exists, should be updated to reflect the latest release.
641 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
645 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
648 String requestedResource =
649 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
650 setupTestableManagedRepository( requestedResource );
652 // Configure Connector (usually done within archiva.xml configuration)
653 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
654 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
655 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
656 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
658 assertResourceNotFound( requestedResource );
659 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
660 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
662 // Proxying 2 repos, both have content, local file updated.
663 assertFetchVersioned( requestedResource );
665 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
666 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
667 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
671 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
674 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
675 String requestedResource =
676 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
677 setupTestableManagedRepository( requestedResource );
679 // Configure Connector (usually done within archiva.xml configuration)
680 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
681 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
683 assertNoMetadata( requestedResource );
685 // One proxy setup, nothing fetched, no local file, failure expected.
686 assertFetchVersionedFailed( requestedResource );
688 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
689 assertNoMetadata( requestedResource );
690 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
694 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
697 // Artifact exists only in the proxied1 location.
698 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
699 setupTestableManagedRepository( requestedResource );
701 // Configure Connector (usually done within archiva.xml configuration)
702 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
703 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
705 assertResourceNotFound( requestedResource );
707 // One proxy setup, one metadata fetched, local file created/updated.
708 assertFetchVersioned( requestedResource );
710 // Local artifact Id should contain latest (which in this case is from proxied download)
711 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
712 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
716 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
719 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
720 setupTestableManagedRepository( requestedResource );
722 // Configure Connector (usually done within archiva.xml configuration)
723 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
724 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
725 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
726 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
728 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
729 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
730 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
732 // Proxying 2 repos, both have content, local file updated.
733 assertFetchVersioned( requestedResource );
735 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
736 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
737 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
741 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
744 // The artifactId exists locally (but not on a remote repo)
745 String requestedResource =
746 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
747 setupTestableManagedRepository( requestedResource );
749 // Configure Connector (usually done within archiva.xml configuration)
750 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
751 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
752 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
753 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
755 assertResourceExists( requestedResource );
756 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
757 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
759 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
760 assertFetchVersioned( requestedResource );
762 // Local metadata exists, repo metadatas should not exist, local file updated.
763 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
764 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
765 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
769 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
772 // The artifactId exists locally (but not on a remote repo)
773 String requestedResource =
774 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
775 setupTestableManagedRepository( requestedResource );
777 // Configure Connector (usually done within archiva.xml configuration)
778 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
779 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
781 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
782 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
784 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
785 assertFetchVersioned( requestedResource );
787 // Local metadata exists, repo metadata exists, local file updated.
788 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
789 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
793 public void testGetGroupMetadataNotProxiedNotLocal()
796 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
797 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
798 setupTestableManagedRepository( requestedResource );
800 assertResourceNotFound( requestedResource );
802 // No proxy setup, nothing fetched, failure expected.
803 assertFetchProjectOrGroupFailed( requestedResource );
805 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
806 assertResourceNotFound( requestedResource );
810 public void testGetGroupMetadataNotProxiedOnLocal()
813 // Project metadata that exists and has multiple versions
814 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
815 setupTestableManagedRepository( requestedResource );
817 assertResourceExists( requestedResource );
819 // No proxy setup, nothing fetched from remote, but local exists.
820 assertFetchProjectOrGroup( requestedResource );
822 // Nothing fetched. Should only contain contents of what is in the repository.
823 // A metadata update is not performed in this use case. Local metadata content is only
824 // updated via the metadata updater consumer.
825 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
829 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
832 // Project metadata that does not exist locally, but has multiple versions in remote repos
833 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
834 setupTestableManagedRepository( requestedResource );
836 // Configure Connector (usually done within archiva.xml configuration)
837 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
838 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
839 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
840 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
842 assertResourceNotFound( requestedResource );
843 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
844 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
846 // Two proxies setup, metadata fetched from both remotes.
847 assertFetchProjectOrGroup( requestedResource );
849 // Nothing fetched. Should only contain contents of what is in the repository.
850 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
851 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
852 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
856 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
859 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
860 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
861 setupTestableManagedRepository( requestedResource );
863 // Configure Connector (usually done within archiva.xml configuration)
864 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
865 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
866 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
867 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
869 assertResourceNotFound( requestedResource );
870 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
871 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
873 // Two proxies setup, nothing fetched from remotes, local does not exist.
874 assertFetchProjectOrGroupFailed( requestedResource );
876 // Nothing fetched. Nothing should exist.
877 assertResourceNotFound( requestedResource );
878 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
879 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
883 public void testGetGroupMetadataProxiedNotLocalOnRemote()
886 // New project metadata that does not exist locally but exists on remote.
887 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
888 setupTestableManagedRepository( requestedResource );
890 // Configure Connector (usually done within archiva.xml configuration)
891 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
892 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
894 assertResourceNotFound( requestedResource );
895 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
897 // One proxy setup, metadata fetched from remote, local does not exist.
898 assertFetchProjectOrGroup( requestedResource );
900 // Remote fetched. Local created/updated.
901 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
902 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
906 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
909 // Project metadata that exist locally, and has multiple versions in remote repos
910 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
911 setupTestableManagedRepository( requestedResource );
913 // Configure Connector (usually done within archiva.xml configuration)
914 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
915 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
916 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
917 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
919 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
920 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
921 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
923 // Two proxies setup, metadata fetched from both remotes.
924 assertFetchProjectOrGroup( requestedResource );
926 // metadata fetched from both repos, and merged with local version.
927 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
928 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
929 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
933 public void testGetGroupMetadataProxiedOnLocalNotRemote()
936 // Project metadata that exist locally, and does not exist in remote repos.
937 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
938 setupTestableManagedRepository( requestedResource );
940 // Configure Connector (usually done within archiva.xml configuration)
941 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
942 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
943 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
944 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
946 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
947 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
948 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
950 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
951 assertFetchProjectOrGroup( requestedResource );
953 // metadata not fetched from both repos, and local version exists.
954 // Since there was no updated metadata content from a remote/proxy, a metadata update on
955 // the local file never ran. Local only updates are performed via the metadata updater consumer.
956 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
957 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
958 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
962 public void testGetGroupMetadataProxiedOnLocalOnRemote()
965 // Project metadata that exist locally and exists on remote.
966 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
967 setupTestableManagedRepository( requestedResource );
969 // Configure Connector (usually done within archiva.xml configuration)
970 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
971 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
973 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
974 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
976 // One proxy setup, metadata fetched from remote, local exists.
977 assertFetchProjectOrGroup( requestedResource );
979 // Remote fetched. Local updated.
980 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
981 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
985 * Transfer the metadata file.
987 * @param requestedResource the requested resource
990 private void assertFetchProjectOrGroup( String requestedResource )
993 File expectedFile = new File( managedDefaultDir, requestedResource );
995 ProjectReference metadata = createProjectReference( requestedResource );
997 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
998 managedDefaultRepository.toMetadataPath(
1001 assertNotNull( "Should have downloaded a file.", downloadedFile );
1002 assertNoTempFiles( expectedFile );
1005 private ProjectReference createProjectReference( String path )
1006 throws RepositoryMetadataException
1008 return metadataTools.toProjectReference( path );
1012 * Transfer the metadata file, not expected to succeed.
1014 * @param requestedResource the requested resource
1017 private void assertFetchProjectOrGroupFailed( String requestedResource )
1020 File expectedFile = new File( managedDefaultDir, requestedResource );
1021 ProjectReference metadata = createProjectReference( requestedResource );
1023 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1024 managedDefaultRepository.toMetadataPath(
1027 assertNull( downloadedFile );
1028 assertNoTempFiles( expectedFile );
1032 * Transfer the metadata file.
1034 * @param requestedResource the requested resource
1037 private void assertFetchVersioned( String requestedResource )
1040 File expectedFile = new File( managedDefaultDir, requestedResource );
1042 VersionedReference metadata = createVersionedReference( requestedResource );
1044 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1045 managedDefaultRepository.toMetadataPath(
1048 assertNotNull( "Should have downloaded a file.", downloadedFile );
1049 assertNoTempFiles( expectedFile );
1052 private VersionedReference createVersionedReference( String path )
1053 throws RepositoryMetadataException
1055 return metadataTools.toVersionedReference( path );
1059 * Transfer the metadata file, not expected to succeed.
1061 * @param requestedResource the requested resource
1064 private void assertFetchVersionedFailed( String requestedResource )
1067 File expectedFile = new File( managedDefaultDir, requestedResource );
1068 VersionedReference metadata = createVersionedReference( requestedResource );
1070 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1071 managedDefaultRepository.toMetadataPath(
1074 assertNull( downloadedFile );
1075 assertNoTempFiles( expectedFile );
1079 * Test for the existance of the requestedResource in the default managed repository.
1081 * @param requestedResource the requested resource
1084 private void assertResourceExists( String requestedResource )
1087 File actualFile = new File( managedDefaultDir, requestedResource );
1088 assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() );
1091 private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
1094 assertNotNull( "Actual File should not be null.", actualFile );
1096 assertTrue( "Actual file exists.", actualFile.exists() );
1098 StringWriter actualContents = new StringWriter();
1099 ArchivaRepositoryMetadata metadata = RepositoryMetadataReader.read( actualFile );
1100 RepositoryMetadataWriter.write( metadata, actualContents );
1102 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1103 if ( !detailedDiff.similar() )
1105 assertEquals( expectedMetadataXml, actualContents );
1108 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1112 * Ensures that the requested resource is not present in the managed repository.
1114 * @param requestedResource the requested resource
1117 private void assertNoMetadata( String requestedResource )
1120 File expectedFile = new File( managedDefaultDir, requestedResource );
1121 assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() );
1125 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1126 * managed repository.
1128 * @param proxiedRepoId the proxied repository id to validate with.
1129 * @param requestedResource the resource requested.
1131 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1133 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1135 File actualFile = new File( managedDefaultDir, proxiedFile );
1136 assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
1139 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1142 File actualFile = new File( managedDefaultDir, requestedResource );
1143 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1145 ProjectReference actualMetadata = createGroupReference( requestedResource );
1147 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1150 private ProjectReference createGroupReference( String requestedResource )
1151 throws RepositoryMetadataException
1153 ProjectReference projectReference = createProjectReference( requestedResource );
1154 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1155 projectReference.setArtifactId( null );
1156 return projectReference;
1159 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1160 String expectedPlugins[] )
1163 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1165 File actualFile = new File( managedDefaultDir, proxiedFile );
1166 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
1168 ProjectReference actualMetadata = createGroupReference( requestedResource );
1170 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1173 private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1176 // Build expected metadata XML
1177 StringWriter expectedMetadataXml = new StringWriter();
1178 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1179 m.setGroupId( actualMetadata.getGroupId() );
1181 for ( String pluginId : expectedPlugins )
1183 Plugin p = new Plugin();
1184 p.setPrefix( pluginId );
1185 p.setArtifactId( pluginId + "-maven-plugin" );
1186 p.setName( "The " + pluginId + " Plugin" );
1187 m.getPlugins().add( p );
1190 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1192 // Compare the file to the actual contents.
1193 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1197 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1198 * does it contain the specified list of expected versions?
1200 * @param requestedResource the requested resource
1203 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1204 String latestVersion, String releaseVersion )
1207 File actualFile = new File( managedDefaultDir, requestedResource );
1208 assertTrue( actualFile.exists() );
1210 ProjectReference metadata = createProjectReference( requestedResource );
1212 // Build expected metadata XML
1213 StringWriter expectedMetadataXml = new StringWriter();
1214 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1215 m.setGroupId( metadata.getGroupId() );
1216 m.setArtifactId( metadata.getArtifactId() );
1217 m.setLatestVersion( latestVersion );
1218 m.setReleasedVersion( releaseVersion );
1220 if ( expectedVersions != null )
1222 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1225 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1227 // Compare the file to the actual contents.
1228 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1232 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1233 * does it contain the expected release maven-metadata.xml contents?
1235 * @param requestedResource the requested resource
1238 private void assertReleaseMetadataContents( String requestedResource )
1241 File actualFile = new File( managedDefaultDir, requestedResource );
1242 assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() );
1244 VersionedReference metadata = createVersionedReference( requestedResource );
1246 // Build expected metadata XML
1247 StringWriter expectedMetadataXml = new StringWriter();
1248 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1249 m.setGroupId( metadata.getGroupId() );
1250 m.setArtifactId( metadata.getArtifactId() );
1251 m.setVersion( metadata.getVersion() );
1252 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1254 // Compare the file to the actual contents.
1255 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1259 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1260 * does it contain the expected release maven-metadata.xml contents?
1262 * @param requestedResource the requested resource
1263 * @param expectedDate the date in "yyyyMMdd" format
1264 * @param expectedTime the time in "hhmmss" format
1265 * @param expectedBuildnumber the build number
1268 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1269 int expectedBuildnumber )
1272 File actualFile = new File( managedDefaultDir, requestedResource );
1273 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1275 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1277 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1281 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1282 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1284 * @param proxiedRepoId the repository id of the proxied repository.
1285 * @param requestedResource the requested resource
1286 * @param expectedDate the date in "yyyyMMdd" format
1287 * @param expectedTime the time in "hhmmss" format
1288 * @param expectedBuildnumber the build number
1291 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1292 String expectedDate, String expectedTime, int expectedBuildnumber )
1295 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1297 File actualFile = new File( managedDefaultDir, proxiedFile );
1298 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1300 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1302 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1305 private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate,
1306 String expectedTime, int expectedBuildnumber )
1307 throws RepositoryMetadataException, Exception
1309 // Build expected metadata XML
1310 StringWriter expectedMetadataXml = new StringWriter();
1311 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1312 m.setGroupId( actualMetadata.getGroupId() );
1313 m.setArtifactId( actualMetadata.getArtifactId() );
1314 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1316 m.setSnapshotVersion( new SnapshotVersion() );
1318 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1320 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1323 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1325 m.setLastUpdated( expectedDate + expectedTime );
1327 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1329 // Compare the file to the actual contents.
1330 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1334 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1335 * list of expected versions within.
1337 * @param proxiedRepoId
1338 * @param requestedResource
1339 * @param expectedProxyVersions
1341 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1342 String[] expectedProxyVersions )
1345 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1347 File actualFile = new File( managedDefaultDir, proxiedFile );
1348 assertTrue( actualFile.exists() );
1350 ProjectReference metadata = createProjectReference( requestedResource );
1352 // Build expected metadata XML
1353 StringWriter expectedMetadataXml = new StringWriter();
1354 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1355 m.setGroupId( metadata.getGroupId() );
1356 m.setArtifactId( metadata.getArtifactId() );
1358 if ( expectedProxyVersions != null )
1360 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1363 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1365 // Compare the file to the actual contents.
1366 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1370 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1371 * list of expected versions within.
1373 * @param proxiedRepoId
1374 * @param requestedResource
1376 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1379 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1381 File actualFile = new File( managedDefaultDir, proxiedFile );
1382 assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() );
1384 VersionedReference metadata = createVersionedReference( requestedResource );
1386 // Build expected metadata XML
1387 StringWriter expectedMetadataXml = new StringWriter();
1388 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1389 m.setGroupId( metadata.getGroupId() );
1390 m.setArtifactId( metadata.getArtifactId() );
1391 m.setVersion( metadata.getVersion() );
1392 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1394 // Compare the file to the actual contents.
1395 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1399 * Test for the non-existance of the requestedResource in the default managed repository.
1401 * @param requestedResource the requested resource
1404 private void assertResourceNotFound( String requestedResource )
1407 File actualFile = new File( managedDefaultDir, requestedResource );
1408 assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() );