]> source.dussan.org Git - archiva.git/blob
a532de1a699d2174022f06c82bc11486c6ae72eb
[archiva.git] /
1 package org.apache.archiva.webdav;
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
23 import com.gargoylesoftware.htmlunit.WebRequest;
24 import com.gargoylesoftware.htmlunit.WebResponse;
25 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.springframework.mock.web.MockHttpServletRequest;
30 import org.springframework.mock.web.MockHttpServletResponse;
31
32 import javax.servlet.http.HttpServletResponse;
33 import java.nio.charset.Charset;
34 import java.nio.file.Files;
35 import java.nio.file.Path;
36 import java.util.ArrayList;
37
38 /**
39  * RepositoryServletTest
40  */
41 public class RepositoryServletNoProxyTest
42     extends AbstractRepositoryServletTestCase
43 {
44
45     @Before
46     @Override
47     public void setUp()
48         throws Exception
49     {
50         super.setUp();
51         archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
52         startRepository();
53     }
54
55     @Override
56     @After
57     public void tearDown( ) throws Exception
58     {
59         super.tearDown( );
60     }
61
62     @Test
63     public void testLastModifiedHeaderExists()
64         throws Exception
65     {
66         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
67
68         Path checksumFile = repoRootInternal.resolve( commonsLangSha1 );
69         Files.createDirectories(checksumFile.getParent());
70
71         org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset(), "dummy-checksum" );
72
73         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
74         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
75         assertNotNull( response.getResponseHeaderValue( "Last-Modified" ) );
76     }
77
78     @Test
79     public void testGetNoProxyChecksumDefaultLayout()
80         throws Exception
81     {
82         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
83
84         Path checksumFile = repoRootInternal.resolve(commonsLangSha1);
85         Files.createDirectories(checksumFile.getParent());
86
87         org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset(), "dummy-checksum");
88
89         //WebRequest request = new WebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
90         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangSha1 );
91         assertResponseOK( response );
92
93         assertEquals( "Expected file contents", "dummy-checksum", response.getContentAsString() );
94     }
95
96     @Test
97     public void testGetNoProxyChecksumLegacyLayout()
98         throws Exception
99     {
100         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
101
102         Path checksumFile = repoRootInternal.resolve(commonsLangSha1);
103         Files.createDirectories(checksumFile.getParent());
104
105         org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset() , "dummy-checksum");
106
107         //WebRequest request = new GetMethodWebRequest(
108         //    "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
109         WebResponse response =
110             getWebResponse( "/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
111         assertResponseNotFound( response );
112     }
113
114     @Test
115     public void testGetNoProxyVersionedMetadataDefaultLayout()
116         throws Exception
117     {
118         String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
119         String expectedMetadataContents = "dummy-versioned-metadata";
120
121         Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
122         Files.createDirectories(metadataFile.getParent());
123
124         org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), expectedMetadataContents );
125
126         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
127         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
128         assertResponseOK( response );
129
130         assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
131     }
132
133     @Test
134     public void testGetNoProxyProjectMetadataDefaultLayout()
135         throws Exception
136     {
137         String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
138         String expectedMetadataContents = "dummy-project-metadata";
139
140         Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
141         Files.createDirectories(metadataFile.getParent());
142
143         org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), expectedMetadataContents );
144
145         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
146         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
147         assertResponseOK( response );
148
149         assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
150     }
151
152     @Test
153     public void testGetNoProxyGroupMetadataDefaultLayout()
154         throws Exception
155     {
156         String commonsLangMetadata = "commons-lang/maven-metadata.xml";
157         String expectedMetadataContents = "dummy-group-metadata";
158
159         Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
160         Files.createDirectories(metadataFile.getParent());
161
162         org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), expectedMetadataContents );
163
164         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
165         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangMetadata );
166         assertResponseOK( response );
167
168         assertEquals( "Expected file contents", expectedMetadataContents, response.getContentAsString() );
169     }
170
171     @Test
172     public void testGetNoProxyArtifactDefaultLayout()
173         throws Exception
174     {
175         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
176         String expectedArtifactContents = "dummy-commons-lang-artifact";
177
178         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
179         Files.createDirectories(artifactFile.getParent());
180
181         org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset(), expectedArtifactContents );
182
183         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
184         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
185         assertResponseOK( response );
186
187         assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
188     }
189
190     @Test
191     public void testGetNoProxyArtifactLegacyLayout()
192         throws Exception
193     {
194         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
195         String expectedArtifactContents = "dummy-commons-lang-artifact";
196
197         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
198         Files.createDirectories(artifactFile.getParent());
199
200         org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset(), expectedArtifactContents );
201
202         //WebRequest request = new GetMethodWebRequest(
203         //    "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
204         WebResponse response = getWebResponse( "/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
205         assertResponseNotFound( response );
206
207     }
208
209     @Test
210     public void testGetNoProxySnapshotArtifactDefaultLayout()
211         throws Exception
212     {
213         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
214         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
215
216         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
217         Files.createDirectories(artifactFile.getParent());
218
219         org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset() , expectedArtifactContents);
220
221         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
222         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
223         assertResponseOK( response );
224
225         assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
226     }
227
228     @Test
229     public void testGetNoProxySnapshotArtifactLegacyLayout()
230         throws Exception
231     {
232         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
233         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
234
235         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
236         Files.createDirectories(artifactFile.getParent());
237
238         org.apache.archiva.common.utils.FileUtils.writeStringToFile( artifactFile, Charset.defaultCharset() , expectedArtifactContents);
239
240         //WebRequest request = new GetMethodWebRequest(
241         //    "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
242         WebResponse response = getWebResponse( "/repository/internal/commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
243         assertResponseNotFound( response );
244     }
245
246     @Test
247     public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
248         throws Exception
249     {
250         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
251         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
252
253         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
254         Files.createDirectories(artifactFile.getParent());
255
256         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
257
258         //WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
259         WebResponse response = getWebResponse( "/repository/internal/" + commonsLangJar );
260         assertResponseOK( response );
261
262         assertEquals( "Expected file contents", expectedArtifactContents, response.getContentAsString() );
263     }
264
265     @Test
266     public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
267         throws Exception
268     {
269         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
270         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
271
272         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
273         Files.createDirectories(artifactFile.getParent());
274
275         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
276
277         WebRequest request = new GetMethodWebRequest(
278             "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
279         WebResponse response = getServletUnitClient().getResponse( request );
280         assertResponseNotFound( response );
281     }
282
283     /**
284      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
285      */
286     @Test
287     public void testGetNoProxyDualExtensionDefaultLayout()
288         throws Exception
289     {
290         String expectedContents = "the-contents-of-the-dual-extension";
291         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
292
293         Path checksumFile = repoRootInternal.resolve(dualExtensionPath);
294         Files.createDirectories(checksumFile.getParent());
295
296         org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
297
298         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
299         WebResponse response = getServletUnitClient().getResponse( request );
300         assertResponseOK( response );
301
302         assertEquals( "Expected file contents", expectedContents, response.getContentAsString() );
303     }
304
305     @Test
306     public void testGetNoProxyDistributionLegacyLayout()
307         throws Exception
308     {
309         String expectedContents = "the-contents-of-the-dual-extension";
310         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
311
312         Path checksumFile = repoRootInternal.resolve(dualExtensionPath);
313         Files.createDirectories(checksumFile.getParent());
314
315         org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
316
317         WebRequest request = new GetMethodWebRequest(
318             "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
319         WebResponse response = getServletUnitClient().getResponse( request );
320         assertResponseNotFound( response );
321
322     }
323
324     @Test
325     public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
326         throws Exception
327     {
328         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
329
330         Path checksumFile = repoRootLegacy.resolve( "commons-lang/jars/commons-lang-2.1.jar.sha1" );
331         Files.createDirectories(checksumFile.getParent());
332
333         org.apache.archiva.common.utils.FileUtils.writeStringToFile( checksumFile, Charset.defaultCharset(), "dummy-checksum" );
334
335         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
336         WebResponse response = getServletUnitClient().getResponse( request );
337         assertResponseNotFound( response );
338     }
339
340     @Test
341     public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
342         throws Exception
343     {
344         String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
345         Path checksumFile = repoRootLegacy.resolve(commonsLangSha1);
346         Files.createDirectories(checksumFile.getParent());
347
348         org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), "dummy-checksum");
349
350         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
351         WebResponse response = getServletUnitClient().getResponse( request );
352         assertResponseNotFound( response );
353     }
354
355     @Test
356     public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
357         throws Exception
358     {
359         String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
360         String expectedMetadataContents = "dummy-versioned-metadata";
361
362         // TODO: find out what this should be from maven-artifact
363         Path metadataFile = repoRootLegacy.resolve(commonsLangMetadata);
364         Files.createDirectories(metadataFile.getParent());
365
366         org.apache.archiva.common.utils.FileUtils.writeStringToFile(metadataFile, Charset.defaultCharset(), expectedMetadataContents);
367
368         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
369         WebResponse response = getServletUnitClient().getResponse( request );
370         assertResponseNotFound( response );
371     }
372
373     @Test
374     public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
375         throws Exception
376     {
377         // TODO: find out what it is meant to be from maven-artifact
378         String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
379         String expectedMetadataContents = "dummy-project-metadata";
380
381         Path metadataFile = repoRootLegacy.resolve(commonsLangMetadata);
382         Files.createDirectories(metadataFile.getParent());
383
384         org.apache.archiva.common.utils.FileUtils.writeStringToFile(metadataFile, Charset.defaultCharset(), expectedMetadataContents);
385
386         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
387         WebResponse response = getServletUnitClient().getResponse( request );
388         assertResponseNotFound( response );
389     }
390
391     @Test
392     public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
393         throws Exception
394     {
395         String commonsLangMetadata = "commons-lang/maven-metadata.xml";
396         String expectedMetadataContents = "dummy-group-metadata";
397
398         Path metadataFile = repoRootLegacy.resolve(commonsLangMetadata);
399         Files.createDirectories(metadataFile.getParent());
400
401         org.apache.archiva.common.utils.FileUtils.writeStringToFile(metadataFile, Charset.defaultCharset(), expectedMetadataContents);
402
403         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
404         WebResponse response = getServletUnitClient().getResponse( request );
405         assertResponseNotFound( response );
406     }
407
408     @Test
409     public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
410         throws Exception
411     {
412         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
413         String expectedArtifactContents = "dummy-commons-lang-artifact";
414
415         Path artifactFile = repoRootLegacy.resolve("commons-lang/jars/commons-lang-2.1.jar" );
416         Files.createDirectories(artifactFile.getParent());
417
418         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
419
420         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
421         WebResponse response = getServletUnitClient().getResponse( request );
422         assertResponseNotFound( response );
423     }
424
425     @Test
426     public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
427         throws Exception
428     {
429         String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
430         String expectedArtifactContents = "dummy-commons-lang-artifact";
431
432         Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
433         Files.createDirectories(artifactFile.getParent());
434
435         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
436
437         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
438         WebResponse response = getServletUnitClient().getResponse( request );
439         assertResponseNotFound( response );
440     }
441
442     @Test
443     public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
444         throws Exception
445     {
446         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
447         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
448
449         Path artifactFile = repoRootLegacy.resolve( "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
450         Files.createDirectories(artifactFile.getParent());
451
452         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
453
454         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
455         WebResponse response = getServletUnitClient().getResponse( request );
456         assertResponseNotFound( response );
457     }
458
459     @Test
460     public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
461         throws Exception
462     {
463         String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
464         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
465
466         Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
467         Files.createDirectories(artifactFile.getParent());
468
469         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
470
471         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
472         WebResponse response = getServletUnitClient().getResponse( request );
473         assertResponseNotFound( response );
474     }
475
476     @Test
477     public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
478         throws Exception
479     {
480         String filename = "commons-lang-2.1-20050821.023400-1.jar";
481         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
482         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
483
484         Path artifactFile = repoRootLegacy.resolve( "commons-lang/jars/" + filename );
485         Files.createDirectories(artifactFile.getParent());
486
487         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
488
489         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
490         WebResponse response = getServletUnitClient().getResponse( request );
491         assertResponseNotFound( response );
492     }
493
494     @Test
495     public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
496         throws Exception
497     {
498         String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
499         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
500
501         Path artifactFile = repoRootLegacy.resolve(commonsLangJar);
502         Files.createDirectories(artifactFile.getParent());
503
504         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
505
506         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
507         WebResponse response = getServletUnitClient().getResponse( request );
508         assertResponseNotFound( response );
509     }
510
511     /**
512      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
513      */
514     @Test
515     public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
516         throws Exception
517     {
518         String expectedContents = "the-contents-of-the-dual-extension";
519         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
520
521         Path checksumFile = repoRootLegacy.resolve( "org.project/distributions/example-presentation-3.2.xml.zip" );
522         Files.createDirectories(checksumFile.getParent());
523
524         org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
525
526         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
527         WebResponse response = getServletUnitClient().getResponse( request );
528         assertResponseNotFound( response );
529     }
530
531     @Test
532     public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
533         throws Exception
534     {
535         String expectedContents = "the-contents-of-the-dual-extension";
536         String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
537
538         Path checksumFile = repoRootLegacy.resolve(dualExtensionPath);
539         Files.createDirectories(checksumFile.getParent());
540
541         org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedContents);
542
543         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
544         WebResponse response = getServletUnitClient().getResponse( request );
545         assertResponseNotFound( response );
546     }
547
548     @Test
549     public void testGetNoProxySnapshotRedirectToTimestampedSnapshot()
550         throws Exception
551     {
552         String commonsLangQuery = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
553         String commonsLangMetadata = "commons-lang/commons-lang/2.1-SNAPSHOT/maven-metadata.xml";
554         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
555         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
556
557         archivaConfiguration.getConfiguration().getWebapp().getUi().setApplicationUrl("http://localhost");
558
559         Path artifactFile = repoRootInternal.resolve(commonsLangJar);
560         Files.createDirectories(artifactFile.getParent());
561         org.apache.archiva.common.utils.FileUtils.writeStringToFile(artifactFile, Charset.defaultCharset(), expectedArtifactContents);
562
563         Path metadataFile = repoRootInternal.resolve(commonsLangMetadata);
564         Files.createDirectories(metadataFile.getParent());
565         org.apache.archiva.common.utils.FileUtils.writeStringToFile( metadataFile, Charset.defaultCharset(), createVersionMetadata("commons-lang", "commons-lang",
566                 "2.1-SNAPSHOT", "20050821.023400", "1", "20050821.023400"));
567
568         WebRequest webRequest = new GetMethodWebRequest(
569                 "http://localhost/repository/internal/" + commonsLangQuery );
570
571         MockHttpServletRequest request = new MockHttpServletRequest();
572         request.setRequestURI( webRequest.getUrl().getPath() );
573         request.addHeader( "User-Agent", "Apache Archiva unit test" );
574         request.setMethod( webRequest.getHttpMethod().name() );
575
576         final MockHttpServletResponse response = execute( request );
577
578         assertEquals( HttpServletResponse.SC_MOVED_TEMPORARILY,
579                       response.getStatus() );
580
581         assertEquals( "http://localhost/repository/internal/" + commonsLangJar,
582                       response.getHeader("Location") );
583     }
584
585 }