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