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