1 package org.apache.archiva.webdav;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.WebRequest;
24 import com.meterware.httpunit.WebResponse;
25 import org.apache.commons.io.FileUtils;
26 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
27 import org.junit.Before;
28 import org.junit.Test;
31 import java.nio.charset.Charset;
32 import java.util.ArrayList;
35 * RepositoryServletTest
39 public class RepositoryServletNoProxyTest
40 extends AbstractRepositoryServletTestCase
48 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
52 public void testLastModifiedHeaderExists()
55 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
57 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
58 checksumFile.getParentFile().mkdirs();
60 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
62 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
63 WebResponse response = getServletUnitClient().getResponse( request );
65 assertNotNull( response.getHeaderField( "last-modified" ) );
69 public void testGetNoProxyChecksumDefaultLayout()
72 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
74 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
75 checksumFile.getParentFile().mkdirs();
77 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
79 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
80 WebResponse response = getServletUnitClient().getResponse( request );
81 assertResponseOK( response );
83 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
87 public void testGetNoProxyChecksumLegacyLayout()
90 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
92 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
93 checksumFile.getParentFile().mkdirs();
95 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
97 WebRequest request = new GetMethodWebRequest(
98 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
99 WebResponse response = getServletUnitClient().getResponse( request );
100 assertResponseOK( response );
102 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
106 public void testGetNoProxyVersionedMetadataDefaultLayout()
109 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
110 String expectedMetadataContents = "dummy-versioned-metadata";
112 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
113 metadataFile.getParentFile().mkdirs();
115 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
117 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
118 WebResponse response = getServletUnitClient().getResponse( request );
119 assertResponseOK( response );
121 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
125 public void testGetNoProxyProjectMetadataDefaultLayout()
128 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
129 String expectedMetadataContents = "dummy-project-metadata";
131 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
132 metadataFile.getParentFile().mkdirs();
134 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
136 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
137 WebResponse response = getServletUnitClient().getResponse( request );
138 assertResponseOK( response );
140 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
144 public void testGetNoProxyGroupMetadataDefaultLayout()
147 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
148 String expectedMetadataContents = "dummy-group-metadata";
150 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
151 metadataFile.getParentFile().mkdirs();
153 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
155 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
156 WebResponse response = getServletUnitClient().getResponse( request );
157 assertResponseOK( response );
159 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
163 public void testGetNoProxyArtifactDefaultLayout()
166 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
167 String expectedArtifactContents = "dummy-commons-lang-artifact";
169 File artifactFile = new File( repoRootInternal, commonsLangJar );
170 artifactFile.getParentFile().mkdirs();
172 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
174 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
175 WebResponse response = getServletUnitClient().getResponse( request );
176 assertResponseOK( response );
178 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
182 public void testGetNoProxyArtifactLegacyLayout()
185 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
186 String expectedArtifactContents = "dummy-commons-lang-artifact";
188 File artifactFile = new File( repoRootInternal, commonsLangJar );
189 artifactFile.getParentFile().mkdirs();
191 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
193 WebRequest request = new GetMethodWebRequest(
194 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
195 WebResponse response = getServletUnitClient().getResponse( request );
196 assertResponseOK( response );
198 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
202 public void testGetNoProxySnapshotArtifactDefaultLayout()
205 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
206 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
208 File artifactFile = new File( repoRootInternal, commonsLangJar );
209 artifactFile.getParentFile().mkdirs();
211 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
213 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
214 WebResponse response = getServletUnitClient().getResponse( request );
215 assertResponseOK( response );
217 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
221 public void testGetNoProxySnapshotArtifactLegacyLayout()
224 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
225 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
227 File artifactFile = new File( repoRootInternal, commonsLangJar );
228 artifactFile.getParentFile().mkdirs();
230 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
232 WebRequest request = new GetMethodWebRequest(
233 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
234 WebResponse response = getServletUnitClient().getResponse( request );
235 assertResponseOK( response );
237 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
241 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
244 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
245 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
247 File artifactFile = new File( repoRootInternal, commonsLangJar );
248 artifactFile.getParentFile().mkdirs();
250 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
252 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
253 WebResponse response = getServletUnitClient().getResponse( request );
254 assertResponseOK( response );
256 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
260 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
263 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
264 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
266 File artifactFile = new File( repoRootInternal, commonsLangJar );
267 artifactFile.getParentFile().mkdirs();
269 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
271 WebRequest request = new GetMethodWebRequest(
272 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
273 WebResponse response = getServletUnitClient().getResponse( request );
274 assertResponseOK( response );
276 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
280 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
283 public void testGetNoProxyDualExtensionDefaultLayout()
286 String expectedContents = "the-contents-of-the-dual-extension";
287 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
289 File checksumFile = new File( repoRootInternal, dualExtensionPath );
290 checksumFile.getParentFile().mkdirs();
292 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
294 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
295 WebResponse response = getServletUnitClient().getResponse( request );
296 assertResponseOK( response );
298 assertEquals( "Expected file contents", expectedContents, response.getText() );
302 public void testGetNoProxyDistributionLegacyLayout()
305 String expectedContents = "the-contents-of-the-dual-extension";
306 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
308 File checksumFile = new File( repoRootInternal, dualExtensionPath );
309 checksumFile.getParentFile().mkdirs();
311 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
313 WebRequest request = new GetMethodWebRequest(
314 "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
315 WebResponse response = getServletUnitClient().getResponse( request );
316 assertResponseOK( response );
318 assertEquals( "Expected file contents", expectedContents, response.getText() );
322 public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
325 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
327 File checksumFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar.sha1" );
328 checksumFile.getParentFile().mkdirs();
330 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
332 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
333 WebResponse response = getServletUnitClient().getResponse( request );
334 assertResponseOK( response );
336 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
340 public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
343 String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
344 File checksumFile = new File( repoRootLegacy, commonsLangSha1 );
345 checksumFile.getParentFile().mkdirs();
347 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", Charset.defaultCharset() );
349 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
350 WebResponse response = getServletUnitClient().getResponse( request );
351 assertResponseOK( response );
353 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
357 public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
360 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
361 String expectedMetadataContents = "dummy-versioned-metadata";
363 // TODO: find out what this should be from maven-artifact
364 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
365 metadataFile.getParentFile().mkdirs();
367 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
369 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
370 WebResponse response = getServletUnitClient().getResponse( request );
371 assertResponseOK( response );
373 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
377 public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
380 // TODO: find out what it is meant to be from maven-artifact
381 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
382 String expectedMetadataContents = "dummy-project-metadata";
384 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
385 metadataFile.getParentFile().mkdirs();
387 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
389 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
390 WebResponse response = getServletUnitClient().getResponse( request );
391 assertResponseOK( response );
393 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
397 public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
400 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
401 String expectedMetadataContents = "dummy-group-metadata";
403 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
404 metadataFile.getParentFile().mkdirs();
406 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, Charset.defaultCharset() );
408 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
409 WebResponse response = getServletUnitClient().getResponse( request );
410 assertResponseOK( response );
412 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
416 public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
419 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
420 String expectedArtifactContents = "dummy-commons-lang-artifact";
422 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar" );
423 artifactFile.getParentFile().mkdirs();
425 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
427 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
428 WebResponse response = getServletUnitClient().getResponse( request );
429 assertResponseOK( response );
431 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
435 public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
438 String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
439 String expectedArtifactContents = "dummy-commons-lang-artifact";
441 File artifactFile = new File( repoRootLegacy, commonsLangJar );
442 artifactFile.getParentFile().mkdirs();
444 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
446 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
447 WebResponse response = getServletUnitClient().getResponse( request );
448 assertResponseOK( response );
450 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
454 public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
457 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
458 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
460 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
461 artifactFile.getParentFile().mkdirs();
463 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
465 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
466 WebResponse response = getServletUnitClient().getResponse( request );
467 assertResponseOK( response );
469 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
473 public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
476 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
477 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
479 File artifactFile = new File( repoRootLegacy, commonsLangJar );
480 artifactFile.getParentFile().mkdirs();
482 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
484 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
485 WebResponse response = getServletUnitClient().getResponse( request );
486 assertResponseOK( response );
488 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
492 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
495 String filename = "commons-lang-2.1-20050821.023400-1.jar";
496 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
497 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
499 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/" + filename );
500 artifactFile.getParentFile().mkdirs();
502 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
504 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
505 WebResponse response = getServletUnitClient().getResponse( request );
506 assertResponseOK( response );
508 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
512 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
515 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
516 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
518 File artifactFile = new File( repoRootLegacy, commonsLangJar );
519 artifactFile.getParentFile().mkdirs();
521 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
523 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
524 WebResponse response = getServletUnitClient().getResponse( request );
525 assertResponseOK( response );
527 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
531 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
534 public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
537 String expectedContents = "the-contents-of-the-dual-extension";
538 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
540 File checksumFile = new File( repoRootLegacy, "org.project/distributions/example-presentation-3.2.xml.zip" );
541 checksumFile.getParentFile().mkdirs();
543 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
545 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
546 WebResponse response = getServletUnitClient().getResponse( request );
547 assertResponseOK( response );
549 assertEquals( "Expected file contents", expectedContents, response.getText() );
553 public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
556 String expectedContents = "the-contents-of-the-dual-extension";
557 String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
559 File checksumFile = new File( repoRootLegacy, dualExtensionPath );
560 checksumFile.getParentFile().mkdirs();
562 FileUtils.writeStringToFile( checksumFile, expectedContents, Charset.defaultCharset() );
564 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
565 WebResponse response = getServletUnitClient().getResponse( request );
566 assertResponseOK( response );
568 assertEquals( "Expected file contents", expectedContents, response.getText() );