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.policies.CachedFailuresPolicy;
23 import org.apache.archiva.policies.ChecksumPolicy;
24 import org.apache.archiva.policies.PropagateErrorsDownloadPolicy;
25 import org.apache.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy;
26 import org.apache.archiva.policies.ProxyDownloadException;
27 import org.apache.archiva.policies.ReleasesPolicy;
28 import org.apache.archiva.policies.SnapshotsPolicy;
29 import org.apache.archiva.repository.layout.LayoutException;
30 import org.apache.maven.wagon.ResourceDoesNotExistException;
31 import org.apache.maven.wagon.TransferFailedException;
32 import org.apache.maven.wagon.authorization.AuthorizationException;
33 import org.junit.Test;
37 import static org.junit.Assert.*;
44 public class ErrorHandlingTest
45 extends AbstractProxyTestCase
47 private static final String PATH_IN_BOTH_REMOTES_NOT_LOCAL =
48 "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
50 private static final String PATH_IN_BOTH_REMOTES_AND_LOCAL =
51 "org/apache/maven/test/get-on-multiple-repos/1.0/get-on-multiple-repos-1.0.pom";
53 private static final String ID_MOCKED_PROXIED1 = "badproxied1";
55 private static final String NAME_MOCKED_PROXIED1 = "Bad Proxied 1";
57 private static final String ID_MOCKED_PROXIED2 = "badproxied2";
59 private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2";
62 public void testPropagateErrorImmediatelyWithErrorThenSuccess()
65 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
66 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
68 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
69 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
71 simulateGetError( path, expectedFile, createTransferException() );
73 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
77 public void testPropagateErrorImmediatelyWithNotFoundThenError()
80 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
81 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
83 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
84 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
86 simulateGetError( path, expectedFile, createResourceNotFoundException() );
88 simulateGetError( path, expectedFile, createTransferException() );
90 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
94 public void testPropagateErrorImmediatelyWithSuccessThenError()
97 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
98 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
100 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
102 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
104 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
108 public void testPropagateErrorImmediatelyWithNotFoundThenSuccess()
111 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
112 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
114 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
116 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
118 simulateGetError( path, expectedFile, createResourceNotFoundException() );
120 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
124 public void testPropagateErrorAtEndWithErrorThenSuccess()
127 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
128 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
130 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
132 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
134 simulateGetError( path, expectedFile, createTransferException() );
136 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
140 public void testPropagateErrorAtEndWithSuccessThenError()
143 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
144 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
146 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
148 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
150 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
154 public void testPropagateErrorAtEndWithNotFoundThenError()
157 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
158 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
160 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
162 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
164 simulateGetError( path, expectedFile, createResourceNotFoundException() );
166 simulateGetError( path, expectedFile, createTransferException() );
168 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
172 public void testPropagateErrorAtEndWithErrorThenNotFound()
175 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
176 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
178 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
180 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
182 simulateGetError( path, expectedFile, createTransferException() );
184 simulateGetError( path, expectedFile, createResourceNotFoundException() );
186 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
190 public void testPropagateErrorAtEndWithErrorThenError()
193 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
194 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
196 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
198 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
200 simulateGetError( path, expectedFile, createTransferException() );
202 simulateGetError( path, expectedFile, createTransferException() );
204 confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
208 public void testPropagateErrorAtEndWithNotFoundThenSuccess()
211 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
212 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
214 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
216 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
218 simulateGetError( path, expectedFile, createResourceNotFoundException() );
220 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
224 public void testIgnoreErrorWithErrorThenSuccess()
227 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
228 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
230 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
232 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
234 simulateGetError( path, expectedFile, createTransferException() );
236 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
240 public void testIgnoreErrorWithSuccessThenError()
243 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
244 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
246 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
248 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
250 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
254 public void testIgnoreErrorWithNotFoundThenError()
257 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
258 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
260 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
262 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
264 simulateGetError( path, expectedFile, createResourceNotFoundException() );
266 simulateGetError( path, expectedFile, createTransferException() );
268 confirmNotDownloadedNoError( path );
272 public void testIgnoreErrorWithErrorThenNotFound()
275 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
276 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
278 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
280 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
282 simulateGetError( path, expectedFile, createTransferException() );
284 simulateGetError( path, expectedFile, createResourceNotFoundException() );
286 confirmNotDownloadedNoError( path );
290 public void testIgnoreErrorWithErrorThenError()
293 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
294 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
296 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
298 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
300 simulateGetError( path, expectedFile, createTransferException() );
302 simulateGetError( path, expectedFile, createTransferException() );
304 confirmNotDownloadedNoError( path );
308 public void testPropagateOnUpdateAlwaysArtifactNotPresent()
311 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
312 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
314 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
315 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
316 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
317 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
319 simulateGetError( path, expectedFile, createTransferException() );
321 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
325 public void testPropagateOnUpdateAlwaysArtifactPresent()
328 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
329 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
331 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
332 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
333 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
334 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
336 simulateGetIfNewerError( path, expectedFile, createTransferException() );
338 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
342 public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent()
345 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
346 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
348 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
349 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
350 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
351 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
353 simulateGetError( path, expectedFile, createTransferException() );
354 simulateGetError( path, expectedFile, createTransferException() );
356 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
360 public void testPropagateOnUpdateAlwaysQueueArtifactPresent()
363 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
364 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
366 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
367 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
368 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
369 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
371 simulateGetIfNewerError( path, expectedFile, createTransferException() );
372 simulateGetIfNewerError( path, expectedFile, createTransferException() );
374 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
378 public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent()
381 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
382 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
384 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
385 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
386 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
387 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
389 simulateGetError( path, expectedFile, createTransferException() );
390 simulateGetError( path, expectedFile, createTransferException() );
392 confirmNotDownloadedNoError( path );
396 public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent()
399 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
400 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
402 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
403 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
404 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
405 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
407 simulateGetIfNewerError( path, expectedFile, createTransferException() );
408 simulateGetIfNewerError( path, expectedFile, createTransferException() );
410 confirmNotDownloadedNoError( path );
411 assertTrue( expectedFile.exists() );
415 public void testPropagateOnUpdateNotPresentArtifactNotPresent()
418 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
419 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
421 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
422 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
423 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
424 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
426 simulateGetError( path, expectedFile, createTransferException() );
428 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
432 public void testPropagateOnUpdateNotPresentArtifactPresent()
435 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
436 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
438 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
439 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
440 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
441 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
443 simulateGetIfNewerError( path, expectedFile, createTransferException() );
445 confirmNotDownloadedNoError( path );
446 assertTrue( expectedFile.exists() );
450 public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
453 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
454 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
456 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
457 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
458 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
459 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
461 simulateGetError( path, expectedFile, createTransferException() );
462 simulateGetError( path, expectedFile, createTransferException() );
464 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
468 public void testPropagateOnUpdateNotPresentQueueArtifactPresent()
471 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
472 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
474 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
475 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
476 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
477 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
479 simulateGetIfNewerError( path, expectedFile, createTransferException() );
480 simulateGetIfNewerError( path, expectedFile, createTransferException() );
482 confirmNotDownloadedNoError( path );
483 assertTrue( expectedFile.exists() );
487 public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
490 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
491 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
493 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
494 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
495 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
496 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
498 simulateGetError( path, expectedFile, createTransferException() );
499 simulateGetError( path, expectedFile, createTransferException() );
501 confirmNotDownloadedNoError( path );
505 public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent()
508 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
509 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
511 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
512 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
513 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
514 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
516 simulateGetIfNewerError( path, expectedFile, createTransferException() );
517 simulateGetIfNewerError( path, expectedFile, createTransferException() );
519 confirmNotDownloadedNoError( path );
520 assertTrue( expectedFile.exists() );
523 // ------------------------------------------
525 // ------------------------------------------
527 private void createMockedProxyConnector( String id, String name, String errorPolicy )
529 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
530 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
531 CachedFailuresPolicy.NO, errorPolicy, false );
534 private void createMockedProxyConnector( String id, String name, String errorPolicy, String errorOnUpdatePolicy )
536 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
537 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
538 CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false );
541 private File setupRepositoriesWithLocalFileNotPresent( String path )
544 setupTestableManagedRepository( path );
546 File file = new File( managedDefaultDir, path );
548 assertNotExistsInManagedDefaultRepo( file );
553 private File setupRepositoriesWithLocalFilePresent( String path )
556 setupTestableManagedRepository( path );
558 File file = new File( managedDefaultDir, path );
560 assertTrue( file.exists() );
565 private void simulateGetError( String path, File expectedFile, Exception throwable )
566 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
568 wagonMock.get( path, createExpectedTempFile( expectedFile ) );
569 wagonMockControl.setMatcher(customWagonGetMatcher);
570 wagonMockControl.setThrowable( throwable, 1 );
573 private void simulateGetIfNewerError( String path, File expectedFile, TransferFailedException exception )
574 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
576 wagonMock.getIfNewer( path, createExpectedTempFile( expectedFile ), expectedFile.lastModified() );
577 wagonMockControl.setMatcher(customWagonGetIfNewerMatcher);
578 wagonMockControl.setThrowable( exception, 1 );
581 private File createExpectedTempFile( File expectedFile )
583 return new File( managedDefaultDir, expectedFile.getName() + ".tmp" ).getAbsoluteFile();
586 private void confirmSingleFailure( String path, String id )
587 throws LayoutException
589 confirmFailures( path, new String[]{id} );
592 private void confirmFailures( String path, String[] ids )
593 throws LayoutException
595 wagonMockControl.replay();
597 // Attempt the proxy fetch.
598 File downloadedFile = null;
601 downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
602 managedDefaultRepository.toArtifactReference( path ) );
603 fail( "Proxy should not have succeeded" );
605 catch ( ProxyDownloadException e )
607 assertEquals( ids.length, e.getFailures().size() );
608 for ( String id : ids )
610 assertTrue( e.getFailures().keySet().contains( id ) );
614 wagonMockControl.verify();
616 assertNotDownloaded( downloadedFile );
619 private void confirmSuccess( String path, File expectedFile, String basedir )
622 File downloadedFile = performDownload( path );
624 File proxied1File = new File( basedir, path );
625 assertFileEquals( expectedFile, downloadedFile, proxied1File );
628 private void confirmNotDownloadedNoError( String path )
631 File downloadedFile = performDownload( path );
633 assertNotDownloaded( downloadedFile );
636 private File performDownload( String path )
637 throws ProxyDownloadException, LayoutException
639 wagonMockControl.replay();
641 // Attempt the proxy fetch.
642 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
643 managedDefaultRepository.toArtifactReference( path ) );
645 wagonMockControl.verify();
646 return downloadedFile;
649 private static TransferFailedException createTransferException()
651 return new TransferFailedException( "test download exception" );
654 private static ResourceDoesNotExistException createResourceNotFoundException()
656 return new ResourceDoesNotExistException( "test download not found" );