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