1 package org.apache.maven.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.maven.archiva.common.utils.VersionUtil;
24 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
25 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
26 import org.apache.maven.archiva.model.Plugin;
27 import org.apache.maven.archiva.model.ProjectReference;
28 import org.apache.maven.archiva.model.SnapshotVersion;
29 import org.apache.maven.archiva.model.VersionedReference;
30 import org.apache.maven.archiva.policies.CachedFailuresPolicy;
31 import org.apache.maven.archiva.policies.ChecksumPolicy;
32 import org.apache.maven.archiva.policies.ReleasesPolicy;
33 import org.apache.maven.archiva.policies.SnapshotsPolicy;
34 import org.apache.maven.archiva.repository.metadata.MetadataTools;
35 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
36 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
37 import org.apache.maven.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;
44 import javax.inject.Inject;
45 import javax.inject.Named;
47 import java.io.StringWriter;
48 import java.util.ArrayList;
49 import java.util.Arrays;
52 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
53 * present in the repository.
55 * Test Case Naming is as follows.
58 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
62 * Which should leave the following matrix of test cases.
64 * Metadata | Proxied | Local | Remote
65 * ----------+----------+-------+---------
66 * Release | Not | Not | n/a (1)
67 * Release | Not | On | n/a (1)
68 * Release | | Not | Not
69 * Release | | Not | On
70 * Release | | Not | Multiple
71 * Release | | On | Not
73 * Release | | On | Multiple
74 * Snapshot | Not | Not | n/a (1)
75 * Snapshot | Not | On | n/a (1)
76 * Snapshot | | Not | Not
77 * Snapshot | | Not | On
78 * Snapshot | | Not | Multiple
79 * Snapshot | | On | Not
80 * Snapshot | | On | On
81 * Snapshot | | On | Multiple
82 * Project | Not | Not | n/a (1)
83 * Project | Not | On | n/a (1)
84 * Project | | Not | Not
85 * Project | | Not | On
86 * Project | | Not | Multiple
87 * Project | | On | Not
89 * Project | | On | Multiple
91 * (1) If it isn't proxied, no point in having a remote.
96 public class MetadataTransferTest
97 extends AbstractProxyTestCase
101 @Named(value = "metadataTools#mocked")
102 private MetadataTools metadataTools;
109 //metadataTools = applicationContext.getBean( MetadataTools.class );
113 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
116 // New project metadata that does not exist locally but exists on remote.
117 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
118 setupTestableManagedRepository( requestedResource );
120 // Configure Connector (usually done within archiva.xml configuration)
121 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
122 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
124 assertResourceNotFound( requestedResource );
125 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
127 File expectedFile = new File( managedDefaultDir, requestedResource );
129 ProjectReference metadata = createProjectReference( requestedResource );
131 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
132 managedDefaultRepository.toMetadataPath(
135 assertNull( "Should not have downloaded a file.", downloadedFile );
136 assertNoTempFiles( expectedFile );
139 // TODO: same test for other fetch* methods
141 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
144 // Project metadata that does not exist locally, but has multiple versions in remote repos
145 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
146 setupTestableManagedRepository( requestedResource );
148 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
150 // Configure Connector (usually done within archiva.xml configuration)
151 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
152 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
153 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
154 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
156 assertResourceNotFound( requestedResource );
157 assertNoRepoMetadata( "badproxied1", requestedResource );
158 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
160 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
161 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
162 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
163 wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
165 wagonMockControl.setMatcher( customWagonGetMatcher );
167 wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) );
169 wagonMockControl.replay();
171 assertFetchProjectOrGroup( requestedResource );
173 wagonMockControl.verify();
175 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
176 assertNoRepoMetadata( "badproxied1", requestedResource );
177 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
181 * Attempt to get the project metadata for non-existant artifact.
183 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
184 * to the requesting client.
187 public void testGetProjectMetadataNotProxiedNotLocal()
190 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
191 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
192 setupTestableManagedRepository( requestedResource );
194 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
196 assertResourceNotFound( requestedResource );
198 // No proxy setup, nothing fetched, failure expected.
199 assertFetchProjectOrGroupFailed( requestedResource );
201 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
202 assertResourceNotFound( requestedResource );
206 public void testGetProjectMetadataNotProxiedOnLocal()
210 // Project metadata that exists and has multiple versions
211 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
212 setupTestableManagedRepository( requestedResource );
214 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
216 assertResourceExists( requestedResource );
218 // No proxy setup, nothing fetched from remote, but local exists.
219 assertFetchProjectOrGroup( requestedResource );
221 // Nothing fetched. Should only contain contents of what is in the repository.
222 // A metadata update is not performed in this use case. Local metadata content is only
223 // updated via the metadata updater consumer.
224 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
228 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
231 // Project metadata that does not exist locally, but has multiple versions in remote repos
232 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
233 setupTestableManagedRepository( requestedResource );
235 // Configure Connector (usually done within archiva.xml configuration)
236 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
237 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
238 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
239 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
241 assertResourceNotFound( requestedResource );
242 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
243 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
245 // Two proxies setup, metadata fetched from both remotes.
246 assertFetchProjectOrGroup( requestedResource );
248 // Nothing fetched. Should only contain contents of what is in the repository.
249 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
250 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
251 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
255 public void testGetProjectMetadataProxiedNotLocalNotRemote()
258 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
259 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
260 setupTestableManagedRepository( requestedResource );
262 // Configure Connector (usually done within archiva.xml configuration)
263 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
264 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
265 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
266 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
268 assertResourceNotFound( requestedResource );
269 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
270 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
272 // Two proxies setup, nothing fetched from remotes, local does not exist.
273 assertFetchProjectOrGroupFailed( requestedResource );
275 // Nothing fetched. Nothing should exist.
276 assertResourceNotFound( requestedResource );
277 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
278 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
282 public void testGetProjectMetadataProxiedNotLocalOnRemote()
285 // New project metadata that does not exist locally but exists on remote.
286 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
287 setupTestableManagedRepository( requestedResource );
289 // Configure Connector (usually done within archiva.xml configuration)
290 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
291 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
293 assertResourceNotFound( requestedResource );
294 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
296 // One proxy setup, metadata fetched from remote, local does not exist.
297 assertFetchProjectOrGroup( requestedResource );
299 // Remote fetched. Local created/updated.
300 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
301 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
305 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
308 // Project metadata that exist locally, and has multiple versions in remote repos
309 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
310 setupTestableManagedRepository( requestedResource );
312 // Configure Connector (usually done within archiva.xml configuration)
313 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
314 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
315 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
316 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
318 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
319 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
320 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
322 // Two proxies setup, metadata fetched from both remotes.
323 assertFetchProjectOrGroup( requestedResource );
325 // metadata fetched from both repos, and merged with local version.
326 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
327 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
328 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
332 public void testGetProjectMetadataProxiedOnLocalNotRemote()
336 // Project metadata that exist locally, and does not exist in remote repos.
337 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
338 setupTestableManagedRepository( requestedResource );
341 config.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>( ) );
342 // Configure Connector (usually done within archiva.xml configuration)
343 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
344 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
345 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
346 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
348 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
349 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
350 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
352 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
353 assertFetchProjectOrGroup( requestedResource );
355 // metadata not fetched from both repos, and local version exists.
356 // Since there was no updated metadata content from a remote/proxy, a metadata update on
357 // the local file never ran. Local only updates are performed via the metadata updater consumer.
358 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
359 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
360 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
364 public void testGetProjectMetadataProxiedOnLocalOnRemote()
367 // Project metadata that exist locally and exists on remote.
368 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
369 setupTestableManagedRepository( requestedResource );
371 // Configure Connector (usually done within archiva.xml configuration)
372 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
373 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
375 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
376 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
378 // One proxy setup, metadata fetched from remote, local exists.
379 assertFetchProjectOrGroup( requestedResource );
381 // Remote fetched. Local updated.
382 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
383 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
387 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
388 * repository has no proxied repositories set up.
390 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
391 * to the requesting client.
394 public void testGetReleaseMetadataNotProxiedNotLocal()
397 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
398 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
399 setupTestableManagedRepository( requestedResource );
401 assertNoMetadata( requestedResource );
403 // No proxy setup, nothing fetched, failure expected.
404 assertFetchVersionedFailed( requestedResource );
406 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
407 assertNoMetadata( requestedResource );
411 * A request for a maven-metadata.xml file that does exist locally, and the managed
412 * repository has no proxied repositories set up.
414 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
415 * information, and then returned to the client.
418 public void testGetReleaseMetadataNotProxiedOnLocal()
421 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
422 setupTestableManagedRepository( requestedResource );
424 assertResourceExists( requestedResource );
426 assertFetchVersioned( requestedResource );
428 assertReleaseMetadataContents( requestedResource );
432 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
433 * exists on multiple remote repositories.
435 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
436 * file location on the managed repository, a merge of the contents to the requested
437 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
438 * returned to the client.
441 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
444 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
445 setupTestableManagedRepository( requestedResource );
447 // Configure Connector (usually done within archiva.xml configuration)
448 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
449 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
450 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
451 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
453 assertResourceNotFound( requestedResource );
454 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
455 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
457 assertFetchVersioned( requestedResource );
459 assertReleaseMetadataContents( requestedResource );
460 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
461 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
465 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
466 * proxied repository.
468 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
469 * information, and then return to the client.
472 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
475 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
476 setupTestableManagedRepository( requestedResource );
478 // Configure Connector (usually done within archiva.xml configuration)
479 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
480 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
482 assertResourceNotFound( requestedResource );
484 assertFetchProjectOrGroupFailed( requestedResource );
486 assertResourceNotFound( requestedResource );
487 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
491 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
492 * exists on 1 remote repository.
494 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
495 * file location on the managed repository, a merge of the contents to the requested
496 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
497 * returned to the client.
500 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
503 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
504 setupTestableManagedRepository( requestedResource );
506 // Configure Connector (usually done within archiva.xml configuration)
507 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
508 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
510 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
512 assertFetchVersioned( requestedResource );
514 assertReleaseMetadataContents( requestedResource );
515 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
519 * A request for a maven-metadata.xml file that exists in the managed repository, but
520 * not on any remote repository.
522 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
523 * is not downloaded. There is no repository specific metadata file on the managed
524 * repository. The managed repository maven-metadata.xml is returned to the
528 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
531 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
532 setupTestableManagedRepository( requestedResource );
534 // Configure Connector (usually done within archiva.xml configuration)
535 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
536 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
538 assertReleaseMetadataContents( requestedResource );
540 assertFetchVersioned( requestedResource );
542 assertReleaseMetadataContents( requestedResource );
543 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
547 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
548 * remote repositories.
550 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
551 * and merged into the contents of the existing managed repository copy of
552 * the maven-metadata.xml file.
555 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
558 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
559 setupTestableManagedRepository( requestedResource );
561 // Configure Connector (usually done within archiva.xml configuration)
562 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
563 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
564 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
565 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
567 assertReleaseMetadataContents( requestedResource );
568 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
569 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
571 assertFetchVersioned( requestedResource );
573 assertReleaseMetadataContents( requestedResource );
574 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
575 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
579 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
582 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
583 * and merged into the contents of the existing managed repository copy of
584 * the maven-metadata.xml file.
587 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
590 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
591 setupTestableManagedRepository( requestedResource );
593 // Configure Connector (usually done within archiva.xml configuration)
594 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
595 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
597 assertReleaseMetadataContents( requestedResource );
598 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
600 assertFetchVersioned( requestedResource );
602 assertReleaseMetadataContents( requestedResource );
603 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
607 public void testGetSnapshotMetadataNotProxiedNotLocal()
610 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
611 String requestedResource =
612 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
613 setupTestableManagedRepository( requestedResource );
615 assertNoMetadata( requestedResource );
617 // No proxy setup, nothing fetched, no local file, failure expected.
618 assertFetchVersionedFailed( requestedResource );
620 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
621 assertNoMetadata( requestedResource );
625 public void testGetSnapshotMetadataNotProxiedOnLocal()
628 // The artifactId exists locally (but not on a remote repo)
629 String requestedResource =
630 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
631 setupTestableManagedRepository( requestedResource );
633 assertResourceExists( requestedResource );
635 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
636 assertFetchVersioned( requestedResource );
638 // Local metadata exists, should be updated to reflect the latest release.
639 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
643 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
646 String requestedResource =
647 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
648 setupTestableManagedRepository( requestedResource );
650 // Configure Connector (usually done within archiva.xml configuration)
651 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
652 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
653 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
654 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
656 assertResourceNotFound( requestedResource );
657 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
658 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
660 // Proxying 2 repos, both have content, local file updated.
661 assertFetchVersioned( requestedResource );
663 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
664 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
665 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
669 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
672 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
673 String requestedResource =
674 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
675 setupTestableManagedRepository( requestedResource );
677 // Configure Connector (usually done within archiva.xml configuration)
678 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
679 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
681 assertNoMetadata( requestedResource );
683 // One proxy setup, nothing fetched, no local file, failure expected.
684 assertFetchVersionedFailed( requestedResource );
686 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
687 assertNoMetadata( requestedResource );
688 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
692 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
695 // Artifact exists only in the proxied1 location.
696 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
697 setupTestableManagedRepository( requestedResource );
699 // Configure Connector (usually done within archiva.xml configuration)
700 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
701 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
703 assertResourceNotFound( requestedResource );
705 // One proxy setup, one metadata fetched, local file created/updated.
706 assertFetchVersioned( requestedResource );
708 // Local artifact Id should contain latest (which in this case is from proxied download)
709 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
710 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
714 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
717 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
718 setupTestableManagedRepository( requestedResource );
720 // Configure Connector (usually done within archiva.xml configuration)
721 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
722 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
723 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
724 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
726 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
727 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
728 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
730 // Proxying 2 repos, both have content, local file updated.
731 assertFetchVersioned( requestedResource );
733 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
734 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
735 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
739 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
742 // The artifactId exists locally (but not on a remote repo)
743 String requestedResource =
744 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
745 setupTestableManagedRepository( requestedResource );
747 // Configure Connector (usually done within archiva.xml configuration)
748 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
749 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
750 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
751 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
753 assertResourceExists( requestedResource );
754 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
755 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
757 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
758 assertFetchVersioned( requestedResource );
760 // Local metadata exists, repo metadatas should not exist, local file updated.
761 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
762 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
763 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
767 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
770 // The artifactId exists locally (but not on a remote repo)
771 String requestedResource =
772 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
773 setupTestableManagedRepository( requestedResource );
775 // Configure Connector (usually done within archiva.xml configuration)
776 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
777 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
779 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
780 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
782 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
783 assertFetchVersioned( requestedResource );
785 // Local metadata exists, repo metadata exists, local file updated.
786 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
787 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
791 public void testGetGroupMetadataNotProxiedNotLocal()
794 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
795 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
796 setupTestableManagedRepository( requestedResource );
798 assertResourceNotFound( requestedResource );
800 // No proxy setup, nothing fetched, failure expected.
801 assertFetchProjectOrGroupFailed( requestedResource );
803 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
804 assertResourceNotFound( requestedResource );
808 public void testGetGroupMetadataNotProxiedOnLocal()
811 // Project metadata that exists and has multiple versions
812 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
813 setupTestableManagedRepository( requestedResource );
815 assertResourceExists( requestedResource );
817 // No proxy setup, nothing fetched from remote, but local exists.
818 assertFetchProjectOrGroup( requestedResource );
820 // Nothing fetched. Should only contain contents of what is in the repository.
821 // A metadata update is not performed in this use case. Local metadata content is only
822 // updated via the metadata updater consumer.
823 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
827 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
830 // Project metadata that does not exist locally, but has multiple versions in remote repos
831 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
832 setupTestableManagedRepository( requestedResource );
834 // Configure Connector (usually done within archiva.xml configuration)
835 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
836 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
837 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
838 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
840 assertResourceNotFound( requestedResource );
841 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
842 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
844 // Two proxies setup, metadata fetched from both remotes.
845 assertFetchProjectOrGroup( requestedResource );
847 // Nothing fetched. Should only contain contents of what is in the repository.
848 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
849 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
850 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
854 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
857 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
858 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
859 setupTestableManagedRepository( requestedResource );
861 // Configure Connector (usually done within archiva.xml configuration)
862 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
863 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
864 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
865 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
867 assertResourceNotFound( requestedResource );
868 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
869 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
871 // Two proxies setup, nothing fetched from remotes, local does not exist.
872 assertFetchProjectOrGroupFailed( requestedResource );
874 // Nothing fetched. Nothing should exist.
875 assertResourceNotFound( requestedResource );
876 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
877 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
881 public void testGetGroupMetadataProxiedNotLocalOnRemote()
884 // New project metadata that does not exist locally but exists on remote.
885 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
886 setupTestableManagedRepository( requestedResource );
888 // Configure Connector (usually done within archiva.xml configuration)
889 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
890 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
892 assertResourceNotFound( requestedResource );
893 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
895 // One proxy setup, metadata fetched from remote, local does not exist.
896 assertFetchProjectOrGroup( requestedResource );
898 // Remote fetched. Local created/updated.
899 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
900 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
904 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
907 // Project metadata that exist locally, and has multiple versions in remote repos
908 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
909 setupTestableManagedRepository( requestedResource );
911 // Configure Connector (usually done within archiva.xml configuration)
912 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
913 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
914 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
915 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
917 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
918 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
919 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
921 // Two proxies setup, metadata fetched from both remotes.
922 assertFetchProjectOrGroup( requestedResource );
924 // metadata fetched from both repos, and merged with local version.
925 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
926 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
927 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
931 public void testGetGroupMetadataProxiedOnLocalNotRemote()
934 // Project metadata that exist locally, and does not exist in remote repos.
935 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
936 setupTestableManagedRepository( requestedResource );
938 // Configure Connector (usually done within archiva.xml configuration)
939 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
940 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
941 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
942 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
944 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
945 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
946 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
948 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
949 assertFetchProjectOrGroup( requestedResource );
951 // metadata not fetched from both repos, and local version exists.
952 // Since there was no updated metadata content from a remote/proxy, a metadata update on
953 // the local file never ran. Local only updates are performed via the metadata updater consumer.
954 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
955 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
956 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
960 public void testGetGroupMetadataProxiedOnLocalOnRemote()
963 // Project metadata that exist locally and exists on remote.
964 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
965 setupTestableManagedRepository( requestedResource );
967 // Configure Connector (usually done within archiva.xml configuration)
968 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
969 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
971 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
972 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
974 // One proxy setup, metadata fetched from remote, local exists.
975 assertFetchProjectOrGroup( requestedResource );
977 // Remote fetched. Local updated.
978 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
979 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
983 * Transfer the metadata file.
985 * @param requestedResource the requested resource
988 private void assertFetchProjectOrGroup( String requestedResource )
991 File expectedFile = new File( managedDefaultDir, requestedResource );
993 ProjectReference metadata = createProjectReference( requestedResource );
995 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
996 managedDefaultRepository.toMetadataPath(
999 assertNotNull( "Should have downloaded a file.", downloadedFile );
1000 assertNoTempFiles( expectedFile );
1003 private ProjectReference createProjectReference( String path )
1004 throws RepositoryMetadataException
1006 return metadataTools.toProjectReference( path );
1010 * Transfer the metadata file, not expected to succeed.
1012 * @param requestedResource the requested resource
1015 private void assertFetchProjectOrGroupFailed( String requestedResource )
1018 File expectedFile = new File( managedDefaultDir, requestedResource );
1019 ProjectReference metadata = createProjectReference( requestedResource );
1021 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1022 managedDefaultRepository.toMetadataPath(
1025 assertNull( downloadedFile );
1026 assertNoTempFiles( expectedFile );
1030 * Transfer the metadata file.
1032 * @param requestedResource the requested resource
1035 private void assertFetchVersioned( String requestedResource )
1038 File expectedFile = new File( managedDefaultDir, requestedResource );
1040 VersionedReference metadata = createVersionedReference( requestedResource );
1042 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1043 managedDefaultRepository.toMetadataPath(
1046 assertNotNull( "Should have downloaded a file.", downloadedFile );
1047 assertNoTempFiles( expectedFile );
1050 private VersionedReference createVersionedReference( String path )
1051 throws RepositoryMetadataException
1053 return metadataTools.toVersionedReference( path );
1057 * Transfer the metadata file, not expected to succeed.
1059 * @param requestedResource the requested resource
1062 private void assertFetchVersionedFailed( String requestedResource )
1065 File expectedFile = new File( managedDefaultDir, requestedResource );
1066 VersionedReference metadata = createVersionedReference( requestedResource );
1068 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1069 managedDefaultRepository.toMetadataPath(
1072 assertNull( downloadedFile );
1073 assertNoTempFiles( expectedFile );
1077 * Test for the existance of the requestedResource in the default managed repository.
1079 * @param requestedResource the requested resource
1082 private void assertResourceExists( String requestedResource )
1085 File actualFile = new File( managedDefaultDir, requestedResource );
1086 assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() );
1089 private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
1092 assertNotNull( "Actual File should not be null.", actualFile );
1094 assertTrue( "Actual file exists.", actualFile.exists() );
1096 StringWriter actualContents = new StringWriter();
1097 ArchivaRepositoryMetadata metadata = RepositoryMetadataReader.read( actualFile );
1098 RepositoryMetadataWriter.write( metadata, actualContents );
1100 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1101 if ( !detailedDiff.similar() )
1103 assertEquals( expectedMetadataXml, actualContents );
1106 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1110 * Ensures that the requested resource is not present in the managed repository.
1112 * @param requestedResource the requested resource
1115 private void assertNoMetadata( String requestedResource )
1118 File expectedFile = new File( managedDefaultDir, requestedResource );
1119 assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() );
1123 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1124 * managed repository.
1126 * @param proxiedRepoId the proxied repository id to validate with.
1127 * @param requestedResource the resource requested.
1129 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1131 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1133 File actualFile = new File( managedDefaultDir, proxiedFile );
1134 assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
1137 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1140 File actualFile = new File( managedDefaultDir, requestedResource );
1141 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1143 ProjectReference actualMetadata = createGroupReference( requestedResource );
1145 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1148 private ProjectReference createGroupReference( String requestedResource )
1149 throws RepositoryMetadataException
1151 ProjectReference projectReference = createProjectReference( requestedResource );
1152 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1153 projectReference.setArtifactId( null );
1154 return projectReference;
1157 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1158 String expectedPlugins[] )
1161 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1163 File actualFile = new File( managedDefaultDir, proxiedFile );
1164 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
1166 ProjectReference actualMetadata = createGroupReference( requestedResource );
1168 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1171 private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1174 // Build expected metadata XML
1175 StringWriter expectedMetadataXml = new StringWriter();
1176 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1177 m.setGroupId( actualMetadata.getGroupId() );
1179 for ( String pluginId : expectedPlugins )
1181 Plugin p = new Plugin();
1182 p.setPrefix( pluginId );
1183 p.setArtifactId( pluginId + "-maven-plugin" );
1184 p.setName( "The " + pluginId + " Plugin" );
1185 m.getPlugins().add( p );
1188 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1190 // Compare the file to the actual contents.
1191 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1195 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1196 * does it contain the specified list of expected versions?
1198 * @param requestedResource the requested resource
1201 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1202 String latestVersion, String releaseVersion )
1205 File actualFile = new File( managedDefaultDir, requestedResource );
1206 assertTrue( actualFile.exists() );
1208 ProjectReference metadata = createProjectReference( requestedResource );
1210 // Build expected metadata XML
1211 StringWriter expectedMetadataXml = new StringWriter();
1212 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1213 m.setGroupId( metadata.getGroupId() );
1214 m.setArtifactId( metadata.getArtifactId() );
1215 m.setLatestVersion( latestVersion );
1216 m.setReleasedVersion( releaseVersion );
1218 if ( expectedVersions != null )
1220 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1223 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1225 // Compare the file to the actual contents.
1226 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1230 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1231 * does it contain the expected release maven-metadata.xml contents?
1233 * @param requestedResource the requested resource
1236 private void assertReleaseMetadataContents( String requestedResource )
1239 File actualFile = new File( managedDefaultDir, requestedResource );
1240 assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() );
1242 VersionedReference metadata = createVersionedReference( requestedResource );
1244 // Build expected metadata XML
1245 StringWriter expectedMetadataXml = new StringWriter();
1246 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1247 m.setGroupId( metadata.getGroupId() );
1248 m.setArtifactId( metadata.getArtifactId() );
1249 m.setVersion( metadata.getVersion() );
1250 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1252 // Compare the file to the actual contents.
1253 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1257 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1258 * does it contain the expected release maven-metadata.xml contents?
1260 * @param requestedResource the requested resource
1261 * @param expectedDate the date in "yyyyMMdd" format
1262 * @param expectedTime the time in "hhmmss" format
1263 * @param expectedBuildnumber the build number
1266 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1267 int expectedBuildnumber )
1270 File actualFile = new File( managedDefaultDir, requestedResource );
1271 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1273 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1275 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1279 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1280 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1282 * @param proxiedRepoId the repository id of the proxied repository.
1283 * @param requestedResource the requested resource
1284 * @param expectedDate the date in "yyyyMMdd" format
1285 * @param expectedTime the time in "hhmmss" format
1286 * @param expectedBuildnumber the build number
1289 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1290 String expectedDate, String expectedTime, int expectedBuildnumber )
1293 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1295 File actualFile = new File( managedDefaultDir, proxiedFile );
1296 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1298 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1300 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1303 private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate,
1304 String expectedTime, int expectedBuildnumber )
1305 throws RepositoryMetadataException, Exception
1307 // Build expected metadata XML
1308 StringWriter expectedMetadataXml = new StringWriter();
1309 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1310 m.setGroupId( actualMetadata.getGroupId() );
1311 m.setArtifactId( actualMetadata.getArtifactId() );
1312 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1314 m.setSnapshotVersion( new SnapshotVersion() );
1316 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1318 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1321 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1323 m.setLastUpdated( expectedDate + expectedTime );
1325 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1327 // Compare the file to the actual contents.
1328 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1332 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1333 * list of expected versions within.
1335 * @param proxiedRepoId
1336 * @param requestedResource
1337 * @param expectedProxyVersions
1339 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1340 String[] expectedProxyVersions )
1343 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1345 File actualFile = new File( managedDefaultDir, proxiedFile );
1346 assertTrue( actualFile.exists() );
1348 ProjectReference metadata = createProjectReference( requestedResource );
1350 // Build expected metadata XML
1351 StringWriter expectedMetadataXml = new StringWriter();
1352 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1353 m.setGroupId( metadata.getGroupId() );
1354 m.setArtifactId( metadata.getArtifactId() );
1356 if ( expectedProxyVersions != null )
1358 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1361 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1363 // Compare the file to the actual contents.
1364 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1368 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1369 * list of expected versions within.
1371 * @param proxiedRepoId
1372 * @param requestedResource
1374 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1377 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1379 File actualFile = new File( managedDefaultDir, proxiedFile );
1380 assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() );
1382 VersionedReference metadata = createVersionedReference( requestedResource );
1384 // Build expected metadata XML
1385 StringWriter expectedMetadataXml = new StringWriter();
1386 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1387 m.setGroupId( metadata.getGroupId() );
1388 m.setArtifactId( metadata.getArtifactId() );
1389 m.setVersion( metadata.getVersion() );
1390 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1392 // Compare the file to the actual contents.
1393 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1397 * Test for the non-existance of the requestedResource in the default managed repository.
1399 * @param requestedResource the requested resource
1402 private void assertResourceNotFound( String requestedResource )
1405 File actualFile = new File( managedDefaultDir, requestedResource );
1406 assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() );