]> source.dussan.org Git - archiva.git/blob
67ee566c9e97bcb04d41dd99c0630913070a1130
[archiva.git] /
1 package org.apache.archiva.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  *
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
19  * under the License.
20  */
21
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.junit.Test;
34
35 import java.io.File;
36
37 import static org.junit.Assert.*;
38
39 /**
40  * ErrorHandlingTest
41  *
42  * @version $Id$
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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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         File 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( expectedFile.exists() );
412     }
413
414     @Test
415     public void testPropagateOnUpdateNotPresentArtifactNotPresent()
416         throws Exception
417     {
418         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
419         File 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         File 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( expectedFile.exists() );
447     }
448
449     @Test
450     public void testPropagateOnUpdateNotPresentQueueArtifactNotPresent()
451         throws Exception
452     {
453         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
454         File 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         File 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( expectedFile.exists() );
484     }
485
486     @Test
487     public void testPropagateOnUpdateNotPresentIgnoreArtifactNotPresent()
488         throws Exception
489     {
490         String path = PATH_IN_BOTH_REMOTES_NOT_LOCAL;
491         File 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         File 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( expectedFile.exists() );
521     }
522
523     // ------------------------------------------
524     // HELPER METHODS
525     // ------------------------------------------
526
527     private void createMockedProxyConnector( String id, String name, String errorPolicy )
528     {
529         saveRemoteRepositoryConfig( id, name, "test://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, String errorPolicy, String errorOnUpdatePolicy )
535     {
536         saveRemoteRepositoryConfig( id, name, "test://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 File setupRepositoriesWithLocalFileNotPresent( String path )
542         throws Exception
543     {
544         setupTestableManagedRepository( path );
545
546         File file = new File( managedDefaultDir, path );
547
548         assertNotExistsInManagedDefaultRepo( file );
549
550         return file;
551     }
552
553     private File setupRepositoriesWithLocalFilePresent( String path )
554         throws Exception
555     {
556         setupTestableManagedRepository( path );
557
558         File file = new File( managedDefaultDir, path );
559
560         assertTrue( file.exists() );
561
562         return file;
563     }
564
565     private void simulateGetError( String path, File expectedFile, Exception throwable )
566         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
567     {
568         wagonMock.get( path, createExpectedTempFile( expectedFile ) );
569         wagonMockControl.setMatcher(customWagonGetMatcher);
570         wagonMockControl.setThrowable( throwable, 1 );
571     }
572
573     private void simulateGetIfNewerError( String path, File expectedFile, TransferFailedException exception )
574         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
575     {
576         wagonMock.getIfNewer( path, createExpectedTempFile( expectedFile ), expectedFile.lastModified() );
577         wagonMockControl.setMatcher(customWagonGetIfNewerMatcher);
578         wagonMockControl.setThrowable( exception, 1 );
579     }
580
581     private File createExpectedTempFile( File expectedFile )
582     {
583         return new File( managedDefaultDir, expectedFile.getName() + ".tmp" ).getAbsoluteFile();
584     }
585
586     private void confirmSingleFailure( String path, String id )
587         throws LayoutException
588     {
589         confirmFailures( path, new String[]{id} );
590     }
591
592     private void confirmFailures( String path, String[] ids )
593         throws LayoutException
594     {
595         wagonMockControl.replay();
596
597         // Attempt the proxy fetch.
598         File downloadedFile = null;
599         try
600         {
601             downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
602                                                             managedDefaultRepository.toArtifactReference( path ) );
603             fail( "Proxy should not have succeeded" );
604         }
605         catch ( ProxyDownloadException e )
606         {
607             assertEquals( ids.length, e.getFailures().size() );
608             for ( String id : ids )
609             {
610                 assertTrue( e.getFailures().keySet().contains( id ) );
611             }
612         }
613
614         wagonMockControl.verify();
615
616         assertNotDownloaded( downloadedFile );
617     }
618
619     private void confirmSuccess( String path, File expectedFile, String basedir )
620         throws Exception
621     {
622         File downloadedFile = performDownload( path );
623
624         File proxied1File = new File( basedir, path );
625         assertFileEquals( expectedFile, downloadedFile, proxied1File );
626     }
627
628     private void confirmNotDownloadedNoError( String path )
629         throws Exception
630     {
631         File downloadedFile = performDownload( path );
632
633         assertNotDownloaded( downloadedFile );
634     }
635
636     private File performDownload( String path )
637         throws ProxyDownloadException, LayoutException
638     {
639         wagonMockControl.replay();
640
641         // Attempt the proxy fetch.
642         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository,
643                                                              managedDefaultRepository.toArtifactReference( path ) );
644
645         wagonMockControl.verify();
646         return downloadedFile;
647     }
648
649     private static TransferFailedException createTransferException()
650     {
651         return new TransferFailedException( "test download exception" );
652     }
653
654     private static ResourceDoesNotExistException createResourceNotFoundException()
655     {
656         return new ResourceDoesNotExistException( "test download not found" );
657     }
658 }