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.model.ArchivaRepositoryMetadata;
25 import org.apache.maven.archiva.model.Plugin;
26 import org.apache.maven.archiva.model.ProjectReference;
27 import org.apache.maven.archiva.model.SnapshotVersion;
28 import org.apache.maven.archiva.model.VersionedReference;
29 import org.apache.maven.archiva.policies.CachedFailuresPolicy;
30 import org.apache.maven.archiva.policies.ChecksumPolicy;
31 import org.apache.maven.archiva.policies.ReleasesPolicy;
32 import org.apache.maven.archiva.policies.SnapshotsPolicy;
33 import org.apache.maven.archiva.repository.metadata.MetadataTools;
34 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
35 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
36 import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
37 import org.apache.maven.wagon.TransferFailedException;
38 import org.custommonkey.xmlunit.DetailedDiff;
39 import org.custommonkey.xmlunit.Diff;
42 import java.io.StringWriter;
43 import java.util.Arrays;
46 * MetadataTransferTest - Tests the various fetching / merging concepts surrounding the maven-metadata.xml files
47 * present in the repository.
49 * Test Case Naming is as follows.
52 * public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
56 * Which should leave the following matrix of test cases.
58 * Metadata | Proxied | Local | Remote
59 * ----------+----------+-------+---------
60 * Release | Not | Not | n/a (1)
61 * Release | Not | On | n/a (1)
62 * Release | | Not | Not
63 * Release | | Not | On
64 * Release | | Not | Multiple
65 * Release | | On | Not
67 * Release | | On | Multiple
68 * Snapshot | Not | Not | n/a (1)
69 * Snapshot | Not | On | n/a (1)
70 * Snapshot | | Not | Not
71 * Snapshot | | Not | On
72 * Snapshot | | Not | Multiple
73 * Snapshot | | On | Not
74 * Snapshot | | On | On
75 * Snapshot | | On | Multiple
76 * Project | Not | Not | n/a (1)
77 * Project | Not | On | n/a (1)
78 * Project | | Not | Not
79 * Project | | Not | On
80 * Project | | Not | Multiple
81 * Project | | On | Not
83 * Project | | On | Multiple
85 * (1) If it isn't proxied, no point in having a remote.
88 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
91 public class MetadataTransferTest
92 extends AbstractProxyTestCase
97 private MetadataTools metadataTools;
99 // TODO: same test for other fetch* methods
100 public void testFetchFromTwoProxiesWhenFirstConnectionFails()
103 // Project metadata that does not exist locally, but has multiple versions in remote repos
104 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
105 setupTestableManagedRepository( requestedResource );
107 saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
109 // Configure Connector (usually done within archiva.xml configuration)
110 saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
111 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
112 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
113 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
115 assertResourceNotFound( requestedResource );
116 assertNoRepoMetadata( "badproxied1", requestedResource );
117 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
119 // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
120 File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
121 metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
122 wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
124 wagonMockControl.setMatcher(customWagonGetMatcher);
126 wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) );
128 wagonMockControl.replay();
130 assertFetchProjectOrGroup( requestedResource );
132 wagonMockControl.verify();
134 assertProjectMetadataContents( requestedResource, new String[] { "1.0.1" }, "1.0.1", "1.0.1" );
135 assertNoRepoMetadata( "badproxied1", requestedResource );
136 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } );
140 * Attempt to get the project metadata for non-existant artifact.
142 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
143 * to the requesting client.
145 public void testGetProjectMetadataNotProxiedNotLocal()
148 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
149 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/maven-metadata.xml";
150 setupTestableManagedRepository( requestedResource );
152 assertResourceNotFound( requestedResource );
154 // No proxy setup, nothing fetched, failure expected.
155 assertFetchProjectOrGroupFailed( requestedResource );
157 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
158 assertResourceNotFound( requestedResource );
161 public void testGetProjectMetadataNotProxiedOnLocal()
164 // Project metadata that exists and has multiple versions
165 String requestedResource = "org/apache/maven/test/get-project-metadata/maven-metadata.xml";
166 setupTestableManagedRepository( requestedResource );
168 assertResourceExists( requestedResource );
170 // No proxy setup, nothing fetched from remote, but local exists.
171 assertFetchProjectOrGroup( requestedResource );
173 // Nothing fetched. Should only contain contents of what is in the repository.
174 // A metadata update is not performed in this use case. Local metadata content is only
175 // updated via the metadata updater consumer.
176 assertProjectMetadataContents( requestedResource, new String[] { "1.0" }, null, null );
179 public void testGetProjectMetadataProxiedNotLocalMultipleRemotes()
182 // Project metadata that does not exist locally, but has multiple versions in remote repos
183 String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
184 setupTestableManagedRepository( requestedResource );
186 // Configure Connector (usually done within archiva.xml configuration)
187 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
188 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
189 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
190 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
192 assertResourceNotFound( requestedResource );
193 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
194 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
196 // Two proxies setup, metadata fetched from both remotes.
197 assertFetchProjectOrGroup( requestedResource );
199 // Nothing fetched. Should only contain contents of what is in the repository.
200 assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
201 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0" } );
202 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } );
205 public void testGetProjectMetadataProxiedNotLocalNotRemote()
208 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
209 String requestedResource = "org/apache/maven/test/get-bogus-artifact/maven-metadata.xml";
210 setupTestableManagedRepository( requestedResource );
212 // Configure Connector (usually done within archiva.xml configuration)
213 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
214 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
215 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
216 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
218 assertResourceNotFound( requestedResource );
219 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
220 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
222 // Two proxies setup, nothing fetched from remotes, local does not exist.
223 assertFetchProjectOrGroupFailed( requestedResource );
225 // Nothing fetched. Nothing should exist.
226 assertResourceNotFound( requestedResource );
227 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
228 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
231 public void testGetProjectMetadataProxiedNotLocalOnRemote()
234 // New project metadata that does not exist locally but exists on remote.
235 String requestedResource = "org/apache/maven/test/get-found-in-proxy/maven-metadata.xml";
236 setupTestableManagedRepository( requestedResource );
238 // Configure Connector (usually done within archiva.xml configuration)
239 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
240 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
242 assertResourceNotFound( requestedResource );
243 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
245 // One proxy setup, metadata fetched from remote, local does not exist.
246 assertFetchProjectOrGroup( requestedResource );
248 // Remote fetched. Local created/updated.
249 assertProjectMetadataContents( requestedResource, new String[] { "1.0.5" }, "1.0.5", "1.0.5" );
250 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0.5" } );
253 public void testGetProjectMetadataProxiedOnLocalMultipleRemote()
256 // Project metadata that exist locally, and has multiple versions in remote repos
257 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/maven-metadata.xml";
258 setupTestableManagedRepository( requestedResource );
260 // Configure Connector (usually done within archiva.xml configuration)
261 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
262 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
263 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
264 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
266 assertProjectMetadataContents( requestedResource, new String[] { "1.0" }, null, null );
267 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
268 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
270 // Two proxies setup, metadata fetched from both remotes.
271 assertFetchProjectOrGroup( requestedResource );
273 // metadata fetched from both repos, and merged with local version.
274 assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
275 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0", "2.0" } );
276 assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0", "1.0.1" } );
279 public void testGetProjectMetadataProxiedOnLocalNotRemote()
282 // Project metadata that exist locally, and does not exist in remote repos.
283 String requestedResource = "org/apache/maven/test/get-not-on-remotes/maven-metadata.xml";
284 setupTestableManagedRepository( requestedResource );
286 // Configure Connector (usually done within archiva.xml configuration)
287 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
288 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
289 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
290 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
292 assertProjectMetadataContents( requestedResource, new String[] { "1.0-beta-2" }, null, null );
293 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
294 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
296 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
297 assertFetchProjectOrGroup( requestedResource );
299 // metadata not fetched from both repos, and local version exists.
300 // Since there was no updated metadata content from a remote/proxy, a metadata update on
301 // the local file never ran. Local only updates are performed via the metadata updater consumer.
302 assertProjectMetadataContents( requestedResource, new String[] { "1.0-beta-2" }, null, null );
303 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
304 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
307 public void testGetProjectMetadataProxiedOnLocalOnRemote()
310 // Project metadata that exist locally and exists on remote.
311 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/maven-metadata.xml";
312 setupTestableManagedRepository( requestedResource );
314 // Configure Connector (usually done within archiva.xml configuration)
315 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
316 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
318 assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22" }, null, null );
319 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
321 // One proxy setup, metadata fetched from remote, local exists.
322 assertFetchProjectOrGroup( requestedResource );
324 // Remote fetched. Local updated.
325 assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
326 assertRepoProjectMetadata( ID_PROXIED1, requestedResource, new String[] { "1.0.22", "2.0" } );
330 * A request for a release maven-metadata.xml file that does not exist locally, and the managed
331 * repository has no proxied repositories set up.
333 * Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
334 * to the requesting client.
336 public void testGetReleaseMetadataNotProxiedNotLocal()
339 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
340 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0/maven-metadata.xml";
341 setupTestableManagedRepository( requestedResource );
343 assertNoMetadata( requestedResource );
345 // No proxy setup, nothing fetched, failure expected.
346 assertFetchVersionedFailed( requestedResource );
348 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
349 assertNoMetadata( requestedResource );
353 * A request for a maven-metadata.xml file that does exist locally, and the managed
354 * repository has no proxied repositories set up.
356 * Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
357 * information, and then returned to the client.
359 public void testGetReleaseMetadataNotProxiedOnLocal()
362 String requestedResource = "org/apache/maven/test/get-default-metadata/1.0/maven-metadata.xml";
363 setupTestableManagedRepository( requestedResource );
365 assertResourceExists( requestedResource );
367 assertFetchVersioned( requestedResource );
369 assertReleaseMetadataContents( requestedResource );
373 * A request for a release maven-metadata.xml file that does not exist on the managed repository, but
374 * exists on multiple remote repositories.
376 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
377 * file location on the managed repository, a merge of the contents to the requested
378 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
379 * returned to the client.
381 public void testGetReleaseMetadataProxiedNotLocalMultipleRemotes()
384 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
385 setupTestableManagedRepository( requestedResource );
387 // Configure Connector (usually done within archiva.xml configuration)
388 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
389 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
390 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
391 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
393 assertResourceNotFound( requestedResource );
394 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
395 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
397 assertFetchVersioned( requestedResource );
399 assertReleaseMetadataContents( requestedResource );
400 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
401 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
405 * A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
406 * proxied repository.
408 * Expected result: the maven-metadata.xml file is created locally, based off of managed repository
409 * information, and then return to the client.
411 public void testGetReleaseMetadataProxiedNotLocalNotRemote()
414 String requestedResource = "org/apache/maven/test/get-bad-metadata/1.0/maven-metadata.xml";
415 setupTestableManagedRepository( requestedResource );
417 // Configure Connector (usually done within archiva.xml configuration)
418 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
419 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
421 assertResourceNotFound( requestedResource );
423 assertFetchProjectOrGroupFailed( requestedResource );
425 assertResourceNotFound( requestedResource );
426 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
430 * A request for a maven-metadata.xml file that does not exist on the managed repository, but
431 * exists on 1 remote repository.
433 * Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
434 * file location on the managed repository, a merge of the contents to the requested
435 * maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
436 * returned to the client.
438 public void testGetReleaseMetadataProxiedNotLocalOnRemote()
441 String requestedResource = "org/apache/maven/test/get-default-layout/1.0/maven-metadata.xml";
442 setupTestableManagedRepository( requestedResource );
444 // Configure Connector (usually done within archiva.xml configuration)
445 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
446 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
448 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
450 assertFetchVersioned( requestedResource );
452 assertReleaseMetadataContents( requestedResource );
453 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
457 * A request for a maven-metadata.xml file that exists in the managed repository, but
458 * not on any remote repository.
460 * Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
461 * is not downloaded. There is no repository specific metadata file on the managed
462 * repository. The managed repository maven-metadata.xml is returned to the
465 public void testGetReleaseMetadataProxiedOnLocalNotRemote()
468 String requestedResource = "org/apache/maven/test/get-not-on-remotes/1.0-beta-2/maven-metadata.xml";
469 setupTestableManagedRepository( requestedResource );
471 // Configure Connector (usually done within archiva.xml configuration)
472 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
473 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
475 assertReleaseMetadataContents( requestedResource );
477 assertFetchVersioned( requestedResource );
479 assertReleaseMetadataContents( requestedResource );
480 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
484 * A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
485 * remote repositories.
487 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
488 * and merged into the contents of the existing managed repository copy of
489 * the maven-metadata.xml file.
491 public void testGetReleaseMetadataProxiedOnLocalMultipleRemote()
494 String requestedResource = "org/apache/maven/test/get-on-multiple-repos/1.0/maven-metadata.xml";
495 setupTestableManagedRepository( requestedResource );
497 // Configure Connector (usually done within archiva.xml configuration)
498 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
499 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
500 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
501 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
503 assertReleaseMetadataContents( requestedResource );
504 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
505 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
507 assertFetchVersioned( requestedResource );
509 assertReleaseMetadataContents( requestedResource );
510 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
511 assertRepoReleaseMetadataContents( ID_PROXIED2, requestedResource );
515 * A request for a maven-metadata.xml file that exists in the managed repository, and on one
518 * Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
519 * and merged into the contents of the existing managed repository copy of
520 * the maven-metadata.xml file.
522 public void testGetReleaseMetadataProxiedOnLocalOnRemote()
525 String requestedResource = "org/apache/maven/test/get-on-local-on-remote/1.0.22/maven-metadata.xml";
526 setupTestableManagedRepository( requestedResource );
528 // Configure Connector (usually done within archiva.xml configuration)
529 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
530 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
532 assertReleaseMetadataContents( requestedResource );
533 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
535 assertFetchVersioned( requestedResource );
537 assertReleaseMetadataContents( requestedResource );
538 assertRepoReleaseMetadataContents( ID_PROXIED1, requestedResource );
541 public void testGetSnapshotMetadataNotProxiedNotLocal()
544 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
545 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
546 setupTestableManagedRepository( requestedResource );
548 assertNoMetadata( requestedResource );
550 // No proxy setup, nothing fetched, no local file, failure expected.
551 assertFetchVersionedFailed( requestedResource );
553 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
554 assertNoMetadata( requestedResource );
557 public void testGetSnapshotMetadataNotProxiedOnLocal()
560 // The artifactId exists locally (but not on a remote repo)
561 String requestedResource = "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
562 setupTestableManagedRepository( requestedResource );
564 assertResourceExists( requestedResource );
566 // No proxy setup, nothing fetched from remote, local file exists, fetch should succeed.
567 assertFetchVersioned( requestedResource );
569 // Local metadata exists, should be updated to reflect the latest release.
570 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
573 public void testGetSnapshotMetadataProxiedNotLocalMultipleRemotes()
576 String requestedResource = "org/apache/maven/test/get-timestamped-snapshot-in-both/1.0-SNAPSHOT/maven-metadata.xml";
577 setupTestableManagedRepository( requestedResource );
579 // Configure Connector (usually done within archiva.xml configuration)
580 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
581 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
582 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
583 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
585 assertResourceNotFound( requestedResource );
586 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
587 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
589 // Proxying 2 repos, both have content, local file updated.
590 assertFetchVersioned( requestedResource );
592 assertSnapshotMetadataContents( requestedResource, "20070101", "000103", 2 );
593 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20061227", "112101", 2 );
594 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070101", "000103", 2 );
597 public void testGetSnapshotMetadataProxiedNotLocalNotRemote()
600 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
601 String requestedResource = "org/apache/maven/test/get-default-metadata-nonexistant/1.0-SNAPSHOT/maven-metadata.xml";
602 setupTestableManagedRepository( requestedResource );
604 // Configure Connector (usually done within archiva.xml configuration)
605 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
606 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
608 assertNoMetadata( requestedResource );
610 // One proxy setup, nothing fetched, no local file, failure expected.
611 assertFetchVersionedFailed( requestedResource );
613 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
614 assertNoMetadata( requestedResource );
615 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
618 public void testGetSnapshotMetadataProxiedNotLocalOnRemote()
621 // Artifact exists only in the proxied1 location.
622 String requestedResource = "org/apache/maven/test/get-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
623 setupTestableManagedRepository( requestedResource );
625 // Configure Connector (usually done within archiva.xml configuration)
626 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
627 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
629 assertResourceNotFound( requestedResource );
631 // One proxy setup, one metadata fetched, local file created/updated.
632 assertFetchVersioned( requestedResource );
634 // Local artifact Id should contain latest (which in this case is from proxied download)
635 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
636 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
639 public void testGetSnapshotMetadataProxiedOnLocalMultipleRemote()
642 String requestedResource = "org/apache/maven/test/get-snapshot-popular/2.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 );
648 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
649 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
651 assertSnapshotMetadataContents( requestedResource, "20070822", "021008", 3 );
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, "20070823", "212711", 6 );
659 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20070822", "145534", 9 );
660 assertRepoSnapshotMetadataContents( ID_PROXIED2, requestedResource, "20070823", "212711", 6 );
663 public void testGetSnapshotMetadataProxiedOnLocalNotRemote()
666 // The artifactId exists locally (but not on a remote repo)
667 String requestedResource = "org/apache/maven/test/get-snapshot-on-local-not-remote/2.0-alpha-2-SNAPSHOT/maven-metadata.xml";
668 setupTestableManagedRepository( requestedResource );
670 // Configure Connector (usually done within archiva.xml configuration)
671 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
672 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
673 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
674 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
676 assertResourceExists( requestedResource );
677 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
678 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
680 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
681 assertFetchVersioned( requestedResource );
683 // Local metadata exists, repo metadatas should not exist, local file updated.
684 assertSnapshotMetadataContents( requestedResource, "20070821", "220304", 2 );
685 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
686 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
689 public void testGetSnapshotMetadataProxiedOnLocalOnRemote()
692 // The artifactId exists locally (but not on a remote repo)
693 String requestedResource = "org/apache/maven/test/get-present-metadata-snapshot/1.0-SNAPSHOT/maven-metadata.xml";
694 setupTestableManagedRepository( requestedResource );
696 // Configure Connector (usually done within archiva.xml configuration)
697 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
698 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
700 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
701 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
703 // two proxies setup, nothing fetched from either remote, local file exists, fetch should succeed.
704 assertFetchVersioned( requestedResource );
706 // Local metadata exists, repo metadata exists, local file updated.
707 assertSnapshotMetadataContents( requestedResource, "20050831", "101112", 1 );
708 assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
711 public void testGetGroupMetadataNotProxiedNotLocal()
714 // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
715 String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
716 setupTestableManagedRepository( requestedResource );
718 assertResourceNotFound( requestedResource );
720 // No proxy setup, nothing fetched, failure expected.
721 assertFetchProjectOrGroupFailed( requestedResource );
723 // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
724 assertResourceNotFound( requestedResource );
727 public void testGetGroupMetadataNotProxiedOnLocal()
730 // Project metadata that exists and has multiple versions
731 String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
732 setupTestableManagedRepository( requestedResource );
734 assertResourceExists( requestedResource );
736 // No proxy setup, nothing fetched from remote, but local exists.
737 assertFetchProjectOrGroup( requestedResource );
739 // Nothing fetched. Should only contain contents of what is in the repository.
740 // A metadata update is not performed in this use case. Local metadata content is only
741 // updated via the metadata updater consumer.
742 assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
745 public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
748 // Project metadata that does not exist locally, but has multiple versions in remote repos
749 String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
750 setupTestableManagedRepository( requestedResource );
752 // Configure Connector (usually done within archiva.xml configuration)
753 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
754 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
755 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
756 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
758 assertResourceNotFound( requestedResource );
759 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
760 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
762 // Two proxies setup, metadata fetched from both remotes.
763 assertFetchProjectOrGroup( requestedResource );
765 // Nothing fetched. Should only contain contents of what is in the repository.
766 assertGroupMetadataContents( requestedResource, new String[] { "plugin2", "plugin1" } );
767 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1" } );
768 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin2" } );
771 public void testGetGroupsMetadataProxiedNotLocalNotRemote()
774 // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
775 String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
776 setupTestableManagedRepository( requestedResource );
778 // Configure Connector (usually done within archiva.xml configuration)
779 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
780 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
781 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
782 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
784 assertResourceNotFound( requestedResource );
785 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
786 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
788 // Two proxies setup, nothing fetched from remotes, local does not exist.
789 assertFetchProjectOrGroupFailed( requestedResource );
791 // Nothing fetched. Nothing should exist.
792 assertResourceNotFound( requestedResource );
793 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
794 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
797 public void testGetGroupMetadataProxiedNotLocalOnRemote()
800 // New project metadata that does not exist locally but exists on remote.
801 String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
802 setupTestableManagedRepository( requestedResource );
804 // Configure Connector (usually done within archiva.xml configuration)
805 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
806 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
808 assertResourceNotFound( requestedResource );
809 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
811 // One proxy setup, metadata fetched from remote, local does not exist.
812 assertFetchProjectOrGroup( requestedResource );
814 // Remote fetched. Local created/updated.
815 assertGroupMetadataContents( requestedResource, new String[] { "plugin3" } );
816 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin3" } );
819 public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
822 // Project metadata that exist locally, and has multiple versions in remote repos
823 String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
824 setupTestableManagedRepository( requestedResource );
826 // Configure Connector (usually done within archiva.xml configuration)
827 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
828 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
829 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
830 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
832 assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
833 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
834 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
836 // Two proxies setup, metadata fetched from both remotes.
837 assertFetchProjectOrGroup( requestedResource );
839 // metadata fetched from both repos, and merged with local version.
840 assertGroupMetadataContents( requestedResource, new String[] { "plugin1", "plugin2", "plugin4" } );
841 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1", "plugin4" } );
842 assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin1", "plugin2" } );
845 public void testGetGroupMetadataProxiedOnLocalNotRemote()
848 // Project metadata that exist locally, and does not exist in remote repos.
849 String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
850 setupTestableManagedRepository( requestedResource );
852 // Configure Connector (usually done within archiva.xml configuration)
853 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
854 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
855 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
856 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
858 assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
859 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
860 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
862 // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
863 assertFetchProjectOrGroup( requestedResource );
865 // metadata not fetched from both repos, and local version exists.
866 // Since there was no updated metadata content from a remote/proxy, a metadata update on
867 // the local file never ran. Local only updates are performed via the metadata updater consumer.
868 assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
869 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
870 assertNoRepoMetadata( ID_PROXIED2, requestedResource );
873 public void testGetGroupMetadataProxiedOnLocalOnRemote()
876 // Project metadata that exist locally and exists on remote.
877 String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
878 setupTestableManagedRepository( requestedResource );
880 // Configure Connector (usually done within archiva.xml configuration)
881 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
882 SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
884 assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7" } );
885 assertNoRepoMetadata( ID_PROXIED1, requestedResource );
887 // One proxy setup, metadata fetched from remote, local exists.
888 assertFetchProjectOrGroup( requestedResource );
890 // Remote fetched. Local updated.
891 assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7", "plugin4" } );
892 assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin7", "plugin4" } );
896 * Transfer the metadata file.
898 * @param requestedResource the requested resource
901 private void assertFetchProjectOrGroup( String requestedResource )
904 File expectedFile = new File( managedDefaultDir, requestedResource );
906 ProjectReference metadata = createProjectReference( requestedResource );
908 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
910 assertNotNull( "Should have downloaded a file.", downloadedFile );
911 assertNoTempFiles( expectedFile );
914 private ProjectReference createProjectReference( String path )
915 throws RepositoryMetadataException
917 return metadataTools.toProjectReference( path );
921 * Transfer the metadata file, not expected to succeed.
923 * @param requestedResource the requested resource
926 private void assertFetchProjectOrGroupFailed( String requestedResource )
929 File expectedFile = new File( managedDefaultDir, requestedResource );
930 ProjectReference metadata = createProjectReference( requestedResource );
932 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
934 assertNull( downloadedFile );
935 assertNoTempFiles( expectedFile );
939 * Transfer the metadata file.
941 * @param requestedResource the requested resource
944 private void assertFetchVersioned( String requestedResource )
947 File expectedFile = new File( managedDefaultDir, requestedResource );
949 VersionedReference metadata = createVersionedReference( requestedResource );
951 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
953 assertNotNull( "Should have downloaded a file.", downloadedFile );
954 assertNoTempFiles( expectedFile );
957 private VersionedReference createVersionedReference( String path )
958 throws RepositoryMetadataException
960 return metadataTools.toVersionedReference( path );
964 * Transfer the metadata file, not expected to succeed.
966 * @param requestedResource the requested resource
969 private void assertFetchVersionedFailed( String requestedResource )
972 File expectedFile = new File( managedDefaultDir, requestedResource );
973 VersionedReference metadata = createVersionedReference( requestedResource );
975 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, metadata );
977 assertNull( downloadedFile );
978 assertNoTempFiles( expectedFile );
982 * Test for the existance of the requestedResource in the default managed repository.
984 * @param requestedResource the requested resource
987 private void assertResourceExists( String requestedResource )
990 File actualFile = new File( managedDefaultDir, requestedResource );
991 assertTrue( "Resource should exist: " + requestedResource, actualFile.exists() );
994 private void assertMetadataEquals( String expectedMetadataXml, File actualFile )
997 assertNotNull( "Actual File should not be null.", actualFile );
999 assertTrue( "Actual file exists.", actualFile.exists() );
1001 StringWriter actualContents = new StringWriter();
1002 ArchivaRepositoryMetadata metadata = RepositoryMetadataReader.read( actualFile );
1003 RepositoryMetadataWriter.write( metadata, actualContents );
1005 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadataXml, actualContents.toString() ) );
1006 if ( !detailedDiff.similar() )
1008 assertEquals( expectedMetadataXml, actualContents );
1011 // assertEquals( "Check file contents.", expectedMetadataXml, actualContents );
1015 * Ensures that the requested resource is not present in the managed repository.
1017 * @param requestedResource the requested resource
1020 private void assertNoMetadata( String requestedResource )
1023 File expectedFile = new File( managedDefaultDir, requestedResource );
1024 assertFalse( "metadata should not exist: " + expectedFile, expectedFile.exists() );
1028 * Ensures that the proxied repository specific maven metadata file does NOT exist in the
1029 * managed repository.
1030 * @param proxiedRepoId the proxied repository id to validate with.
1031 * @param requestedResource the resource requested.
1033 private void assertNoRepoMetadata( String proxiedRepoId, String requestedResource )
1035 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1037 File actualFile = new File( managedDefaultDir, proxiedFile );
1038 assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
1041 private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
1044 File actualFile = new File( managedDefaultDir, requestedResource );
1045 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1047 ProjectReference actualMetadata = createGroupReference( requestedResource );
1049 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1052 private ProjectReference createGroupReference( String requestedResource )
1053 throws RepositoryMetadataException
1055 ProjectReference projectReference = createProjectReference( requestedResource );
1056 projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
1057 projectReference.setArtifactId( null );
1058 return projectReference;
1061 private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
1062 String expectedPlugins[] )
1065 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1067 File actualFile = new File( managedDefaultDir, proxiedFile );
1068 assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
1070 ProjectReference actualMetadata = createGroupReference( requestedResource );
1072 assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
1075 private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
1078 // Build expected metadata XML
1079 StringWriter expectedMetadataXml = new StringWriter();
1080 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1081 m.setGroupId( actualMetadata.getGroupId() );
1083 for ( String pluginId : expectedPlugins )
1085 Plugin p = new Plugin();
1086 p.setPrefix( pluginId );
1087 p.setArtifactId( pluginId + "-maven-plugin" );
1088 p.setName( "The " + pluginId + " Plugin" );
1089 m.getPlugins().add( p );
1092 m.setModelEncoding( null );
1093 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1095 // Compare the file to the actual contents.
1096 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1100 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1101 * does it contain the specified list of expected versions?
1103 * @param requestedResource the requested resource
1106 private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
1107 String latestVersion, String releaseVersion )
1110 File actualFile = new File( managedDefaultDir, requestedResource );
1111 assertTrue( actualFile.exists() );
1113 ProjectReference metadata = createProjectReference( requestedResource );
1115 // Build expected metadata XML
1116 StringWriter expectedMetadataXml = new StringWriter();
1117 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1118 m.setGroupId( metadata.getGroupId() );
1119 m.setArtifactId( metadata.getArtifactId() );
1120 m.setLatestVersion( latestVersion );
1121 m.setReleasedVersion( releaseVersion );
1123 if ( expectedVersions != null )
1125 m.getAvailableVersions().addAll( Arrays.asList( expectedVersions ) );
1128 m.setModelEncoding( null );
1129 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1131 // Compare the file to the actual contents.
1132 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1136 * Test for the existance of the requestedResource in the default managed repository, and if it exists,
1137 * does it contain the expected release maven-metadata.xml contents?
1139 * @param requestedResource the requested resource
1142 private void assertReleaseMetadataContents( String requestedResource )
1145 File actualFile = new File( managedDefaultDir, requestedResource );
1146 assertTrue( "Release Metadata should exist: " + requestedResource, actualFile.exists() );
1148 VersionedReference metadata = createVersionedReference( requestedResource );
1150 // Build expected metadata XML
1151 StringWriter expectedMetadataXml = new StringWriter();
1152 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1153 m.setGroupId( metadata.getGroupId() );
1154 m.setArtifactId( metadata.getArtifactId() );
1155 m.setVersion( metadata.getVersion() );
1156 m.setModelEncoding( null );
1157 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1159 // Compare the file to the actual contents.
1160 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1164 * Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
1165 * does it contain the expected release maven-metadata.xml contents?
1167 * @param requestedResource the requested resource
1168 * @param expectedDate the date in "yyyyMMdd" format
1169 * @param expectedTime the time in "hhmmss" format
1170 * @param expectedBuildnumber the build number
1174 private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
1175 int expectedBuildnumber )
1178 File actualFile = new File( managedDefaultDir, requestedResource );
1179 assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1181 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1183 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1187 * Test for the existance of the proxied repository specific snapshot metadata in the default managed
1188 * repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
1190 * @param proxiedRepoId the repository id of the proxied repository.
1191 * @param requestedResource the requested resource
1192 * @param expectedDate the date in "yyyyMMdd" format
1193 * @param expectedTime the time in "hhmmss" format
1194 * @param expectedBuildnumber the build number
1198 private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
1199 String expectedDate, String expectedTime, int expectedBuildnumber )
1202 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1204 File actualFile = new File( managedDefaultDir, proxiedFile );
1205 assertTrue( "Repo Specific Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
1207 VersionedReference actualMetadata = createVersionedReference( requestedResource );
1209 assertSnapshotMetadata( actualFile, actualMetadata, expectedDate, expectedTime, expectedBuildnumber );
1212 private void assertSnapshotMetadata( File actualFile, VersionedReference actualMetadata, String expectedDate,
1213 String expectedTime, int expectedBuildnumber )
1214 throws RepositoryMetadataException, Exception
1216 // Build expected metadata XML
1217 StringWriter expectedMetadataXml = new StringWriter();
1218 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1219 m.setGroupId( actualMetadata.getGroupId() );
1220 m.setArtifactId( actualMetadata.getArtifactId() );
1221 m.setVersion( VersionUtil.getBaseVersion( actualMetadata.getVersion() ) );
1223 m.setSnapshotVersion( new SnapshotVersion() );
1225 if ( StringUtils.isNotBlank( expectedDate ) && StringUtils.isNotBlank( expectedTime ) )
1227 m.getSnapshotVersion().setTimestamp( expectedDate + "." + expectedTime );
1230 m.getSnapshotVersion().setBuildNumber( expectedBuildnumber );
1232 m.setLastUpdated( expectedDate + expectedTime );
1234 m.setModelEncoding( null );
1235 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1237 // Compare the file to the actual contents.
1238 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1242 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1243 * list of expected versions within.
1244 * @param proxiedRepoId
1245 * @param requestedResource
1246 * @param expectedProxyVersions
1248 private void assertRepoProjectMetadata( String proxiedRepoId, String requestedResource,
1249 String[] expectedProxyVersions )
1252 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1254 File actualFile = new File( managedDefaultDir, proxiedFile );
1255 assertTrue( actualFile.exists() );
1257 ProjectReference metadata = createProjectReference( requestedResource );
1259 // Build expected metadata XML
1260 StringWriter expectedMetadataXml = new StringWriter();
1261 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1262 m.setGroupId( metadata.getGroupId() );
1263 m.setArtifactId( metadata.getArtifactId() );
1265 if ( expectedProxyVersions != null )
1267 m.getAvailableVersions().addAll( Arrays.asList( expectedProxyVersions ) );
1270 m.setModelEncoding( null );
1271 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1273 // Compare the file to the actual contents.
1274 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1278 * Ensures that the repository specific maven metadata file exists, and contains the appropriate
1279 * list of expected versions within.
1281 * @param proxiedRepoId
1282 * @param requestedResource
1284 private void assertRepoReleaseMetadataContents( String proxiedRepoId, String requestedResource )
1287 String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
1289 File actualFile = new File( managedDefaultDir, proxiedFile );
1290 assertTrue( "Release metadata for repo should exist: " + actualFile, actualFile.exists() );
1292 VersionedReference metadata = createVersionedReference( requestedResource );
1294 // Build expected metadata XML
1295 StringWriter expectedMetadataXml = new StringWriter();
1296 ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
1297 m.setGroupId( metadata.getGroupId() );
1298 m.setArtifactId( metadata.getArtifactId() );
1299 m.setVersion( metadata.getVersion() );
1300 m.setModelEncoding( null );
1301 RepositoryMetadataWriter.write( m, expectedMetadataXml );
1303 // Compare the file to the actual contents.
1304 assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
1308 * Test for the non-existance of the requestedResource in the default managed repository.
1310 * @param requestedResource the requested resource
1313 private void assertResourceNotFound( String requestedResource )
1316 File actualFile = new File( managedDefaultDir, requestedResource );
1317 assertFalse( "Resource should not exist: " + requestedResource, actualFile.exists() );
1320 protected void setUp()
1325 metadataTools = (MetadataTools) lookup( MetadataTools.class );