1 package org.apache.archiva.proxy;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.common.utils.VersionUtil;
23 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
24 import org.apache.archiva.maven2.metadata.MavenMetadataReader;
25 import org.apache.archiva.model.ArchivaRepositoryMetadata;
26 import org.apache.archiva.model.Plugin;
27 import org.apache.archiva.model.ProjectReference;
28 import org.apache.archiva.model.SnapshotVersion;
29 import org.apache.archiva.model.VersionedReference;
30 import org.apache.archiva.policies.CachedFailuresPolicy;
31 import org.apache.archiva.policies.ChecksumPolicy;
32 import org.apache.archiva.policies.ReleasesPolicy;
33 import org.apache.archiva.policies.SnapshotsPolicy;
34 import org.apache.archiva.repository.metadata.MetadataTools;
35 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
36 import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
37 import org.apache.commons.lang.StringUtils;
38 import org.apache.maven.wagon.ResourceDoesNotExistException;
39 import org.apache.maven.wagon.TransferFailedException;
40 import org.custommonkey.xmlunit.DetailedDiff;
41 import org.custommonkey.xmlunit.Diff;
42 import org.easymock.EasyMock;
43 import org.junit.Test;
45 import javax.inject.Inject;
46 import javax.inject.Named;
48 import java.io.StringWriter;
49 import java.util.ArrayList;
50 import java.util.Arrays;
52 import static org.junit.Assert.*;
55 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
56 * present in the repository.
58 * Test Case Naming is as follows.
61 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
65 * Which should leave the following matrix of test cases.
67 * Metadata | Proxied | Local | Remote
68 * ----------+----------+-------+---------
69 * Release | Not | Not | n/a (1)
70 * Release | Not | On | n/a (1)
71 * Release | | Not | Not
72 * Release | | Not | On
73 * Release | | Not | Multiple
74 * Release | | On | Not
76 * Release | | On | Multiple
77 * Snapshot | Not | Not | n/a (1)
78 * Snapshot | Not | On | n/a (1)
79 * Snapshot | | Not | Not
80 * Snapshot | | Not | On
81 * Snapshot | | Not | Multiple
82 * Snapshot | | On | Not
83 * Snapshot | | On | On
84 * Snapshot | | On | Multiple
85 * Project | Not | Not | n/a (1)
86 * Project | Not | On | n/a (1)
87 * Project | | Not | Not
88 * Project | | Not | On
89 * Project | | Not | Multiple
90 * Project | | On | Not
92 * Project | | On | Multiple
94 * (1) If it isn't proxied, no point in having a remote.
99 public class MetadataTransferTest
100 extends AbstractProxyTestCase
104 @Named(value = "metadataTools#mocked")
105 private MetadataTools metadataTools;
109 public void testGetProjectMetadataProxiedNotLocalOnRemoteConnectoDisabled()
112 // New project metadata that does not exist locally but exists on remote.
113 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
114 setupTestableManagedRepository( requestedResource );
116 // Configure Connector (usually done within archiva.xml configuration)
117 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
118 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
120 assertResourceNotFound( requestedResource );
121 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
123 File expectedFile = new File( managedDefaultDir, requestedResource );
125 ProjectReference metadata = createProjectReference( requestedResource );
127 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
128 managedDefaultRepository.toMetadataPath(
131 assertNull( "Should not have downloaded a file.", downloadedFile );
132 assertNoTempFiles( expectedFile );
135 // TODO: same test for other fetch* methods
137 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
140 // Project metadata that does not exist locally, but has multiple versions in remote repos
141 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
142 setupTestableManagedRepository( requestedResource );
144 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
146 // Configure Connector (usually done within archiva.xml configuration)
147 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
148 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
149 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
150 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
152 assertResourceNotFound( requestedResource );
153 assertNoRepoMetadata( "badproxied1", requestedResource );
154 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
156 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
157 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
158 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
160 wagonMock.get( EasyMock.eq( requestedResource ), EasyMock.anyObject( File.class ));
161 EasyMock.expectLastCall().andThrow( new TransferFailedException( "can't connect" ) );
164 wagonMockControl.replay();
166 assertFetchProjectOrGroup( requestedResource );
168 wagonMockControl.verify();
170 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.1" }, "1.0.1", "1.0.1" );
171 assertNoRepoMetadata( "badproxied1", requestedResource );
172 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
176 * Attempt to get the project metadata for non-existant artifact.
178 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
179 * to the requesting client.
182 public void testGetProjectMetadataNotProxiedNotLocal()
185 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
186 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
187 setupTestableManagedRepository( requestedResource );
189 config.getConfiguration().setProxyConnectors( new ArrayList<>( ) );
191 assertResourceNotFound( requestedResource );
193 // No proxy setup, nothing fetched, failure expected.
194 assertFetchProjectOrGroupFailed( requestedResource );
196 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
197 assertResourceNotFound( requestedResource );
201 public void testGetProjectMetadataNotProxiedOnLocal()
205 // Project metadata that exists and has multiple versions
206 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
207 setupTestableManagedRepository( requestedResource );
209 config.getConfiguration().setProxyConnectors( new ArrayList<>( ) );
211 assertResourceExists( requestedResource );
213 // No proxy setup, nothing fetched from remote, but local exists.
214 assertFetchProjectOrGroup( requestedResource );
216 // Nothing fetched. Should only contain contents of what is in the repository.
217 // A metadata update is not performed in this use case. Local metadata content is only
218 // updated via the metadata updater consumer.
219 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
223 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
226 // Project metadata that does not exist locally, but has multiple versions in remote repos
227 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
228 setupTestableManagedRepository( requestedResource );
230 // Configure Connector (usually done within archiva.xml configuration)
231 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
232 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
233 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
234 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
236 assertResourceNotFound( requestedResource );
237 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
238 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
240 // Two proxies setup, metadata fetched from both remotes.
241 assertFetchProjectOrGroup( requestedResource );
243 // Nothing fetched. Should only contain contents of what is in the repository.
244 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
245 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0" } );
246 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0.1" } );
250 public void testGetProjectMetadataProxiedNotLocalNotRemote()
253 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
254 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
255 setupTestableManagedRepository( requestedResource );
257 // Configure Connector (usually done within archiva.xml configuration)
258 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
259 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
260 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
261 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
263 assertResourceNotFound( requestedResource );
264 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
265 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
267 // Two proxies setup, nothing fetched from remotes, local does not exist.
268 assertFetchProjectOrGroupFailed( requestedResource );
270 // Nothing fetched. Nothing should exist.
271 assertResourceNotFound( requestedResource );
272 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
273 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
277 public void testGetProjectMetadataProxiedNotLocalOnRemote()
280 // New project metadata that does not exist locally but exists on remote.
281 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
282 setupTestableManagedRepository( requestedResource );
284 // Configure Connector (usually done within archiva.xml configuration)
285 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
286 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
288 assertResourceNotFound( requestedResource );
289 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
291 // One proxy setup, metadata fetched from remote, local does not exist.
292 assertFetchProjectOrGroup( requestedResource );
294 // Remote fetched. Local created/updated.
295 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.5" }, "1.0.5", "1.0.5" );
296 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.5" } );
300 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
303 // Project metadata that exist locally, and has multiple versions in remote repos
304 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
305 setupTestableManagedRepository( requestedResource );
307 // Configure Connector (usually done within archiva.xml configuration)
308 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
309 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
310 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
311 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
313 assertProjectMetadataContents( requestedResource, new String[]{ "1.0" }, null, null );
314 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
315 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
317 // Two proxies setup, metadata fetched from both remotes.
318 assertFetchProjectOrGroup( requestedResource );
320 // metadata fetched from both repos, and merged with local version.
321 assertProjectMetadataContents( requestedResource, new String[]{ "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
322 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0", "2.0" } );
323 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[]{ "1.0", "1.0.1" } );
327 public void testGetProjectMetadataProxiedOnLocalNotRemote()
331 // Project metadata that exist locally, and does not exist in remote repos.
332 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
333 setupTestableManagedRepository( requestedResource );
336 config.getConfiguration().setProxyConnectors( new ArrayList<>( ) );
337 // Configure Connector (usually done within archiva.xml configuration)
338 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
339 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
340 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
341 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
343 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
344 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
345 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
347 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
348 assertFetchProjectOrGroup( requestedResource );
350 // metadata not fetched from both repos, and local version exists.
351 // Since there was no updated metadata content from a remote/proxy, a metadata update on
352 // the local file never ran. Local only updates are performed via the metadata updater consumer.
353 assertProjectMetadataContents( requestedResource, new String[]{ "1.0-beta-2" }, null, null );
354 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
355 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
359 public void testGetProjectMetadataProxiedOnLocalOnRemote()
362 // Project metadata that exist locally and exists on remote.
363 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
364 setupTestableManagedRepository( requestedResource );
366 // Configure Connector (usually done within archiva.xml configuration)
367 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
368 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
370 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22" }, null, null );
371 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
373 // One proxy setup, metadata fetched from remote, local exists.
374 assertFetchProjectOrGroup( requestedResource );
376 // Remote fetched. Local updated.
377 assertProjectMetadataContents( requestedResource, new String[]{ "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
378 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[]{ "1.0.22", "2.0" } );
382 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
383 * repository has no proxied repositories set up.
385 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
386 * to the requesting client.
389 public void testGetReleaseMetadataNotProxiedNotLocal()
392 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
393 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
394 setupTestableManagedRepository( requestedResource );
396 assertNoMetadata( requestedResource );
398 // No proxy setup, nothing fetched, failure expected.
399 assertFetchVersionedFailed( requestedResource );
401 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
402 assertNoMetadata( requestedResource );
406 * A request for a maven-metadata.xml file that does exist locally, and the managed
407 * repository has no proxied repositories set up.
409 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
410 * information, and then returned to the client.
413 public void testGetReleaseMetadataNotProxiedOnLocal()
416 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
417 setupTestableManagedRepository( requestedResource );
419 assertResourceExists( requestedResource );
421 assertFetchVersioned( requestedResource );
423 assertReleaseMetadataContents( requestedResource );
427 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
428 * exists on multiple remote repositories.
430 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
431 * file location on the managed repository, a merge of the contents to the requested
432 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
433 * returned to the client.
436 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
439 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
440 setupTestableManagedRepository( requestedResource );
442 // Configure Connector (usually done within archiva.xml configuration)
443 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
444 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
445 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
446 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
448 assertResourceNotFound( requestedResource );
449 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
450 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
452 assertFetchVersioned( requestedResource );
454 assertReleaseMetadataContents( requestedResource );
455 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
456 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
460 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
461 * proxied repository.
463 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
464 * information, and then return to the client.
467 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
470 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
471 setupTestableManagedRepository( requestedResource );
473 // Configure Connector (usually done within archiva.xml configuration)
474 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
475 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
477 assertResourceNotFound( requestedResource );
479 assertFetchProjectOrGroupFailed( requestedResource );
481 assertResourceNotFound( requestedResource );
482 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
486 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
487 * exists on 1 remote repository.
489 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
490 * file location on the managed repository, a merge of the contents to the requested
491 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
492 * returned to the client.
495 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
498 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
499 setupTestableManagedRepository( requestedResource );
501 // Configure Connector (usually done within archiva.xml configuration)
502 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
503 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
505 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
507 assertFetchVersioned( requestedResource );
509 assertReleaseMetadataContents( requestedResource );
510 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
514 * A request for a maven-metadata.xml file that exists in the managed repository, but
515 * not on any remote repository.
517 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
518 * is not downloaded. There is no repository specific metadata file on the managed
519 * repository. The managed repository maven-metadata.xml is returned to the
523 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
526 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
527 setupTestableManagedRepository( requestedResource );
529 // Configure Connector (usually done within archiva.xml configuration)
530 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
531 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
533 assertReleaseMetadataContents( requestedResource );
535 assertFetchVersioned( requestedResource );
537 assertReleaseMetadataContents( requestedResource );
538 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
542 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
543 * remote repositories.
545 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
546 * and merged into the contents of the existing managed repository copy of
547 * the maven-metadata.xml file.
550 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
553 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
554 setupTestableManagedRepository( requestedResource );
556 // Configure Connector (usually done within archiva.xml configuration)
557 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
558 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
559 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
560 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
562 assertReleaseMetadataContents( requestedResource );
563 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
564 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
566 assertFetchVersioned( requestedResource );
568 assertReleaseMetadataContents( requestedResource );
569 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
570 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
574 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
577 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
578 * and merged into the contents of the existing managed repository copy of
579 * the maven-metadata.xml file.
582 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
585 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
586 setupTestableManagedRepository( requestedResource );
588 // Configure Connector (usually done within archiva.xml configuration)
589 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
590 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
592 assertReleaseMetadataContents( requestedResource );
593 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
595 assertFetchVersioned( requestedResource );
597 assertReleaseMetadataContents( requestedResource );
598 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
602 public void testGetSnapshotMetadataNotProxiedNotLocal()
605 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
606 String requestedResource =
607 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
608 setupTestableManagedRepository( requestedResource );
610 assertNoMetadata( requestedResource );
612 // No proxy setup, nothing fetched, no local file, failure expected.
613 assertFetchVersionedFailed( requestedResource );
615 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
616 assertNoMetadata( requestedResource );
620 public void testGetSnapshotMetadataNotProxiedOnLocal()
623 // The artifactId exists locally (but not on a remote repo)
624 String requestedResource =
625 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
626 setupTestableManagedRepository( requestedResource );
628 assertResourceExists( requestedResource );
630 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
631 assertFetchVersioned( requestedResource );
633 // Local metadata exists, should be updated to reflect the latest release.
634 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
638 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
641 String requestedResource =
642 "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
643 setupTestableManagedRepository( requestedResource );
645 // Configure Connector (usually done within archiva.xml configuration)
646 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
647 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
648 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
649 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
651 assertResourceNotFound( requestedResource );
652 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
653 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
655 // Proxying 2 repos, both have content, local file updated.
656 assertFetchVersioned( requestedResource );
658 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
659 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
660 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
664 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
667 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
668 String requestedResource =
669 "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
670 setupTestableManagedRepository( requestedResource );
672 // Configure Connector (usually done within archiva.xml configuration)
673 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
674 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
676 assertNoMetadata( requestedResource );
678 // One proxy setup, nothing fetched, no local file, failure expected.
679 assertFetchVersionedFailed( requestedResource );
681 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
682 assertNoMetadata( requestedResource );
683 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
687 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
690 // Artifact exists only in the proxied1 location.
691 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
692 setupTestableManagedRepository( requestedResource );
694 // Configure Connector (usually done within archiva.xml configuration)
695 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
696 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
698 assertResourceNotFound( requestedResource );
700 // One proxy setup, one metadata fetched, local file created/updated.
701 assertFetchVersioned( requestedResource );
703 // Local artifact Id should contain latest (which in this case is from proxied download)
704 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
705 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
709 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
712 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.0-SNAPSHOT/maven-metadata.xml";
713 setupTestableManagedRepository( requestedResource );
715 // Configure Connector (usually done within archiva.xml configuration)
716 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
717 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
718 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
719 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
721 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
722 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
723 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
725 // Proxying 2 repos, both have content, local file updated.
726 assertFetchVersioned( requestedResource );
728 assertSnapshotMetadataContents( requestedResource, "20070823", "212711", 6 );
729 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
730 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
734 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
737 // The artifactId exists locally (but not on a remote repo)
738 String requestedResource =
739 "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
740 setupTestableManagedRepository( requestedResource );
742 // Configure Connector (usually done within archiva.xml configuration)
743 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
744 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
745 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
746 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
748 assertResourceExists( requestedResource );
749 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
750 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
752 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
753 assertFetchVersioned( requestedResource );
755 // Local metadata exists, repo metadatas should not exist, local file updated.
756 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
757 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
758 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
762 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
765 // The artifactId exists locally (but not on a remote repo)
766 String requestedResource =
767 "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
768 setupTestableManagedRepository( requestedResource );
770 // Configure Connector (usually done within archiva.xml configuration)
771 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
772 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
774 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
775 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
777 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
778 assertFetchVersioned( requestedResource );
780 // Local metadata exists, repo metadata exists, local file updated.
781 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
782 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
786 public void testGetGroupMetadataNotProxiedNotLocal()
789 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
790 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
791 setupTestableManagedRepository( requestedResource );
793 assertResourceNotFound( requestedResource );
795 // No proxy setup, nothing fetched, failure expected.
796 assertFetchProjectOrGroupFailed( requestedResource );
798 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
799 assertResourceNotFound( requestedResource );
803 public void testGetGroupMetadataNotProxiedOnLocal()
806 // Project metadata that exists and has multiple versions
807 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
808 setupTestableManagedRepository( requestedResource );
810 assertResourceExists( requestedResource );
812 // No proxy setup, nothing fetched from remote, but local exists.
813 assertFetchProjectOrGroup( requestedResource );
815 // Nothing fetched. Should only contain contents of what is in the repository.
816 // A metadata update is not performed in this use case. Local metadata content is only
817 // updated via the metadata updater consumer.
818 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
822 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
825 // Project metadata that does not exist locally, but has multiple versions in remote repos
826 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
827 setupTestableManagedRepository( requestedResource );
829 // Configure Connector (usually done within archiva.xml configuration)
830 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
831 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
832 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
833 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
835 assertResourceNotFound( requestedResource );
836 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
837 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
839 // Two proxies setup, metadata fetched from both remotes.
840 assertFetchProjectOrGroup( requestedResource );
842 // Nothing fetched. Should only contain contents of what is in the repository.
843 assertGroupMetadataContents( requestedResource, new String[]{ "plugin2", "plugin1" } );
844 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1" } );
845 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin2" } );
849 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
852 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
853 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
854 setupTestableManagedRepository( requestedResource );
856 // Configure Connector (usually done within archiva.xml configuration)
857 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
858 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
859 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
860 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
862 assertResourceNotFound( requestedResource );
863 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
864 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
866 // Two proxies setup, nothing fetched from remotes, local does not exist.
867 assertFetchProjectOrGroupFailed( requestedResource );
869 // Nothing fetched. Nothing should exist.
870 assertResourceNotFound( requestedResource );
871 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
872 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
876 public void testGetGroupMetadataProxiedNotLocalOnRemote()
879 // New project metadata that does not exist locally but exists on remote.
880 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
881 setupTestableManagedRepository( requestedResource );
883 // Configure Connector (usually done within archiva.xml configuration)
884 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
885 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
887 assertResourceNotFound( requestedResource );
888 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
890 // One proxy setup, metadata fetched from remote, local does not exist.
891 assertFetchProjectOrGroup( requestedResource );
893 // Remote fetched. Local created/updated.
894 assertGroupMetadataContents( requestedResource, new String[]{ "plugin3" } );
895 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin3" } );
899 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
902 // Project metadata that exist locally, and has multiple versions in remote repos
903 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
904 setupTestableManagedRepository( requestedResource );
906 // Configure Connector (usually done within archiva.xml configuration)
907 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
908 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
909 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
910 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
912 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1" } );
913 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
914 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
916 // Two proxies setup, metadata fetched from both remotes.
917 assertFetchProjectOrGroup( requestedResource );
919 // metadata fetched from both repos, and merged with local version.
920 assertGroupMetadataContents( requestedResource, new String[]{ "plugin1", "plugin2", "plugin4" } );
921 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin1", "plugin4" } );
922 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[]{ "plugin1", "plugin2" } );
926 public void testGetGroupMetadataProxiedOnLocalNotRemote()
929 // Project metadata that exist locally, and does not exist in remote repos.
930 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
931 setupTestableManagedRepository( requestedResource );
933 // Configure Connector (usually done within archiva.xml configuration)
934 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
935 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
936 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
937 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
939 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
940 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
941 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
943 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
944 assertFetchProjectOrGroup( requestedResource );
946 // metadata not fetched from both repos, and local version exists.
947 // Since there was no updated metadata content from a remote/proxy, a metadata update on
948 // the local file never ran. Local only updates are performed via the metadata updater consumer.
949 assertGroupMetadataContents( requestedResource, new String[]{ "plugin5" } );
950 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
951 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
955 public void testGetGroupMetadataProxiedOnLocalOnRemote()
958 // Project metadata that exist locally and exists on remote.
959 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
960 setupTestableManagedRepository( requestedResource );
962 // Configure Connector (usually done within archiva.xml configuration)
963 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
964 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
966 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7" } );
967 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
969 // One proxy setup, metadata fetched from remote, local exists.
970 assertFetchProjectOrGroup( requestedResource );
972 // Remote fetched. Local updated.
973 assertGroupMetadataContents( requestedResource, new String[]{ "plugin6", "plugin7", "plugin4" } );
974 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[]{ "plugin7", "plugin4" } );
978 * Transfer the metadata file.
980 * @param requestedResource the requested resource
983 private void assertFetchProjectOrGroup( String requestedResource )
986 File expectedFile = new File( managedDefaultDir, requestedResource );
988 ProjectReference metadata = createProjectReference( requestedResource );
990 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
991 managedDefaultRepository.toMetadataPath(
994 assertNotNull( "Should have downloaded a file.", downloadedFile );
995 assertNoTempFiles( expectedFile );
998 private ProjectReference createProjectReference( String path )
999 throws RepositoryMetadataException
1001 return metadataTools.toProjectReference( path );
1005 * Transfer the metadata file, not expected to succeed.
1007 * @param requestedResource the requested resource
1010 private void assertFetchProjectOrGroupFailed( String requestedResource )
1013 File expectedFile = new File( managedDefaultDir, requestedResource );
1014 ProjectReference metadata = createProjectReference( requestedResource );
1016 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1017 managedDefaultRepository.toMetadataPath(
1020 assertNull( downloadedFile );
1021 assertNoTempFiles( expectedFile );
1025 * Transfer the metadata file.
1027 * @param requestedResource the requested resource
1030 private void assertFetchVersioned( String requestedResource )
1033 File expectedFile = new File( managedDefaultDir, requestedResource );
1035 VersionedReference metadata = createVersionedReference( requestedResource );
1037 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1038 managedDefaultRepository.toMetadataPath(
1041 assertNotNull( "Should have downloaded a file.", downloadedFile );
1042 assertNoTempFiles( expectedFile );
1045 private VersionedReference createVersionedReference( String path )
1046 throws RepositoryMetadataException
1048 return metadataTools.toVersionedReference( path );
1052 * Transfer the metadata file, not expected to succeed.
1054 * @param requestedResource the requested resource
1057 private void assertFetchVersionedFailed( String requestedResource )
1060 File expectedFile = new File( managedDefaultDir, requestedResource );
1061 VersionedReference metadata = createVersionedReference( requestedResource );
1063 File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
1064 managedDefaultRepository.toMetadataPath(
1067 assertNull( downloadedFile );
1068 assertNoTempFiles( expectedFile );
1072 * Test for the existance of the requestedResource in the default managed repository.
1074 * @param requestedResource the requested resource
1077 private void assertResourceExists( String requestedResource )
1080 File actualFile = new File( managedDefaultDir, requestedResource );
1081 assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() );
1084 private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
1087 assertNotNull( "Actual File should not be null.", actualFile );
1089 assertTrue( "Actual file exists.", actualFile.exists() );
1091 StringWriter actualContents = new StringWriter();
1092 ArchivaRepositoryMetadata metadata = MavenMetadataReader.read( actualFile );
1093 RepositoryMetadataWriter.write( metadata, actualContents );
1095 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1096 if ( !detailedDiff.similar() )
1098 assertEquals( expectedMetadataXml, actualContents );
1101 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1105 * Ensures that the requested resource is not present in the managed repository.
1107 * @param requestedResource the requested resource
1110 private void assertNoMetadata( String requestedResource )
1113 File expectedFile = new File( managedDefaultDir, requestedResource );
1114 assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() );
1118 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1119 * managed repository.
1121 * @param proxiedRepoId the proxied repository id to validate with.
1122 * @param requestedResource the resource requested.
1124 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1126 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1128 File actualFile = new File( managedDefaultDir, proxiedFile );
1129 assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
1132 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1135 File actualFile = new File( managedDefaultDir, requestedResource );
1136 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1138 ProjectReference actualMetadata = createGroupReference( requestedResource );
1140 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1143 private ProjectReference createGroupReference( String requestedResource )
1144 throws RepositoryMetadataException
1146 ProjectReference projectReference = createProjectReference( requestedResource );
1147 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1148 projectReference.setArtifactId( null );
1149 return projectReference;
1152 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1153 String expectedPlugins[] )
1156 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1158 File actualFile = new File( managedDefaultDir, proxiedFile );
1159 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
1161 ProjectReference actualMetadata = createGroupReference( requestedResource );
1163 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1166 private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1169 // Build expected metadata XML
1170 StringWriter expectedMetadataXml = new StringWriter();
1171 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1172 m.setGroupId( actualMetadata.getGroupId() );
1174 for ( String pluginId : expectedPlugins )
1176 Plugin p = new Plugin();
1177 p.setPrefix( pluginId );
1178 p.setArtifactId( pluginId + "-maven-plugin" );
1179 p.setName( "The " + pluginId + " Plugin" );
1180 m.getPlugins().add( p );
1183 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1185 // Compare the file to the actual contents.
1186 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1190 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1191 * does it contain the specified list of expected versions?
1193 * @param requestedResource the requested resource
1196 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1197 String latestVersion, String releaseVersion )
1200 File actualFile = new File( managedDefaultDir, requestedResource );
1201 assertTrue( actualFile.exists() );
1203 ProjectReference metadata = createProjectReference( requestedResource );
1205 // Build expected metadata XML
1206 StringWriter expectedMetadataXml = new StringWriter();
1207 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1208 m.setGroupId( metadata.getGroupId() );
1209 m.setArtifactId( metadata.getArtifactId() );
1210 m.setLatestVersion( latestVersion );
1211 m.setReleasedVersion( releaseVersion );
1213 if ( expectedVersions != null )
1215 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1218 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1220 // Compare the file to the actual contents.
1221 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1225 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1226 * does it contain the expected release maven-metadata.xml contents?
1228 * @param requestedResource the requested resource
1231 private void assertReleaseMetadataContents( String requestedResource )
1234 File actualFile = new File( managedDefaultDir, requestedResource );
1235 assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() );
1237 VersionedReference metadata = createVersionedReference( requestedResource );
1239 // Build expected metadata XML
1240 StringWriter expectedMetadataXml = new StringWriter();
1241 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1242 m.setGroupId( metadata.getGroupId() );
1243 m.setArtifactId( metadata.getArtifactId() );
1244 m.setVersion( metadata.getVersion() );
1245 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1247 // Compare the file to the actual contents.
1248 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1252 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1253 * does it contain the expected release maven-metadata.xml contents?
1255 * @param requestedResource the requested resource
1256 * @param expectedDate the date in "yyyyMMdd" format
1257 * @param expectedTime the time in "hhmmss" format
1258 * @param expectedBuildnumber the build number
1261 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1262 int expectedBuildnumber )
1265 File actualFile = new File( managedDefaultDir, requestedResource );
1266 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1268 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1270 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1274 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1275 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1277 * @param proxiedRepoId the repository id of the proxied repository.
1278 * @param requestedResource the requested resource
1279 * @param expectedDate the date in "yyyyMMdd" format
1280 * @param expectedTime the time in "hhmmss" format
1281 * @param expectedBuildnumber the build number
1284 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1285 String expectedDate, String expectedTime, int expectedBuildnumber )
1288 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1290 File actualFile = new File( managedDefaultDir, proxiedFile );
1291 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1293 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1295 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1298 private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate,
1299 String expectedTime, int expectedBuildnumber )
1300 throws RepositoryMetadataException, Exception
1302 // Build expected metadata XML
1303 StringWriter expectedMetadataXml = new StringWriter();
1304 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1305 m.setGroupId( actualMetadata.getGroupId() );
1306 m.setArtifactId( actualMetadata.getArtifactId() );
1307 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1309 m.setSnapshotVersion( new SnapshotVersion() );
1311 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1313 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1316 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1318 m.setLastUpdated( expectedDate + expectedTime );
1320 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1322 // Compare the file to the actual contents.
1323 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1327 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1328 * list of expected versions within.
1330 * @param proxiedRepoId
1331 * @param requestedResource
1332 * @param expectedProxyVersions
1334 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1335 String[] expectedProxyVersions )
1338 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1340 File actualFile = new File( managedDefaultDir, proxiedFile );
1341 assertTrue( actualFile.exists() );
1343 ProjectReference metadata = createProjectReference( requestedResource );
1345 // Build expected metadata XML
1346 StringWriter expectedMetadataXml = new StringWriter();
1347 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1348 m.setGroupId( metadata.getGroupId() );
1349 m.setArtifactId( metadata.getArtifactId() );
1351 if ( expectedProxyVersions != null )
1353 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1356 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1358 // Compare the file to the actual contents.
1359 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1363 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1364 * list of expected versions within.
1366 * @param proxiedRepoId
1367 * @param requestedResource
1369 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1372 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1374 File actualFile = new File( managedDefaultDir, proxiedFile );
1375 assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() );
1377 VersionedReference metadata = createVersionedReference( requestedResource );
1379 // Build expected metadata XML
1380 StringWriter expectedMetadataXml = new StringWriter();
1381 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1382 m.setGroupId( metadata.getGroupId() );
1383 m.setArtifactId( metadata.getArtifactId() );
1384 m.setVersion( metadata.getVersion() );
1385 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1387 // Compare the file to the actual contents.
1388 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1392 * Test for the non-existance of the requestedResource in the default managed repository.
1394 * @param requestedResource the requested resource
1397 private void assertResourceNotFound( String requestedResource )
1400 File actualFile = new File( managedDefaultDir, requestedResource );
1401 assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() );