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.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.easymock.EasyMock;
34 import org.junit.Test;
37 import java.io.IOException;
38 import java.nio.file.Files;
39 import java.nio.file.Path;
40 import java.nio.file.Paths;
42 import static org.junit.Assert.*;
49 public class ErrorHandlingTest
50 extends AbstractProxyTestCase
52 private static final String PATH_IN_BOTH_REMOTES_NOT_LOCAL =
53 "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
55 private static final String PATH_IN_BOTH_REMOTES_AND_LOCAL =
56 "org/apache/maven/test/get-on-multiple-repos/1.0/get-on-multiple-repos-1.0.pom";
58 private static final String ID_MOCKED_PROXIED1 = "badproxied1";
60 private static final String NAME_MOCKED_PROXIED1 = "Bad Proxied 1";
62 private static final String ID_MOCKED_PROXIED2 = "badproxied2";
64 private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2";
67 public void testPropagateErrorImmediatelyWithErrorThenSuccess()
70 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
71 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
73 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
74 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
76 simulateGetError( path, expectedFile, createTransferException() );
78 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
82 public void testPropagateErrorImmediatelyWithNotFoundThenError()
85 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
86 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
88 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
89 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
91 simulateGetError( path, expectedFile, createResourceNotFoundException() );
93 simulateGetError( path, expectedFile, createTransferException() );
95 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
99 public void testPropagateErrorImmediatelyWithSuccessThenError()
102 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
103 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
105 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
107 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
109 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
113 public void testPropagateErrorImmediatelyWithNotFoundThenSuccess()
116 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
117 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
119 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
121 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
123 simulateGetError( path, expectedFile, createResourceNotFoundException() );
125 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
129 public void testPropagateErrorAtEndWithErrorThenSuccess()
132 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
133 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
135 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
137 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
139 simulateGetError( path, expectedFile, createTransferException() );
141 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
145 public void testPropagateErrorAtEndWithSuccessThenError()
148 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
149 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
151 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
153 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
155 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
159 public void testPropagateErrorAtEndWithNotFoundThenError()
162 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
163 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
165 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
167 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
169 simulateGetError( path, expectedFile, createResourceNotFoundException() );
171 simulateGetError( path, expectedFile, createTransferException() );
173 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
177 public void testPropagateErrorAtEndWithErrorThenNotFound()
180 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
181 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
183 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
185 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
187 simulateGetError( path, expectedFile, createTransferException() );
189 simulateGetError( path, expectedFile, createResourceNotFoundException() );
191 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
195 public void testPropagateErrorAtEndWithErrorThenError()
198 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
199 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
201 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
203 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
205 simulateGetError( path, expectedFile, createTransferException() );
207 simulateGetError( path, expectedFile, createTransferException() );
209 confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
213 public void testPropagateErrorAtEndWithNotFoundThenSuccess()
216 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
217 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
219 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
221 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
223 simulateGetError( path, expectedFile, createResourceNotFoundException() );
225 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
229 public void testIgnoreErrorWithErrorThenSuccess()
232 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
233 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
235 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
237 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
239 simulateGetError( path, expectedFile, createTransferException() );
241 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
245 public void testIgnoreErrorWithSuccessThenError()
248 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
249 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
251 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
253 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
255 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
259 public void testIgnoreErrorWithNotFoundThenError()
262 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
263 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
265 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
267 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
269 simulateGetError( path, expectedFile, createResourceNotFoundException() );
271 simulateGetError( path, expectedFile, createTransferException() );
273 confirmNotDownloadedNoError( path );
277 public void testIgnoreErrorWithErrorThenNotFound()
280 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
281 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
283 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
285 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
287 simulateGetError( path, expectedFile, createTransferException() );
289 simulateGetError( path, expectedFile, createResourceNotFoundException() );
291 confirmNotDownloadedNoError( path );
295 public void testIgnoreErrorWithErrorThenError()
298 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
299 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
301 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
303 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
305 simulateGetError( path, expectedFile, createTransferException() );
307 simulateGetError( path, expectedFile, createTransferException() );
309 confirmNotDownloadedNoError( path );
313 public void testPropagateOnUpdateAlwaysArtifactNotPresent()
316 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
317 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
319 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
320 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
321 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
322 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
324 simulateGetError( path, expectedFile, createTransferException() );
326 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
330 public void testPropagateOnUpdateAlwaysArtifactPresent()
333 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
334 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
336 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
337 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
338 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
339 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
341 simulateGetIfNewerError( path, expectedFile, createTransferException() );
343 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
347 public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent()
350 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
351 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
353 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
354 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
355 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
356 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
358 simulateGetError( path, expectedFile, createTransferException() );
359 simulateGetError( path, expectedFile, createTransferException() );
361 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
365 public void testPropagateOnUpdateAlwaysQueueArtifactPresent()
368 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
369 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
371 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
372 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
373 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
374 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
376 simulateGetIfNewerError( path, expectedFile, createTransferException() );
377 simulateGetIfNewerError( path, expectedFile, createTransferException() );
379 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
383 public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent()
386 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
387 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
389 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
390 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
391 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
392 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
394 simulateGetError( path, expectedFile, createTransferException() );
395 simulateGetError( path, expectedFile, createTransferException() );
397 confirmNotDownloadedNoError( path );
401 public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent()
404 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
405 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
407 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
408 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
409 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
410 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
412 simulateGetIfNewerError( path, expectedFile, createTransferException() );
413 simulateGetIfNewerError( path, expectedFile, createTransferException() );
415 confirmNotDownloadedNoError( path );
416 assertTrue( Files.exists(expectedFile) );
420 public void testPropagateOnUpdateNotPresentArtifactNotPresent()
423 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
424 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
426 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
427 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
428 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
429 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
431 simulateGetError( path, expectedFile, createTransferException() );
433 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
437 public void testPropagateOnUpdateNotPresentArtifactPresent()
440 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
441 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
443 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
444 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
445 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
446 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
448 simulateGetIfNewerError( path, expectedFile, createTransferException() );
450 confirmNotDownloadedNoError( path );
451 assertTrue( Files.exists(expectedFile) );
455 public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
458 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
459 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
461 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
462 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
463 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
464 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
466 simulateGetError( path, expectedFile, createTransferException() );
467 simulateGetError( path, expectedFile, createTransferException() );
469 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
473 public void testPropagateOnUpdateNotPresentQueueArtifactPresent()
476 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
477 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
479 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
480 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
481 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
482 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
484 simulateGetIfNewerError( path, expectedFile, createTransferException() );
485 simulateGetIfNewerError( path, expectedFile, createTransferException() );
487 confirmNotDownloadedNoError( path );
488 assertTrue( Files.exists(expectedFile));
492 public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
495 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
496 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
498 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
499 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
500 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
501 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
503 simulateGetError( path, expectedFile, createTransferException() );
504 simulateGetError( path, expectedFile, createTransferException() );
506 confirmNotDownloadedNoError( path );
510 public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent()
513 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
514 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
516 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
517 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
518 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
519 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
521 simulateGetIfNewerError( path, expectedFile, createTransferException() );
522 simulateGetIfNewerError( path, expectedFile, createTransferException() );
524 confirmNotDownloadedNoError( path );
525 assertTrue( Files.exists(expectedFile));
528 // ------------------------------------------
530 // ------------------------------------------
532 private void createMockedProxyConnector( String id, String name, String errorPolicy )
534 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
535 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
536 CachedFailuresPolicy.NO, errorPolicy, false );
539 private void createMockedProxyConnector( String id, String name, String errorPolicy, String errorOnUpdatePolicy )
541 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
542 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
543 CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false );
546 private Path setupRepositoriesWithLocalFileNotPresent( String path )
549 setupTestableManagedRepository( path );
551 Path file = managedDefaultDir.resolve( path );
553 assertNotExistsInManagedDefaultRepo( file );
558 private Path setupRepositoriesWithLocalFilePresent( String path )
561 setupTestableManagedRepository( path );
563 Path file = managedDefaultDir.resolve( path );
565 assertTrue( Files.exists(file) );
570 private void simulateGetError( String path, Path expectedFile, Exception throwable )
571 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
573 wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
574 EasyMock.expectLastCall().andThrow(throwable );
577 private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
578 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
580 wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
581 EasyMock.expectLastCall().andThrow( exception );
584 private Path createExpectedTempFile( Path expectedFile )
586 return managedDefaultDir.resolve(expectedFile.getFileName().toString() + ".tmp" ).toAbsolutePath();
589 private void confirmSingleFailure( String path, String id )
590 throws LayoutException
592 confirmFailures( path, new String[]{id} );
595 private void confirmFailures( String path, String[] ids )
596 throws LayoutException
598 wagonMockControl.replay();
600 // Attempt the proxy fetch.
601 Path downloadedFile = null;
604 downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
605 managedDefaultRepository.toArtifactReference( path ) );
606 fail( "Proxy should not have succeeded" );
608 catch ( ProxyDownloadException e )
610 assertEquals( ids.length, e.getFailures().size() );
611 for ( String id : ids )
613 assertTrue( e.getFailures().keySet().contains( id ) );
617 wagonMockControl.verify();
619 assertNotDownloaded( downloadedFile );
622 private void confirmSuccess( String path, Path expectedFile, String basedir )
625 Path downloadedFile = performDownload( path );
627 Path proxied1File = Paths.get( basedir, path );
628 assertFileEquals( expectedFile, downloadedFile, proxied1File );
631 private void confirmNotDownloadedNoError( String path )
634 Path downloadedFile = performDownload( path );
636 assertNotDownloaded( downloadedFile );
639 private Path performDownload( String path )
640 throws ProxyDownloadException, LayoutException
642 wagonMockControl.replay();
644 // Attempt the proxy fetch.
645 Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
646 managedDefaultRepository.toArtifactReference( path ) );
648 wagonMockControl.verify();
649 return downloadedFile;
652 private static TransferFailedException createTransferException()
654 return new TransferFailedException( "test download exception" );
657 private static ResourceDoesNotExistException createResourceNotFoundException()
659 return new ResourceDoesNotExistException( "test download not found" );