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.easymock.EasyMock;
34 import org.junit.Test;
38 import java.io.IOException;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
43 import static org.junit.Assert.*;
50 public class ErrorHandlingTest
51 extends AbstractProxyTestCase
53 private static final String PATH_IN_BOTH_REMOTES_NOT_LOCAL =
54 "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
56 private static final String PATH_IN_BOTH_REMOTES_AND_LOCAL =
57 "org/apache/maven/test/get-on-multiple-repos/1.0/get-on-multiple-repos-1.0.pom";
59 private static final String ID_MOCKED_PROXIED1 = "badproxied1";
61 private static final String NAME_MOCKED_PROXIED1 = "Bad Proxied 1";
63 private static final String ID_MOCKED_PROXIED2 = "badproxied2";
65 private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2";
68 public void testPropagateErrorImmediatelyWithErrorThenSuccess()
71 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
72 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
74 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
75 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
77 simulateGetError( path, expectedFile, createTransferException() );
79 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
83 public void testPropagateErrorImmediatelyWithNotFoundThenError()
86 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
87 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
89 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
90 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
92 simulateGetError( path, expectedFile, createResourceNotFoundException() );
94 simulateGetError( path, expectedFile, createTransferException() );
96 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
100 public void testPropagateErrorImmediatelyWithSuccessThenError()
103 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
104 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
106 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
108 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
110 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
114 public void testPropagateErrorImmediatelyWithNotFoundThenSuccess()
117 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
118 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
120 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
122 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
124 simulateGetError( path, expectedFile, createResourceNotFoundException() );
126 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
130 public void testPropagateErrorAtEndWithErrorThenSuccess()
133 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
134 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
136 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
138 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
140 simulateGetError( path, expectedFile, createTransferException() );
142 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
146 public void testPropagateErrorAtEndWithSuccessThenError()
149 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
150 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
152 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
154 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
156 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
160 public void testPropagateErrorAtEndWithNotFoundThenError()
163 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
164 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
166 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
168 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
170 simulateGetError( path, expectedFile, createResourceNotFoundException() );
172 simulateGetError( path, expectedFile, createTransferException() );
174 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
178 public void testPropagateErrorAtEndWithErrorThenNotFound()
181 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
182 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
184 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
186 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
188 simulateGetError( path, expectedFile, createTransferException() );
190 simulateGetError( path, expectedFile, createResourceNotFoundException() );
192 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
196 public void testPropagateErrorAtEndWithErrorThenError()
199 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
200 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
202 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
204 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
206 simulateGetError( path, expectedFile, createTransferException() );
208 simulateGetError( path, expectedFile, createTransferException() );
210 confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
214 public void testPropagateErrorAtEndWithNotFoundThenSuccess()
217 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
218 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
220 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
222 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
224 simulateGetError( path, expectedFile, createResourceNotFoundException() );
226 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
230 public void testIgnoreErrorWithErrorThenSuccess()
233 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
234 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
236 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
238 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
240 simulateGetError( path, expectedFile, createTransferException() );
242 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
246 public void testIgnoreErrorWithSuccessThenError()
249 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
250 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
252 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
254 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
256 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
260 public void testIgnoreErrorWithNotFoundThenError()
263 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
264 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
266 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
268 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
270 simulateGetError( path, expectedFile, createResourceNotFoundException() );
272 simulateGetError( path, expectedFile, createTransferException() );
274 confirmNotDownloadedNoError( path );
278 public void testIgnoreErrorWithErrorThenNotFound()
281 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
282 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
284 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
286 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
288 simulateGetError( path, expectedFile, createTransferException() );
290 simulateGetError( path, expectedFile, createResourceNotFoundException() );
292 confirmNotDownloadedNoError( path );
296 public void testIgnoreErrorWithErrorThenError()
299 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
300 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
302 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
304 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
306 simulateGetError( path, expectedFile, createTransferException() );
308 simulateGetError( path, expectedFile, createTransferException() );
310 confirmNotDownloadedNoError( path );
314 public void testPropagateOnUpdateAlwaysArtifactNotPresent()
317 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
318 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
320 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
321 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
322 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
323 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
325 simulateGetError( path, expectedFile, createTransferException() );
327 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
331 public void testPropagateOnUpdateAlwaysArtifactPresent()
334 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
335 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
337 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
338 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
339 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
340 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
342 simulateGetIfNewerError( path, expectedFile, createTransferException() );
344 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
348 public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent()
351 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
352 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
354 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
355 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
356 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
357 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
359 simulateGetError( path, expectedFile, createTransferException() );
360 simulateGetError( path, expectedFile, createTransferException() );
362 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
366 public void testPropagateOnUpdateAlwaysQueueArtifactPresent()
369 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
370 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
372 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
373 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
374 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
375 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
377 simulateGetIfNewerError( path, expectedFile, createTransferException() );
378 simulateGetIfNewerError( path, expectedFile, createTransferException() );
380 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
384 public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent()
387 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
388 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
390 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
391 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
392 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
393 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
395 simulateGetError( path, expectedFile, createTransferException() );
396 simulateGetError( path, expectedFile, createTransferException() );
398 confirmNotDownloadedNoError( path );
402 public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent()
405 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
406 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
408 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
409 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
410 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
411 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
413 simulateGetIfNewerError( path, expectedFile, createTransferException() );
414 simulateGetIfNewerError( path, expectedFile, createTransferException() );
416 confirmNotDownloadedNoError( path );
417 assertTrue( Files.exists(expectedFile) );
421 public void testPropagateOnUpdateNotPresentArtifactNotPresent()
424 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
425 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
427 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
428 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
429 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
430 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
432 simulateGetError( path, expectedFile, createTransferException() );
434 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
438 public void testPropagateOnUpdateNotPresentArtifactPresent()
441 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
442 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
444 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
445 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
446 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
447 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
449 simulateGetIfNewerError( path, expectedFile, createTransferException() );
451 confirmNotDownloadedNoError( path );
452 assertTrue( Files.exists(expectedFile) );
456 public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
459 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
460 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
462 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
463 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
464 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
465 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
467 simulateGetError( path, expectedFile, createTransferException() );
468 simulateGetError( path, expectedFile, createTransferException() );
470 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
474 public void testPropagateOnUpdateNotPresentQueueArtifactPresent()
477 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
478 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
480 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
481 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
482 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
483 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
485 simulateGetIfNewerError( path, expectedFile, createTransferException() );
486 simulateGetIfNewerError( path, expectedFile, createTransferException() );
488 confirmNotDownloadedNoError( path );
489 assertTrue( Files.exists(expectedFile));
493 public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
496 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
497 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
499 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
500 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
501 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
502 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
504 simulateGetError( path, expectedFile, createTransferException() );
505 simulateGetError( path, expectedFile, createTransferException() );
507 confirmNotDownloadedNoError( path );
511 public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent()
514 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
515 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
517 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
518 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
519 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
520 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
522 simulateGetIfNewerError( path, expectedFile, createTransferException() );
523 simulateGetIfNewerError( path, expectedFile, createTransferException() );
525 confirmNotDownloadedNoError( path );
526 assertTrue( Files.exists(expectedFile));
529 // ------------------------------------------
531 // ------------------------------------------
533 private void createMockedProxyConnector( String id, String name, String errorPolicy )
535 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
536 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
537 CachedFailuresPolicy.NO, errorPolicy, false );
540 private void createMockedProxyConnector( String id, String name, String errorPolicy, String errorOnUpdatePolicy )
542 saveRemoteRepositoryConfig( id, name, "test://bad.machine.com/repo/", "default" );
543 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
544 CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false );
547 private Path setupRepositoriesWithLocalFileNotPresent( String path )
550 setupTestableManagedRepository( path );
552 Path file = managedDefaultDir.resolve( path );
554 assertNotExistsInManagedDefaultRepo( file );
559 private Path setupRepositoriesWithLocalFilePresent( String path )
562 setupTestableManagedRepository( path );
564 Path file = managedDefaultDir.resolve( path );
566 assertTrue( Files.exists(file) );
571 private void simulateGetError( String path, Path expectedFile, Exception throwable )
572 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
574 wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
575 EasyMock.expectLastCall().andThrow(throwable );
578 private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
579 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
581 wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
582 EasyMock.expectLastCall().andThrow( exception );
585 private Path createExpectedTempFile( Path expectedFile )
587 return managedDefaultDir.resolve(expectedFile.getFileName().toString() + ".tmp" ).toAbsolutePath();
590 private void confirmSingleFailure( String path, String id )
591 throws LayoutException
593 confirmFailures( path, new String[]{id} );
596 private void confirmFailures( String path, String[] ids )
597 throws LayoutException
599 wagonMockControl.replay();
601 // Attempt the proxy fetch.
602 Path downloadedFile = null;
605 downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
606 managedDefaultRepository.toArtifactReference( path ) );
607 fail( "Proxy should not have succeeded" );
609 catch ( ProxyDownloadException e )
611 assertEquals( ids.length, e.getFailures().size() );
612 for ( String id : ids )
614 assertTrue( e.getFailures().keySet().contains( id ) );
618 wagonMockControl.verify();
620 assertNotDownloaded( downloadedFile );
623 private void confirmSuccess( String path, Path expectedFile, String basedir )
626 Path downloadedFile = performDownload( path );
628 Path proxied1File = Paths.get( basedir, path );
629 assertFileEquals( expectedFile, downloadedFile, proxied1File );
632 private void confirmNotDownloadedNoError( String path )
635 Path downloadedFile = performDownload( path );
637 assertNotDownloaded( downloadedFile );
640 private Path performDownload( String path )
641 throws ProxyDownloadException, LayoutException
643 wagonMockControl.replay();
645 // Attempt the proxy fetch.
646 Path downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
647 managedDefaultRepository.toArtifactReference( path ) );
649 wagonMockControl.verify();
650 return downloadedFile;
653 private static TransferFailedException createTransferException()
655 return new TransferFailedException( "test download exception" );
658 private static ResourceDoesNotExistException createResourceNotFoundException()
660 return new ResourceDoesNotExistException( "test download not found" );