1 package org.apache.archiva.maven.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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.policies.*;
22 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
23 import org.apache.archiva.repository.content.LayoutException;
24 import org.apache.archiva.repository.storage.StorageAsset;
25 import org.apache.maven.wagon.ResourceDoesNotExistException;
26 import org.apache.maven.wagon.TransferFailedException;
27 import org.apache.maven.wagon.authorization.AuthorizationException;
28 import org.easymock.EasyMock;
29 import org.junit.Test;
32 import java.io.IOException;
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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 Path 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( Files.exists(expectedFile) );
415 public void testPropagateOnUpdateNotPresentArtifactNotPresent()
418 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
419 Path 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 Path 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( Files.exists(expectedFile) );
450 public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
453 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
454 Path 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 Path 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( Files.exists(expectedFile));
487 public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
490 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
491 Path 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 Path 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( Files.exists(expectedFile));
523 // ------------------------------------------
525 // ------------------------------------------
527 private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy )
529 saveRemoteRepositoryConfig( id, name, "http://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, PolicyOption errorPolicy, PolicyOption errorOnUpdatePolicy )
536 saveRemoteRepositoryConfig( id, name, "http://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 Path setupRepositoriesWithLocalFileNotPresent( String path )
544 setupTestableManagedRepository( path );
546 Path file = managedDefaultDir.resolve( path );
548 assertNotExistsInManagedDefaultRepo( file );
553 private Path setupRepositoriesWithLocalFilePresent( String path )
556 setupTestableManagedRepository( path );
558 Path file = managedDefaultDir.resolve( path );
560 assertTrue( Files.exists(file) );
565 private void simulateGetError( String path, Path expectedFile, Exception throwable )
566 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
568 wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
569 EasyMock.expectLastCall().andThrow(throwable );
572 private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
573 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
575 wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
576 EasyMock.expectLastCall().andThrow( exception );
579 private Path createExpectedTempFile( Path expectedFile )
581 return managedDefaultDir.resolve(expectedFile.getFileName().toString() + ".tmp" ).toAbsolutePath();
584 private void confirmSingleFailure( String path, String id )
585 throws LayoutException
587 confirmFailures( path, new String[]{id} );
590 private void confirmFailures( String path, String[] ids )
591 throws LayoutException
593 wagonMockControl.replay();
595 // Attempt the proxy fetch.
596 StorageAsset downloadedFile = null;
599 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
600 downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
601 layout.getArtifact( path ) );
602 fail( "Proxy should not have succeeded" );
604 catch ( ProxyDownloadException e )
606 assertEquals( ids.length, e.getFailures().size() );
607 for ( String id : ids )
609 assertTrue( e.getFailures().keySet().contains( id ) );
613 wagonMockControl.verify();
615 assertNotDownloaded( downloadedFile );
618 private void confirmSuccess( String path, Path expectedFile, String basedir )
621 StorageAsset downloadedFile = performDownload( path );
623 Path proxied1File = Paths.get( basedir, path );
624 assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
627 private void confirmNotDownloadedNoError( String path )
630 StorageAsset downloadedFile = performDownload( path );
632 assertNotDownloaded( downloadedFile );
635 private StorageAsset performDownload( String path )
636 throws ProxyDownloadException, LayoutException
638 wagonMockControl.replay();
640 // Attempt the proxy fetch.
641 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
643 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
644 layout.getArtifact( path ) );
646 wagonMockControl.verify();
647 return downloadedFile;
650 private static TransferFailedException createTransferException()
652 return new TransferFailedException( "test download exception" );
655 private static ResourceDoesNotExistException createResourceNotFoundException()
657 return new ResourceDoesNotExistException( "test download not found" );