]> source.dussan.org Git - archiva.git/blob
ce6edd3fed6d1144c8e1cd6c72bbd59af5288b44
[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.commons.io.FileUtils;
23 import org.apache.archiva.model.ArtifactReference;
24 import org.apache.archiva.policies.CachedFailuresPolicy;
25 import org.apache.archiva.policies.ChecksumPolicy;
26 import org.apache.archiva.policies.ReleasesPolicy;
27 import org.apache.archiva.policies.SnapshotsPolicy;
28 import org.apache.maven.wagon.ResourceDoesNotExistException;
29 import org.easymock.EasyMock;
30 import org.junit.Test;
31
32 import java.io.File;
33
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.Assert.assertNull;
36
37 /**
38  * ChecksumTransferTest
39  *
40  *
41  */
42 public class ChecksumTransferTest
43     extends AbstractProxyTestCase
44 {
45     @Test
46     public void testGetChecksumWhenConnectorIsDisabled()
47         throws Exception
48     {
49         String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
50         setupTestableManagedRepository( path );
51
52         File expectedFile = new File( managedDefaultDir, path );
53         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
54
55         FileUtils.deleteDirectory( expectedFile.getParentFile() );
56         assertFalse( expectedFile.exists() );
57
58         // Configure Connector (usually done within archiva.xml configuration)
59         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
60                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, true );
61
62         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
63
64         assertNull( downloadedFile );
65     }
66
67     @Test
68     public void testGetChecksumBothCorrect()
69         throws Exception
70     {
71         String path = "org/apache/maven/test/get-checksum-both-right/1.0/get-checksum-both-right-1.0.jar";
72         setupTestableManagedRepository( path );
73
74         File expectedFile = new File( managedDefaultDir, path );
75         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
76
77         FileUtils.deleteDirectory( expectedFile.getParentFile() );
78         assertFalse( expectedFile.exists() );
79
80         // Configure Connector (usually done within archiva.xml configuration)
81         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
82                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
83
84         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
85
86         File proxied1File = new File( REPOPATH_PROXIED1, path );
87         assertFileEquals( expectedFile, downloadedFile, proxied1File );
88         assertNoTempFiles( expectedFile );
89         assertChecksums( expectedFile, "066d76e459f7782c312c31e8a11b3c0f1e3e43a7 *get-checksum-both-right-1.0.jar",
90                          "e58f30c6a150a2e843552438d18e15cb *get-checksum-both-right-1.0.jar" );
91     }
92
93     @Test
94     public void testGetChecksumCorrectSha1NoMd5()
95         throws Exception
96     {
97         String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
98         setupTestableManagedRepository( path );
99
100         File expectedFile = new File( managedDefaultDir, path );
101         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
102
103         FileUtils.deleteDirectory( expectedFile.getParentFile() );
104         assertFalse( expectedFile.exists() );
105
106         // Configure Connector (usually done within archiva.xml configuration)
107         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
108                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
109
110         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
111
112         File proxied1File = new File( REPOPATH_PROXIED1, path );
113         assertFileEquals( expectedFile, downloadedFile, proxied1File );
114         assertNoTempFiles( expectedFile );
115         assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
116                          null );
117     }
118
119     @Test
120     public void testGetChecksumNoSha1CorrectMd5()
121         throws Exception
122     {
123         String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
124         setupTestableManagedRepository( path );
125
126         File expectedFile = new File( managedDefaultDir, path );
127         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
128
129         FileUtils.deleteDirectory( expectedFile.getParentFile() );
130         assertFalse( expectedFile.exists() );
131
132         // Configure Connector (usually done within archiva.xml configuration)
133         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
134                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
135
136         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
137
138         File proxied1File = new File( REPOPATH_PROXIED1, path );
139         assertFileEquals( expectedFile, downloadedFile, proxied1File );
140         assertNoTempFiles( expectedFile );
141         assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
142     }
143
144     @Test
145     public void testGetWithNoChecksumsUsingIgnoredSetting()
146         throws Exception
147     {
148         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
149         setupTestableManagedRepository( path );
150
151         File expectedFile = new File( managedDefaultDir, path );
152         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
153
154         FileUtils.deleteDirectory( expectedFile.getParentFile() );
155         assertFalse( expectedFile.exists() );
156
157         // Configure Connector (usually done within archiva.xml configuration)
158         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
159                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
160
161         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
162
163         File proxied1File = new File( REPOPATH_PROXIED1, path );
164         assertFileEquals( expectedFile, downloadedFile, proxied1File );
165         assertNoTempFiles( expectedFile );
166         assertChecksums( expectedFile, null, null );
167     }
168
169     @Test
170     public void testGetChecksumBadSha1BadMd5IgnoredSetting()
171         throws Exception
172     {
173         String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
174         setupTestableManagedRepository( path );
175
176         File expectedFile = new File( managedDefaultDir, path );
177         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
178
179         FileUtils.deleteDirectory( expectedFile.getParentFile() );
180         assertFalse( expectedFile.exists() );
181
182         // Configure Connector (usually done within archiva.xml configuration)
183         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
184                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
185
186         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
187
188         File proxied1File = new File( REPOPATH_PROXIED1, path );
189         assertFileEquals( expectedFile, downloadedFile, proxied1File );
190         assertNoTempFiles( expectedFile );
191         assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
192     }
193
194     @Test
195     public void testGetChecksumBadSha1BadMd5FailSetting()
196         throws Exception
197     {
198         String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
199         setupTestableManagedRepository( path );
200
201         File expectedFile = new File( managedDefaultDir, path );
202         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
203
204         FileUtils.deleteDirectory( expectedFile.getParentFile() );
205         assertFalse( expectedFile.exists() );
206
207         // Configure Connector (usually done within archiva.xml configuration)
208         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
209                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
210
211         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
212
213         assertNotDownloaded( downloadedFile );
214         assertChecksums( expectedFile, null, null );
215     }
216
217     @Test
218     public void testGetChecksumBadSha1BadMd5FixSetting()
219         throws Exception
220     {
221         String path = "org/apache/maven/test/get-checksum-both-bad/1.0/get-checksum-both-bad-1.0.jar";
222         setupTestableManagedRepository( path );
223
224         File expectedFile = new File( managedDefaultDir, path );
225         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
226
227         FileUtils.deleteDirectory( expectedFile.getParentFile() );
228         assertFalse( expectedFile.exists() );
229
230         // Configure Connector (usually done within archiva.xml configuration)
231         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
232                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
233
234         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
235
236         File proxied1File = new File( REPOPATH_PROXIED1, path );
237         assertFileEquals( expectedFile, downloadedFile, proxied1File );
238         assertNoTempFiles( expectedFile );
239         assertChecksums( expectedFile, "4ec20a12dc91557330bd0b39d1805be5e329ae56  get-checksum-both-bad-1.0.jar",
240                          "a292491a35925465e693a44809a078b5  get-checksum-both-bad-1.0.jar" );
241     }
242
243     @Test
244     public void testGetChecksumCorrectSha1BadMd5UsingFailSetting()
245         throws Exception
246     {
247         String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
248         setupTestableManagedRepository( path );
249
250         File expectedFile = new File( managedDefaultDir, path );
251         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
252
253         FileUtils.deleteDirectory( expectedFile.getParentFile() );
254         assertFalse( expectedFile.exists() );
255
256         // Configure Connector (usually done within archiva.xml configuration)
257         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
258                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
259
260         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
261
262         assertNotDownloaded( downloadedFile );
263         assertChecksums( expectedFile, null, null );
264     }
265
266     @Test
267     public void testGetChecksumNoSha1CorrectMd5UsingFailSetting()
268         throws Exception
269     {
270         String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
271         setupTestableManagedRepository( path );
272
273         File expectedFile = new File( managedDefaultDir, path );
274         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
275
276         FileUtils.deleteDirectory( expectedFile.getParentFile() );
277         assertFalse( expectedFile.exists() );
278
279         // Configure Connector (usually done within archiva.xml configuration)
280         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
281                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
282
283         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
284
285         // This is a success situation. No SHA1 with a Good MD5.
286         File proxied1File = new File( REPOPATH_PROXIED1, path );
287         assertFileEquals( expectedFile, downloadedFile, proxied1File );
288         assertNoTempFiles( expectedFile );
289         assertChecksums( expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
290     }
291
292     @Test
293     public void testGetWithNoChecksumsUsingFailSetting()
294         throws Exception
295     {
296         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
297         setupTestableManagedRepository( path );
298
299         File expectedFile = new File( managedDefaultDir, path );
300         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
301
302         FileUtils.deleteDirectory( expectedFile.getParentFile() );
303         assertFalse( expectedFile.exists() );
304
305         // Configure Connector (usually done within archiva.xml configuration)
306         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
307                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
308
309         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
310
311         assertNotDownloaded( downloadedFile );
312         assertChecksums( expectedFile, null, null );
313     }
314
315     @Test
316     public void testGetChecksumCorrectSha1BadMd5UsingIgnoredSetting()
317         throws Exception
318     {
319         String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
320         setupTestableManagedRepository( path );
321
322         File expectedFile = new File( managedDefaultDir, path );
323         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
324
325         FileUtils.deleteDirectory( expectedFile.getParentFile() );
326         assertFalse( expectedFile.exists() );
327
328         // Configure Connector (usually done within archiva.xml configuration)
329         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
330                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
331
332         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
333
334         File proxied1File = new File( REPOPATH_PROXIED1, path );
335         assertFileEquals( expectedFile, downloadedFile, proxied1File );
336         assertNoTempFiles( expectedFile );
337         assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
338                          "invalid checksum file" );
339     }
340
341     @Test
342     public void testGetChecksumCorrectSha1BadMd5UsingFixSetting()
343         throws Exception
344     {
345         String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
346         setupTestableManagedRepository( path );
347
348         File expectedFile = new File( managedDefaultDir, path );
349         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
350
351         FileUtils.deleteDirectory( expectedFile.getParentFile() );
352         assertFalse( expectedFile.exists() );
353
354         // Configure Connector (usually done within archiva.xml configuration)
355         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
356                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
357
358         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
359
360         File proxied1File = new File( REPOPATH_PROXIED1, path );
361         assertFileEquals( expectedFile, downloadedFile, proxied1File );
362         assertNoTempFiles( expectedFile );
363         assertChecksums( expectedFile, "3dd1a3a57b807d3ef3fbc6013d926c891cbb8670 *get-checksum-sha1-bad-md5-1.0.jar",
364                          "c35f3b76268b73a4ba617f6f275c49ab  get-checksum-sha1-bad-md5-1.0.jar" );
365     }
366
367     @Test
368     public void testGetChecksumNoSha1CorrectMd5UsingFixSetting()
369         throws Exception
370     {
371         String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
372         setupTestableManagedRepository( path );
373
374         File expectedFile = new File( managedDefaultDir, path );
375         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
376
377         FileUtils.deleteDirectory( expectedFile.getParentFile() );
378         assertFalse( expectedFile.exists() );
379
380         // Configure Connector (usually done within archiva.xml configuration)
381         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
382                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
383
384         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
385
386         File proxied1File = new File( REPOPATH_PROXIED1, path );
387         assertFileEquals( expectedFile, downloadedFile, proxied1File );
388         assertNoTempFiles( expectedFile );
389         assertChecksums( expectedFile, "71f7dc3f72053a3f2d9fdd6fef9db055ef957ffb  get-checksum-md5-only-1.0.jar",
390                          "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar" );
391     }
392
393     @Test
394     public void testGetWithNoChecksumsUsingFixSetting()
395         throws Exception
396     {
397         String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
398         setupTestableManagedRepository( path );
399
400         File expectedFile = new File( managedDefaultDir, path );
401         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
402
403         FileUtils.deleteDirectory( expectedFile.getParentFile() );
404         assertFalse( expectedFile.exists() );
405
406         // Configure Connector (usually done within archiva.xml configuration)
407         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
408                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
409
410         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
411
412         File proxied1File = new File( REPOPATH_PROXIED1, path );
413         assertFileEquals( expectedFile, downloadedFile, proxied1File );
414         assertNoTempFiles( expectedFile );
415         assertChecksums( expectedFile, "1f12821c5e43e1a0b76b9564a6ddb0548ccb9486  get-default-layout-1.0.jar",
416                          "3f7341545f21226b6f49a3c2704cb9be  get-default-layout-1.0.jar" );
417     }
418
419     @Test
420     public void testGetChecksumNotFoundOnRemote()
421         throws Exception
422     {
423         String path = "org/apache/maven/test/get-checksum-sha1-only/1.0/get-checksum-sha1-only-1.0.jar";
424         setupTestableManagedRepository( path );
425
426         File expectedFile = new File( managedDefaultDir, path );
427         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
428
429         FileUtils.deleteDirectory( expectedFile.getParentFile() );
430         assertFalse( expectedFile.getParentFile().exists() );
431         assertFalse( expectedFile.exists() );
432
433         saveRemoteRepositoryConfig( "badproxied", "Bad Proxied", "test://bad.machine.com/repo/", "default" );
434
435         // Configure Connector (usually done within archiva.xml configuration)
436         saveConnector( ID_DEFAULT_MANAGED, "badproxied", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
437                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
438
439         //wagonMock.get( path, new File( expectedFile.getAbsolutePath() + ".tmp" ) );
440         //wagonMockControl.setMatcher( customWagonGetMatcher );
441         //wagonMockControl.setVoidCallable();
442         wagonMock.get( EasyMock.eq( path ), EasyMock.anyObject( File.class ));
443         EasyMock.expectLastCall().once();
444
445         //wagonMock.get( path + ".sha1", new File( expectedFile.getAbsolutePath() + ".sha1.tmp" ) );
446         //wagonMockControl.setMatcher( customWagonGetMatcher );
447         //wagonMockControl.setVoidCallable();
448         wagonMock.get( EasyMock.eq( path + ".sha1" ), EasyMock.anyObject( File.class ));
449         EasyMock.expectLastCall().once();
450
451         //wagonMock.get( path + ".md5", new File( expectedFile.getAbsolutePath() + ".md5.tmp" ) );
452         //wagonMockControl.setMatcher( customWagonGetMatcher );
453         //wagonMockControl.setThrowable( new ResourceDoesNotExistException( "Resource does not exist." ) );
454
455         wagonMock.get( EasyMock.eq( path + ".md5" ), EasyMock.anyObject( File.class ));
456         EasyMock.expectLastCall().andThrow( new ResourceDoesNotExistException( "Resource does not exist." ) ).once();
457
458         wagonMockControl.replay();
459
460         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
461
462         wagonMockControl.verify();
463
464         // Do what the mock doesn't do.
465         String proxyPath = new File( REPOPATH_PROXIED1, path ).getAbsolutePath();
466         String localPath = new File( managedDefaultDir, path ).getAbsolutePath();
467         FileUtils.copyFile( new File( proxyPath ), new File( localPath ) );
468         FileUtils.copyFile( new File( proxyPath + ".sha1" ), new File( localPath + ".sha1" ) );
469
470         // Test results.
471         File proxied1File = new File( REPOPATH_PROXIED1, path );
472         assertFileEquals( expectedFile, downloadedFile, proxied1File );
473         assertNoTempFiles( expectedFile );
474         assertChecksums( expectedFile, "748a3a013bf5eacf2bbb40a2ac7d37889b728837 *get-checksum-sha1-only-1.0.jar",
475                          null );
476     }
477
478     @Test
479     public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingIgnoredSetting()
480         throws Exception
481     {
482         String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
483         setupTestableManagedRepository( path );
484
485         File expectedFile = new File( managedDefaultDir, path );
486         File remoteFile = new File( REPOPATH_PROXIED1, path );
487
488         setManagedOlderThanRemote( expectedFile, remoteFile );
489
490         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
491
492         // Configure Connector (usually done within archiva.xml configuration)
493         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS,
494                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
495
496         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
497
498         File proxied1File = new File( REPOPATH_PROXIED1, path );
499         assertFileEquals( expectedFile, downloadedFile, proxied1File );
500         assertNoTempFiles( expectedFile );
501         // There are no hashcodes on the proxy side to download, hence the local ones should remain invalid.
502         assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
503     }
504
505     @Test
506     public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFailSetting()
507         throws Exception
508     {
509         String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
510         setupTestableManagedRepository( path );
511
512         File expectedFile = new File( managedDefaultDir, path );
513         File remoteFile = new File( REPOPATH_PROXIED1, path );
514
515         setManagedOlderThanRemote( expectedFile, remoteFile );
516
517         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
518
519         // Configure Connector (usually done within archiva.xml configuration)
520         saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS,
521                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
522
523         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
524
525         assertNotDownloaded( downloadedFile );
526         assertNoTempFiles( expectedFile );
527         // There are no hashcodes on the proxy side to download.
528         // The FAIL policy will delete the checksums as bad.
529
530         assertChecksums( expectedFile, "invalid checksum file", "invalid checksum file" );
531     }
532
533     @Test
534     public void testGetAlwaysBadChecksumPresentLocallyAbsentRemoteUsingFixSetting()
535         throws Exception
536     {
537         String path = "org/apache/maven/test/get-bad-local-checksum/1.0/get-bad-local-checksum-1.0.jar";
538         setupTestableManagedRepository( path );
539
540         File expectedFile = new File( managedDefaultDir, path );
541         File remoteFile = new File( REPOPATH_PROXIED1, path );
542
543         setManagedOlderThanRemote( expectedFile, remoteFile );
544
545         ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
546
547         // Configure Connector (usually done within archiva.xml configuration)
548         saveConnector( ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
549                        SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false );
550
551         File downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository, artifact );
552
553         File proxied1File = new File( REPOPATH_PROXIED1, path );
554         assertFileEquals( expectedFile, downloadedFile, proxied1File );
555         assertNoTempFiles( expectedFile );
556         assertChecksums( expectedFile, "96a08dc80a108cba8efd3b20aec91b32a0b2cbd4  get-bad-local-checksum-1.0.jar",
557                          "46fdd6ca55bf1d7a7eb0c858f41e0ccd  get-bad-local-checksum-1.0.jar" );
558     }
559 }