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.*;
23 import org.apache.archiva.repository.content.BaseRepositoryContentLayout;
24 import org.apache.archiva.repository.content.LayoutException;
25 import org.apache.archiva.repository.storage.StorageAsset;
26 import org.apache.maven.wagon.ResourceDoesNotExistException;
27 import org.apache.maven.wagon.TransferFailedException;
28 import org.apache.maven.wagon.authorization.AuthorizationException;
29 import org.easymock.EasyMock;
30 import org.junit.Test;
33 import java.io.IOException;
34 import java.nio.file.Files;
35 import java.nio.file.Path;
36 import java.nio.file.Paths;
38 import static org.junit.Assert.*;
45 public class ErrorHandlingTest
46 extends AbstractProxyTestCase
48 private static final String PATH_IN_BOTH_REMOTES_NOT_LOCAL =
49 "org/apache/maven/test/get-in-both-proxies/1.0/get-in-both-proxies-1.0.jar";
51 private static final String PATH_IN_BOTH_REMOTES_AND_LOCAL =
52 "org/apache/maven/test/get-on-multiple-repos/1.0/get-on-multiple-repos-1.0.pom";
54 private static final String ID_MOCKED_PROXIED1 = "badproxied1";
56 private static final String NAME_MOCKED_PROXIED1 = "Bad Proxied 1";
58 private static final String ID_MOCKED_PROXIED2 = "badproxied2";
60 private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2";
63 public void testPropagateErrorImmediatelyWithErrorThenSuccess()
66 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
67 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
69 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
70 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
72 simulateGetError( path, expectedFile, createTransferException() );
74 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
78 public void testPropagateErrorImmediatelyWithNotFoundThenError()
81 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
82 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
84 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
85 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
87 simulateGetError( path, expectedFile, createResourceNotFoundException() );
89 simulateGetError( path, expectedFile, createTransferException() );
91 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
95 public void testPropagateErrorImmediatelyWithSuccessThenError()
98 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
99 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
101 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
103 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
105 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
109 public void testPropagateErrorImmediatelyWithNotFoundThenSuccess()
112 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
113 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
115 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
117 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
119 simulateGetError( path, expectedFile, createResourceNotFoundException() );
121 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
125 public void testPropagateErrorAtEndWithErrorThenSuccess()
128 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
129 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
131 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
133 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
135 simulateGetError( path, expectedFile, createTransferException() );
137 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
141 public void testPropagateErrorAtEndWithSuccessThenError()
144 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
145 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
147 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
149 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
151 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
155 public void testPropagateErrorAtEndWithNotFoundThenError()
158 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
159 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
161 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
163 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
165 simulateGetError( path, expectedFile, createResourceNotFoundException() );
167 simulateGetError( path, expectedFile, createTransferException() );
169 confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
173 public void testPropagateErrorAtEndWithErrorThenNotFound()
176 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
177 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
179 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
181 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
183 simulateGetError( path, expectedFile, createTransferException() );
185 simulateGetError( path, expectedFile, createResourceNotFoundException() );
187 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
191 public void testPropagateErrorAtEndWithErrorThenError()
194 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
195 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
197 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
199 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
201 simulateGetError( path, expectedFile, createTransferException() );
203 simulateGetError( path, expectedFile, createTransferException() );
205 confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
209 public void testPropagateErrorAtEndWithNotFoundThenSuccess()
212 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
213 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
215 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
217 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
219 simulateGetError( path, expectedFile, createResourceNotFoundException() );
221 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
225 public void testIgnoreErrorWithErrorThenSuccess()
228 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
229 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
231 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
233 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
235 simulateGetError( path, expectedFile, createTransferException() );
237 confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
241 public void testIgnoreErrorWithSuccessThenError()
244 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
245 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
247 saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
249 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
251 confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
255 public void testIgnoreErrorWithNotFoundThenError()
258 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
259 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
261 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
263 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
265 simulateGetError( path, expectedFile, createResourceNotFoundException() );
267 simulateGetError( path, expectedFile, createTransferException() );
269 confirmNotDownloadedNoError( path );
273 public void testIgnoreErrorWithErrorThenNotFound()
276 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
277 Path 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, createResourceNotFoundException() );
287 confirmNotDownloadedNoError( path );
291 public void testIgnoreErrorWithErrorThenError()
294 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
295 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
297 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
299 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
301 simulateGetError( path, expectedFile, createTransferException() );
303 simulateGetError( path, expectedFile, createTransferException() );
305 confirmNotDownloadedNoError( path );
309 public void testPropagateOnUpdateAlwaysArtifactNotPresent()
312 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
313 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
315 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
316 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
317 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
318 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
320 simulateGetError( path, expectedFile, createTransferException() );
322 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
326 public void testPropagateOnUpdateAlwaysArtifactPresent()
329 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
330 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
332 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
333 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
334 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
335 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
337 simulateGetIfNewerError( path, expectedFile, createTransferException() );
339 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
343 public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent()
346 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
347 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
349 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
350 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
351 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
352 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
354 simulateGetError( path, expectedFile, createTransferException() );
355 simulateGetError( path, expectedFile, createTransferException() );
357 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
361 public void testPropagateOnUpdateAlwaysQueueArtifactPresent()
364 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
365 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
367 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
368 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
369 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
370 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
372 simulateGetIfNewerError( path, expectedFile, createTransferException() );
373 simulateGetIfNewerError( path, expectedFile, createTransferException() );
375 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
379 public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent()
382 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
383 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
385 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
386 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
387 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
388 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
390 simulateGetError( path, expectedFile, createTransferException() );
391 simulateGetError( path, expectedFile, createTransferException() );
393 confirmNotDownloadedNoError( path );
397 public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent()
400 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
401 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
403 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
404 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
405 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
406 PropagateErrorsOnUpdateDownloadPolicy.ALWAYS );
408 simulateGetIfNewerError( path, expectedFile, createTransferException() );
409 simulateGetIfNewerError( path, expectedFile, createTransferException() );
411 confirmNotDownloadedNoError( path );
412 assertTrue( Files.exists(expectedFile) );
416 public void testPropagateOnUpdateNotPresentArtifactNotPresent()
419 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
420 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
422 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
423 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
424 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
425 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
427 simulateGetError( path, expectedFile, createTransferException() );
429 confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
433 public void testPropagateOnUpdateNotPresentArtifactPresent()
436 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
437 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
439 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP,
440 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
441 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP,
442 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
444 simulateGetIfNewerError( path, expectedFile, createTransferException() );
446 confirmNotDownloadedNoError( path );
447 assertTrue( Files.exists(expectedFile) );
451 public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
454 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
455 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
457 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
458 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
459 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
460 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
462 simulateGetError( path, expectedFile, createTransferException() );
463 simulateGetError( path, expectedFile, createTransferException() );
465 confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
469 public void testPropagateOnUpdateNotPresentQueueArtifactPresent()
472 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
473 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
475 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE,
476 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
477 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE,
478 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
480 simulateGetIfNewerError( path, expectedFile, createTransferException() );
481 simulateGetIfNewerError( path, expectedFile, createTransferException() );
483 confirmNotDownloadedNoError( path );
484 assertTrue( Files.exists(expectedFile));
488 public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
491 String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
492 Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
494 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
495 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
496 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
497 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
499 simulateGetError( path, expectedFile, createTransferException() );
500 simulateGetError( path, expectedFile, createTransferException() );
502 confirmNotDownloadedNoError( path );
506 public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent()
509 String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
510 Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
512 createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE,
513 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
514 createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE,
515 PropagateErrorsOnUpdateDownloadPolicy.NOT_PRESENT );
517 simulateGetIfNewerError( path, expectedFile, createTransferException() );
518 simulateGetIfNewerError( path, expectedFile, createTransferException() );
520 confirmNotDownloadedNoError( path );
521 assertTrue( Files.exists(expectedFile));
524 // ------------------------------------------
526 // ------------------------------------------
528 private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy )
530 saveRemoteRepositoryConfig( id, name, "http://bad.machine.com/repo/", "default" );
531 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
532 CachedFailuresPolicy.NO, errorPolicy, false );
535 private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy, PolicyOption errorOnUpdatePolicy )
537 saveRemoteRepositoryConfig( id, name, "http://bad.machine.com/repo/", "default" );
538 saveConnector( ID_DEFAULT_MANAGED, id, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS,
539 CachedFailuresPolicy.NO, errorPolicy, errorOnUpdatePolicy, false );
542 private Path setupRepositoriesWithLocalFileNotPresent( String path )
545 setupTestableManagedRepository( path );
547 Path file = managedDefaultDir.resolve( path );
549 assertNotExistsInManagedDefaultRepo( file );
554 private Path setupRepositoriesWithLocalFilePresent( String path )
557 setupTestableManagedRepository( path );
559 Path file = managedDefaultDir.resolve( path );
561 assertTrue( Files.exists(file) );
566 private void simulateGetError( String path, Path expectedFile, Exception throwable )
567 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
569 wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
570 EasyMock.expectLastCall().andThrow(throwable );
573 private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
574 throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
576 wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
577 EasyMock.expectLastCall().andThrow( exception );
580 private Path createExpectedTempFile( Path expectedFile )
582 return managedDefaultDir.resolve(expectedFile.getFileName().toString() + ".tmp" ).toAbsolutePath();
585 private void confirmSingleFailure( String path, String id )
586 throws LayoutException
588 confirmFailures( path, new String[]{id} );
591 private void confirmFailures( String path, String[] ids )
592 throws LayoutException
594 wagonMockControl.replay();
596 // Attempt the proxy fetch.
597 StorageAsset downloadedFile = null;
600 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
601 downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
602 layout.getArtifact( 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, Path expectedFile, String basedir )
622 StorageAsset downloadedFile = performDownload( path );
624 Path proxied1File = Paths.get( basedir, path );
625 assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
628 private void confirmNotDownloadedNoError( String path )
631 StorageAsset downloadedFile = performDownload( path );
633 assertNotDownloaded( downloadedFile );
636 private StorageAsset performDownload( String path )
637 throws ProxyDownloadException, LayoutException
639 wagonMockControl.replay();
641 // Attempt the proxy fetch.
642 BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
644 StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
645 layout.getArtifact( path ) );
647 wagonMockControl.verify();
648 return downloadedFile;
651 private static TransferFailedException createTransferException()
653 return new TransferFailedException( "test download exception" );
656 private static ResourceDoesNotExistException createResourceNotFoundException()
658 return new ResourceDoesNotExistException( "test download not found" );