]> source.dussan.org Git - archiva.git/blob
53fb8f36b0eb3f96dd14cc138f4ae5e0445424cd
[archiva.git] /
1 package org.apache.archiva.maven.proxy;
2
3 /*
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
11  *
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
18  * under the License.
19  */
20
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;
30
31 import java.io.File;
32 import java.io.IOException;
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36
37 import static org.junit.Assert.*;
38
39 /**
40  * ErrorHandlingTest
41  *
42  *
43  */
44 public class ErrorHandlingTest
45     extends AbstractProxyTestCase
46 {
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";
49
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";
52
53     private static final String ID_MOCKED_PROXIED1 = "badproxied1";
54
55     private static final String NAME_MOCKED_PROXIED1 = "Bad Proxied 1";
56
57     private static final String ID_MOCKED_PROXIED2 = "badproxied2";
58
59     private static final String NAME_MOCKED_PROXIED2 = "Bad Proxied 2";
60
61     @Test
62     public void testPropagateErrorImmediatelyWithErrorThenSuccess()
63         throws Exception
64     {
65         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
66         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
67
68         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
69         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false );
70
71         simulateGetError( path, expectedFile, createTransferException() );
72
73         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
74     }
75
76     @Test
77     public void testPropagateErrorImmediatelyWithNotFoundThenError()
78         throws Exception
79     {
80         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
81         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
82
83         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
84         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
85
86         simulateGetError( path, expectedFile, createResourceNotFoundException() );
87
88         simulateGetError( path, expectedFile, createTransferException() );
89
90         confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
91     }
92
93     @Test
94     public void testPropagateErrorImmediatelyWithSuccessThenError()
95         throws Exception
96     {
97         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
98         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
99
100         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false );
101
102         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.STOP );
103
104         confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
105     }
106
107     @Test
108     public void testPropagateErrorImmediatelyWithNotFoundThenSuccess()
109         throws Exception
110     {
111         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
112         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
113
114         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
115
116         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
117
118         simulateGetError( path, expectedFile, createResourceNotFoundException() );
119
120         confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
121     }
122
123     @Test
124     public void testPropagateErrorAtEndWithErrorThenSuccess()
125         throws Exception
126     {
127         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
128         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
129
130         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.STOP );
131
132         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
133
134         simulateGetError( path, expectedFile, createTransferException() );
135
136         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
137     }
138
139     @Test
140     public void testPropagateErrorAtEndWithSuccessThenError()
141         throws Exception
142     {
143         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
144         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
145
146         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false  );
147
148         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
149
150         confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
151     }
152
153     @Test
154     public void testPropagateErrorAtEndWithNotFoundThenError()
155         throws Exception
156     {
157         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
158         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
159
160         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
161
162         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
163
164         simulateGetError( path, expectedFile, createResourceNotFoundException() );
165
166         simulateGetError( path, expectedFile, createTransferException() );
167
168         confirmSingleFailure( path, ID_MOCKED_PROXIED2 );
169     }
170
171     @Test
172     public void testPropagateErrorAtEndWithErrorThenNotFound()
173         throws Exception
174     {
175         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
176         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
177
178         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
179
180         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
181
182         simulateGetError( path, expectedFile, createTransferException() );
183
184         simulateGetError( path, expectedFile, createResourceNotFoundException() );
185
186         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
187     }
188
189     @Test
190     public void testPropagateErrorAtEndWithErrorThenError()
191         throws Exception
192     {
193         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
194         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
195
196         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
197
198         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.QUEUE );
199
200         simulateGetError( path, expectedFile, createTransferException() );
201
202         simulateGetError( path, expectedFile, createTransferException() );
203
204         confirmFailures( path, new String[]{ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2} );
205     }
206
207     @Test
208     public void testPropagateErrorAtEndWithNotFoundThenSuccess()
209         throws Exception
210     {
211         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
212         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
213
214         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.QUEUE );
215
216         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
217
218         simulateGetError( path, expectedFile, createResourceNotFoundException() );
219
220         confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
221     }
222
223     @Test
224     public void testIgnoreErrorWithErrorThenSuccess()
225         throws Exception
226     {
227         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
228         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
229
230         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
231
232         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, false  );
233
234         simulateGetError( path, expectedFile, createTransferException() );
235
236         confirmSuccess( path, expectedFile, REPOPATH_PROXIED2 );
237     }
238
239     @Test
240     public void testIgnoreErrorWithSuccessThenError()
241         throws Exception
242     {
243         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
244         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
245
246         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, false  );
247
248         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
249
250         confirmSuccess( path, expectedFile, REPOPATH_PROXIED1 );
251     }
252
253     @Test
254     public void testIgnoreErrorWithNotFoundThenError()
255         throws Exception
256     {
257         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
258         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
259
260         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
261
262         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
263
264         simulateGetError( path, expectedFile, createResourceNotFoundException() );
265
266         simulateGetError( path, expectedFile, createTransferException() );
267
268         confirmNotDownloadedNoError( path );
269     }
270
271     @Test
272     public void testIgnoreErrorWithErrorThenNotFound()
273         throws Exception
274     {
275         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
276         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
277
278         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
279
280         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
281
282         simulateGetError( path, expectedFile, createTransferException() );
283
284         simulateGetError( path, expectedFile, createResourceNotFoundException() );
285
286         confirmNotDownloadedNoError( path );
287     }
288
289     @Test
290     public void testIgnoreErrorWithErrorThenError()
291         throws Exception
292     {
293         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
294         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
295
296         createMockedProxyConnector( ID_MOCKED_PROXIED1, NAME_MOCKED_PROXIED1, PropagateErrorsDownloadPolicy.IGNORE );
297
298         createMockedProxyConnector( ID_MOCKED_PROXIED2, NAME_MOCKED_PROXIED2, PropagateErrorsDownloadPolicy.IGNORE );
299
300         simulateGetError( path, expectedFile, createTransferException() );
301
302         simulateGetError( path, expectedFile, createTransferException() );
303
304         confirmNotDownloadedNoError( path );
305     }
306
307     @Test
308     public void testPropagateOnUpdateAlwaysArtifactNotPresent()
309         throws Exception
310     {
311         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
312         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
313
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 );
318
319         simulateGetError( path, expectedFile, createTransferException() );
320
321         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
322     }
323
324     @Test
325     public void testPropagateOnUpdateAlwaysArtifactPresent()
326         throws Exception
327     {
328         String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
329         Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
330
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 );
335
336         simulateGetIfNewerError( path, expectedFile, createTransferException() );
337
338         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
339     }
340
341     @Test
342     public void testPropagateOnUpdateAlwaysQueueArtifactNotPresent()
343         throws Exception
344     {
345         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
346         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
347
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 );
352
353         simulateGetError( path, expectedFile, createTransferException() );
354         simulateGetError( path, expectedFile, createTransferException() );
355
356         confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
357     }
358
359     @Test
360     public void testPropagateOnUpdateAlwaysQueueArtifactPresent()
361         throws Exception
362     {
363         String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
364         Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
365
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 );
370
371         simulateGetIfNewerError( path, expectedFile, createTransferException() );
372         simulateGetIfNewerError( path, expectedFile, createTransferException() );
373
374         confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
375     }
376
377     @Test
378     public void testPropagateOnUpdateAlwaysIgnoreArtifactNotPresent()
379         throws Exception
380     {
381         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
382         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
383
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 );
388
389         simulateGetError( path, expectedFile, createTransferException() );
390         simulateGetError( path, expectedFile, createTransferException() );
391
392         confirmNotDownloadedNoError( path );
393     }
394
395     @Test
396     public void testPropagateOnUpdateAlwaysIgnoreArtifactPresent()
397         throws Exception
398     {
399         String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
400         Path  expectedFile = setupRepositoriesWithLocalFilePresent( path );
401
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 );
406
407         simulateGetIfNewerError( path, expectedFile, createTransferException() );
408         simulateGetIfNewerError( path, expectedFile, createTransferException() );
409
410         confirmNotDownloadedNoError( path );
411         assertTrue( Files.exists(expectedFile) );
412     }
413
414     @Test
415     public void testPropagateOnUpdateNotPresentArtifactNotPresent()
416         throws Exception
417     {
418         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
419         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
420
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 );
425
426         simulateGetError( path, expectedFile, createTransferException() );
427
428         confirmSingleFailure( path, ID_MOCKED_PROXIED1 );
429     }
430
431     @Test
432     public void testPropagateOnUpdateNotPresentArtifactPresent()
433         throws Exception
434     {
435         String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
436         Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
437
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 );
442
443         simulateGetIfNewerError( path, expectedFile, createTransferException() );
444
445         confirmNotDownloadedNoError( path );
446         assertTrue( Files.exists(expectedFile) );
447     }
448
449     @Test
450     public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
451         throws Exception
452     {
453         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
454         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
455
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 );
460
461         simulateGetError( path, expectedFile, createTransferException() );
462         simulateGetError( path, expectedFile, createTransferException() );
463
464         confirmFailures( path, new String[] { ID_MOCKED_PROXIED1, ID_MOCKED_PROXIED2 } );
465     }
466
467     @Test
468     public void testPropagateOnUpdateNotPresentQueueArtifactPresent()
469         throws Exception
470     {
471         String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
472         Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
473
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 );
478
479         simulateGetIfNewerError( path, expectedFile, createTransferException() );
480         simulateGetIfNewerError( path, expectedFile, createTransferException() );
481
482         confirmNotDownloadedNoError( path );
483         assertTrue( Files.exists(expectedFile));
484     }
485
486     @Test
487     public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
488         throws Exception
489     {
490         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
491         Path expectedFile = setupRepositoriesWithLocalFileNotPresent( path );
492
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 );
497
498         simulateGetError( path, expectedFile, createTransferException() );
499         simulateGetError( path, expectedFile, createTransferException() );
500
501         confirmNotDownloadedNoError( path );
502     }
503
504     @Test
505     public void testPropagateOnUpdateNotPresentIgnoreArtifactPresent()
506         throws Exception
507     {
508         String path = PATH_IN_BOTH_REMOTES_AND_LOCAL;
509         Path expectedFile = setupRepositoriesWithLocalFilePresent( path );
510
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 );
515
516         simulateGetIfNewerError( path, expectedFile, createTransferException() );
517         simulateGetIfNewerError( path, expectedFile, createTransferException() );
518
519         confirmNotDownloadedNoError( path );
520         assertTrue( Files.exists(expectedFile));
521     }
522
523     // ------------------------------------------
524     // HELPER METHODS
525     // ------------------------------------------
526
527     private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy )
528     {
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 );
532     }
533
534     private void createMockedProxyConnector( String id, String name, PolicyOption errorPolicy, PolicyOption errorOnUpdatePolicy )
535     {
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 );
539     }
540
541     private Path setupRepositoriesWithLocalFileNotPresent( String path )
542         throws Exception
543     {
544         setupTestableManagedRepository( path );
545
546         Path file = managedDefaultDir.resolve( path );
547
548         assertNotExistsInManagedDefaultRepo( file );
549
550         return file;
551     }
552
553     private Path setupRepositoriesWithLocalFilePresent( String path )
554         throws Exception
555     {
556         setupTestableManagedRepository( path );
557
558         Path file = managedDefaultDir.resolve( path );
559
560         assertTrue( Files.exists(file) );
561
562         return file;
563     }
564
565     private void simulateGetError( String path, Path expectedFile, Exception throwable )
566         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
567     {
568         wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
569         EasyMock.expectLastCall().andThrow(throwable );
570     }
571
572     private void simulateGetIfNewerError( String path, Path expectedFile, TransferFailedException exception )
573         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException, IOException
574     {
575         wagonMock.getIfNewer( EasyMock.eq( path ), EasyMock.anyObject( File.class ), EasyMock.eq( Files.getLastModifiedTime( expectedFile ).toMillis() ));
576         EasyMock.expectLastCall().andThrow( exception );
577     }
578
579     private Path createExpectedTempFile( Path expectedFile )
580     {
581         return managedDefaultDir.resolve(expectedFile.getFileName().toString() + ".tmp" ).toAbsolutePath();
582     }
583
584     private void confirmSingleFailure( String path, String id )
585         throws LayoutException
586     {
587         confirmFailures( path, new String[]{id} );
588     }
589
590     private void confirmFailures( String path, String[] ids )
591         throws LayoutException
592     {
593         wagonMockControl.replay();
594
595         // Attempt the proxy fetch.
596         StorageAsset downloadedFile = null;
597         try
598         {
599             BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
600             downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
601                 layout.getArtifact( path ) );
602             fail( "Proxy should not have succeeded" );
603         }
604         catch ( ProxyDownloadException e )
605         {
606             assertEquals( ids.length, e.getFailures().size() );
607             for ( String id : ids )
608             {
609                 assertTrue( e.getFailures().keySet().contains( id ) );
610             }
611         }
612
613         wagonMockControl.verify();
614
615         assertNotDownloaded( downloadedFile );
616     }
617
618     private void confirmSuccess( String path, Path expectedFile, String basedir )
619         throws Exception
620     {
621         StorageAsset downloadedFile = performDownload( path );
622
623         Path proxied1File = Paths.get( basedir, path );
624         assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxied1File );
625     }
626
627     private void confirmNotDownloadedNoError( String path )
628         throws Exception
629     {
630         StorageAsset downloadedFile = performDownload( path );
631
632         assertNotDownloaded( downloadedFile );
633     }
634
635     private StorageAsset performDownload( String path )
636         throws ProxyDownloadException, LayoutException
637     {
638         wagonMockControl.replay();
639
640         // Attempt the proxy fetch.
641         BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
642
643         StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(),
644             layout.getArtifact( path ) );
645
646         wagonMockControl.verify();
647         return downloadedFile;
648     }
649
650     private static TransferFailedException createTransferException()
651     {
652         return new TransferFailedException( "test download exception" );
653     }
654
655     private static ResourceDoesNotExistException createResourceNotFoundException()
656     {
657         return new ResourceDoesNotExistException( "test download not found" );
658     }
659 }