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