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.maven.archiva.policies.CachedFailuresPolicy;
23 import org.apache.maven.archiva.policies.ChecksumPolicy;
24 import org.apache.maven.archiva.policies.PropagateErrorsDownloadPolicy;
25 import org.apache.maven.archiva.policies.PropagateErrorsOnUpdateDownloadPolicy;
26 import org.apache.maven.archiva.policies.ProxyDownloadException;
27 import org.apache.maven.archiva.policies.ReleasesPolicy;
28 import org.apache.maven.archiva.policies.SnapshotsPolicy;
29 import org.apache.maven.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;
39 * @author Brett Porter
42 public class ErrorHandlingTest
43 extends AbstractProxyTestCase
45 private static final String PATH_IN_BOTH_REMOTES_NOT_LOCAL =
46 "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
48 private static final String PATH_IN_BOTH_REMOTES_AND_LOCAL =
49 "org/apache/maven/test/get-on-multiple-repos/1.0/get-on-multiple-repos-1.0.pom";
51 private static final String ID_MOCKED_PROXIED1 = "badproxied1";
53 private static final String NAME_MOCKED_PROXIED1 = "Bad Proxied 1";
55 private static final String ID_MOCKED_PROXIED2 = "badproxied2";
57 private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2";
59 public void testPropagateErrorImmediatelyWithErrorThenSuccess()
62 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
63 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
65 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
66 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
68 simulateGetError( path, expectedFile, createTransferException() );
70 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
73 public void testPropagateErrorImmediatelyWithNotFoundThenError()
76 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
77 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
79 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
80 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
82 simulateGetError( path, expectedFile, createResourceNotFoundException() );
84 simulateGetError( path, expectedFile, createTransferException() );
86 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
89 public void testPropagateErrorImmediatelyWithSuccessThenError()
92 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
93 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
95 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
97 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
99 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
102 public void testPropagateErrorImmediatelyWithNotFoundThenSuccess()
105 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
106 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
108 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
110 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
112 simulateGetError( path, expectedFile, createResourceNotFoundException() );
114 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
117 public void testPropagateErrorAtEndWithErrorThenSuccess()
120 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
121 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
123 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
125 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
127 simulateGetError( path, expectedFile, createTransferException() );
129 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
132 public void testPropagateErrorAtEndWithSuccessThenError()
135 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
136 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
138 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
140 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
142 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
145 public void testPropagateErrorAtEndWithNotFoundThenError()
148 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
149 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
151 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
153 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
155 simulateGetError( path, expectedFile, createResourceNotFoundException() );
157 simulateGetError( path, expectedFile, createTransferException() );
159 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
162 public void testPropagateErrorAtEndWithErrorThenNotFound()
165 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
166 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
168 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
170 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
172 simulateGetError( path, expectedFile, createTransferException() );
174 simulateGetError( path, expectedFile, createResourceNotFoundException() );
176 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
179 public void testPropagateErrorAtEndWithErrorThenError()
182 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
183 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
185 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
187 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
189 simulateGetError( path, expectedFile, createTransferException() );
191 simulateGetError( path, expectedFile, createTransferException() );
193 confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
196 public void testPropagateErrorAtEndWithNotFoundThenSuccess()
199 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
200 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
202 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
204 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
206 simulateGetError( path, expectedFile, createResourceNotFoundException() );
208 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
211 public void testIgnoreErrorWithErrorThenSuccess()
214 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
215 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
217 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
219 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2 );
221 simulateGetError( path, expectedFile, createTransferException() );
223 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
226 public void testIgnoreErrorWithSuccessThenError()
229 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
230 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
232 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1 );
234 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
236 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
239 public void testIgnoreErrorWithNotFoundThenError()
242 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
243 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
245 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
247 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
249 simulateGetError( path, expectedFile, createResourceNotFoundException() );
251 simulateGetError( path, expectedFile, createTransferException() );
253 confirmNotDownloadedNoError( path );
256 public void testIgnoreErrorWithErrorThenNotFound()
259 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
260 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
262 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
264 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
266 simulateGetError( path, expectedFile, createTransferException() );
268 simulateGetError( path, expectedFile, createResourceNotFoundException() );
270 confirmNotDownloadedNoError( path );
273 public void testIgnoreErrorWithErrorThenError()
276 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
277 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
279 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
281 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
283 simulateGetError( path, expectedFile, createTransferException() );
285 simulateGetError( path, expectedFile, createTransferException() );
287 confirmNotDownloadedNoError( path );
290 public void testPropagateOnUpdateAlwaysArtifactNotPresent()
293 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
294 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
296 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
297 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
298 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
299 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
301 simulateGetError( path, expectedFile, createTransferException() );
303 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
306 public void testPropagateOnUpdateAlwaysArtifactPresent()
309 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
310 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
312 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
313 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
314 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
315 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
317 simulateGetIfNewerError( path, expectedFile, createTransferException() );
319 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
322 public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent()
325 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
326 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
328 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
329 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
330 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
331 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
333 simulateGetError( path, expectedFile, createTransferException() );
334 simulateGetError( path, expectedFile, createTransferException() );
336 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
339 public void testPropagateOnUpdateAlwaysQueueArtifactPresent()
342 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
343 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
345 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
346 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
347 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
348 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
350 simulateGetIfNewerError( path, expectedFile, createTransferException() );
351 simulateGetIfNewerError( path, expectedFile, createTransferException() );
353 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
356 public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent()
359 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
360 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
362 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
363 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
364 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
365 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
367 simulateGetError( path, expectedFile, createTransferException() );
368 simulateGetError( path, expectedFile, createTransferException() );
370 confirmNotDownloadedNoError( path );
373 public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent()
376 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
377 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
379 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
380 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
381 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
382 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
384 simulateGetIfNewerError( path, expectedFile, createTransferException() );
385 simulateGetIfNewerError( path, expectedFile, createTransferException() );
387 confirmNotDownloadedNoError( path );
388 assertTrue( expectedFile.exists() );
391 public void testPropagateOnUpdateNotPresentArtifactNotPresent()
394 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
395 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
397 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
398 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
399 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
400 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
402 simulateGetError( path, expectedFile, createTransferException() );
404 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
407 public void testPropagateOnUpdateNotPresentArtifactPresent()
410 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
411 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
413 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
414 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
415 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
416 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
418 simulateGetIfNewerError( path, expectedFile, createTransferException() );
420 confirmNotDownloadedNoError( path );
421 assertTrue( expectedFile.exists() );
424 public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
427 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
428 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
430 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
431 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
432 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
433 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
435 simulateGetError( path, expectedFile, createTransferException() );
436 simulateGetError( path, expectedFile, createTransferException() );
438 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
441 public void testPropagateOnUpdateNotPresentQueueArtifactPresent()
444 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
445 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
447 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
448 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
449 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
450 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
452 simulateGetIfNewerError( path, expectedFile, createTransferException() );
453 simulateGetIfNewerError( path, expectedFile, createTransferException() );
455 confirmNotDownloadedNoError( path );
456 assertTrue( expectedFile.exists() );
459 public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
462 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
463 File expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
465 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
466 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
467 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
468 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
470 simulateGetError( path, expectedFile, createTransferException() );
471 simulateGetError( path, expectedFile, createTransferException() );
473 confirmNotDownloadedNoError( path );
476 public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent()
479 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
480 File expectedFile = setupRepositoriesWithLocalFilePresent( path );
482 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
483 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
484 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
485 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
487 simulateGetIfNewerError( path, expectedFile, createTransferException() );
488 simulateGetIfNewerError( path, expectedFile, createTransferException() );
490 confirmNotDownloadedNoError( path );
491 assertTrue( expectedFile.exists() );
494 // ------------------------------------------
496 // ------------------------------------------
498 private void createMockedProxyConnector( String id, String name, String errorPolicy )
500 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
501 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
502 CachedFailuresPolicy.NO, errorPolicy );
505 private void createMockedProxyConnector( String id, String name, String errorPolicy, String errorOnUpdatePolicy )
507 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
508 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
509 CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy );
512 private File setupRepositoriesWithLocalFileNotPresent( String path )
515 setupTestableManagedRepository( path );
517 File file = new File( managedDefaultDir, path );
519 assertNotExistsInManagedDefaultRepo( file );
524 private File setupRepositoriesWithLocalFilePresent( String path )
527 setupTestableManagedRepository( path );
529 File file = new File( managedDefaultDir, path );
531 assertTrue( file.exists() );
536 private void simulateGetError( String path, File expectedFile, Exception throwable )
537 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
539 wagonMock.get( path, createExpectedTempFile( expectedFile ) );
540 wagonMockControl.setMatcher(customWagonGetMatcher);
541 wagonMockControl.setThrowable( throwable, 1 );
544 private void simulateGetIfNewerError( String path, File expectedFile, TransferFailedException exception )
545 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
547 wagonMock.getIfNewer( path, createExpectedTempFile( expectedFile ), expectedFile.lastModified() );
548 wagonMockControl.setMatcher(customWagonGetIfNewerMatcher);
549 wagonMockControl.setThrowable( exception, 1 );
552 private File createExpectedTempFile( File expectedFile )
554 return new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ).getAbsoluteFile();
557 private void confirmSingleFailure( String path, String id )
558 throws LayoutException
560 confirmFailures( path, new String[]{id} );
563 private void confirmFailures( String path, String[] ids )
564 throws LayoutException
566 wagonMockControl.replay();
568 // Attempt the proxy fetch.
569 File downloadedFile = null;
572 downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
573 managedDefaultRepository.toArtifactReference( path ) );
574 fail( "Proxy should not have succeeded" );
576 catch ( ProxyDownloadException e )
578 assertEquals( ids.length, e.getFailures().size() );
579 for ( String id : ids )
581 assertTrue( e.getFailures().keySet().contains( id ) );
585 wagonMockControl.verify();
587 assertNotDownloaded( downloadedFile );
590 private void confirmSuccess( String path, File expectedFile, String basedir )
593 File downloadedFile = performDownload( path );
595 File proxied1File = new File( basedir, path );
596 assertFileEquals( expectedFile, downloadedFile, proxied1File );
599 private void confirmNotDownloadedNoError( String path )
602 File downloadedFile = performDownload( path );
604 assertNotDownloaded( downloadedFile );
607 private File performDownload( String path )
608 throws ProxyDownloadException, LayoutException
610 wagonMockControl.replay();
612 // Attempt the proxy fetch.
613 File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
614 managedDefaultRepository.toArtifactReference( path ) );
616 wagonMockControl.verify();
617 return downloadedFile;
620 private static TransferFailedException createTransferException()
622 return new TransferFailedException( "test download exception" );
625 private static ResourceDoesNotExistException createResourceNotFoundException()
627 return new ResourceDoesNotExistException( "test download not found" );