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.util.ArrayList;
34 * RepositoryServletTest
38 public class RepositoryServletNoProxyTest
39 extends AbstractRepositoryServletTestCase
47 archivaConfiguration.getConfiguration().setProxyConnectors( new ArrayList<ProxyConnectorConfiguration>() );
51 public void testLastModifiedHeaderExists()
54 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
56 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
57 checksumFile.getParentFile().mkdirs();
59 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
61 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
62 WebResponse response = getServletUnitClient().getResponse( request );
64 assertNotNull( response.getHeaderField( "last-modified" ) );
68 public void testGetNoProxyChecksumDefaultLayout()
71 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
73 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
74 checksumFile.getParentFile().mkdirs();
76 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
78 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
79 WebResponse response = getServletUnitClient().getResponse( request );
80 assertResponseOK( response );
82 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
86 public void testGetNoProxyChecksumLegacyLayout()
89 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
91 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
92 checksumFile.getParentFile().mkdirs();
94 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
96 WebRequest request = new GetMethodWebRequest(
97 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
98 WebResponse response = getServletUnitClient().getResponse( request );
99 assertResponseOK( response );
101 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
105 public void testGetNoProxyVersionedMetadataDefaultLayout()
108 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
109 String expectedMetadataContents = "dummy-versioned-metadata";
111 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
112 metadataFile.getParentFile().mkdirs();
114 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
116 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
117 WebResponse response = getServletUnitClient().getResponse( request );
118 assertResponseOK( response );
120 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
124 public void testGetNoProxyProjectMetadataDefaultLayout()
127 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
128 String expectedMetadataContents = "dummy-project-metadata";
130 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
131 metadataFile.getParentFile().mkdirs();
133 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
135 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
136 WebResponse response = getServletUnitClient().getResponse( request );
137 assertResponseOK( response );
139 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
143 public void testGetNoProxyGroupMetadataDefaultLayout()
146 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
147 String expectedMetadataContents = "dummy-group-metadata";
149 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
150 metadataFile.getParentFile().mkdirs();
152 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
154 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
155 WebResponse response = getServletUnitClient().getResponse( request );
156 assertResponseOK( response );
158 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
162 public void testGetNoProxyArtifactDefaultLayout()
165 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
166 String expectedArtifactContents = "dummy-commons-lang-artifact";
168 File artifactFile = new File( repoRootInternal, commonsLangJar );
169 artifactFile.getParentFile().mkdirs();
171 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
173 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
174 WebResponse response = getServletUnitClient().getResponse( request );
175 assertResponseOK( response );
177 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
181 public void testGetNoProxyArtifactLegacyLayout()
184 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
185 String expectedArtifactContents = "dummy-commons-lang-artifact";
187 File artifactFile = new File( repoRootInternal, commonsLangJar );
188 artifactFile.getParentFile().mkdirs();
190 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
192 WebRequest request = new GetMethodWebRequest(
193 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" );
194 WebResponse response = getServletUnitClient().getResponse( request );
195 assertResponseOK( response );
197 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
201 public void testGetNoProxySnapshotArtifactDefaultLayout()
204 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
205 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
207 File artifactFile = new File( repoRootInternal, commonsLangJar );
208 artifactFile.getParentFile().mkdirs();
210 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
212 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
213 WebResponse response = getServletUnitClient().getResponse( request );
214 assertResponseOK( response );
216 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
220 public void testGetNoProxySnapshotArtifactLegacyLayout()
223 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
224 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
226 File artifactFile = new File( repoRootInternal, commonsLangJar );
227 artifactFile.getParentFile().mkdirs();
229 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
231 WebRequest request = new GetMethodWebRequest(
232 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
233 WebResponse response = getServletUnitClient().getResponse( request );
234 assertResponseOK( response );
236 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
240 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
243 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
244 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
246 File artifactFile = new File( repoRootInternal, commonsLangJar );
247 artifactFile.getParentFile().mkdirs();
249 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
251 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
252 WebResponse response = getServletUnitClient().getResponse( request );
253 assertResponseOK( response );
255 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
259 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
262 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
263 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
265 File artifactFile = new File( repoRootInternal, commonsLangJar );
266 artifactFile.getParentFile().mkdirs();
268 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
270 WebRequest request = new GetMethodWebRequest(
271 "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
272 WebResponse response = getServletUnitClient().getResponse( request );
273 assertResponseOK( response );
275 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
279 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
282 public void testGetNoProxyDualExtensionDefaultLayout()
285 String expectedContents = "the-contents-of-the-dual-extension";
286 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
288 File checksumFile = new File( repoRootInternal, dualExtensionPath );
289 checksumFile.getParentFile().mkdirs();
291 FileUtils.writeStringToFile( checksumFile, expectedContents, null );
293 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
294 WebResponse response = getServletUnitClient().getResponse( request );
295 assertResponseOK( response );
297 assertEquals( "Expected file contents", expectedContents, response.getText() );
301 public void testGetNoProxyDistributionLegacyLayout()
304 String expectedContents = "the-contents-of-the-dual-extension";
305 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip";
307 File checksumFile = new File( repoRootInternal, dualExtensionPath );
308 checksumFile.getParentFile().mkdirs();
310 FileUtils.writeStringToFile( checksumFile, expectedContents, null );
312 WebRequest request = new GetMethodWebRequest(
313 "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" );
314 WebResponse response = getServletUnitClient().getResponse( request );
315 assertResponseOK( response );
317 assertEquals( "Expected file contents", expectedContents, response.getText() );
321 public void testGetNoProxyChecksumDefaultLayoutManagedLegacy()
324 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
326 File checksumFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar.sha1" );
327 checksumFile.getParentFile().mkdirs();
329 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
331 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
332 WebResponse response = getServletUnitClient().getResponse( request );
333 assertResponseOK( response );
335 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
339 public void testGetNoProxyChecksumLegacyLayoutManagedLegacy()
342 String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1";
343 File checksumFile = new File( repoRootLegacy, commonsLangSha1 );
344 checksumFile.getParentFile().mkdirs();
346 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
348 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 );
349 WebResponse response = getServletUnitClient().getResponse( request );
350 assertResponseOK( response );
352 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
356 public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy()
359 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
360 String expectedMetadataContents = "dummy-versioned-metadata";
362 // TODO: find out what this should be from maven-artifact
363 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
364 metadataFile.getParentFile().mkdirs();
366 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
368 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
369 WebResponse response = getServletUnitClient().getResponse( request );
370 assertResponseOK( response );
372 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
376 public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy()
379 // TODO: find out what it is meant to be from maven-artifact
380 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
381 String expectedMetadataContents = "dummy-project-metadata";
383 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
384 metadataFile.getParentFile().mkdirs();
386 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
388 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
389 WebResponse response = getServletUnitClient().getResponse( request );
390 assertResponseOK( response );
392 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
396 public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy()
399 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
400 String expectedMetadataContents = "dummy-group-metadata";
402 File metadataFile = new File( repoRootLegacy, commonsLangMetadata );
403 metadataFile.getParentFile().mkdirs();
405 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
407 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata );
408 WebResponse response = getServletUnitClient().getResponse( request );
409 assertResponseOK( response );
411 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
415 public void testGetNoProxyArtifactDefaultLayoutManagedLegacy()
418 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
419 String expectedArtifactContents = "dummy-commons-lang-artifact";
421 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar" );
422 artifactFile.getParentFile().mkdirs();
424 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
426 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
427 WebResponse response = getServletUnitClient().getResponse( request );
428 assertResponseOK( response );
430 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
434 public void testGetNoProxyArtifactLegacyLayoutManagedLegacy()
437 String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar";
438 String expectedArtifactContents = "dummy-commons-lang-artifact";
440 File artifactFile = new File( repoRootLegacy, commonsLangJar );
441 artifactFile.getParentFile().mkdirs();
443 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
445 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
446 WebResponse response = getServletUnitClient().getResponse( request );
447 assertResponseOK( response );
449 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
453 public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy()
456 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
457 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
459 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
460 artifactFile.getParentFile().mkdirs();
462 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
464 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
465 WebResponse response = getServletUnitClient().getResponse( request );
466 assertResponseOK( response );
468 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
472 public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy()
475 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar";
476 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
478 File artifactFile = new File( repoRootLegacy, commonsLangJar );
479 artifactFile.getParentFile().mkdirs();
481 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
483 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
484 WebResponse response = getServletUnitClient().getResponse( request );
485 assertResponseOK( response );
487 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
491 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy()
494 String filename = "commons-lang-2.1-20050821.023400-1.jar";
495 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename;
496 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
498 File artifactFile = new File( repoRootLegacy, "commons-lang/jars/" + filename );
499 artifactFile.getParentFile().mkdirs();
501 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
503 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
504 WebResponse response = getServletUnitClient().getResponse( request );
505 assertResponseOK( response );
507 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
511 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy()
514 String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar";
515 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
517 File artifactFile = new File( repoRootLegacy, commonsLangJar );
518 artifactFile.getParentFile().mkdirs();
520 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
522 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar );
523 WebResponse response = getServletUnitClient().getResponse( request );
524 assertResponseOK( response );
526 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
530 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
533 public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy()
536 String expectedContents = "the-contents-of-the-dual-extension";
537 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
539 File checksumFile = new File( repoRootLegacy, "org.project/distributions/example-presentation-3.2.xml.zip" );
540 checksumFile.getParentFile().mkdirs();
542 FileUtils.writeStringToFile( checksumFile, expectedContents, null );
544 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
545 WebResponse response = getServletUnitClient().getResponse( request );
546 assertResponseOK( response );
548 assertEquals( "Expected file contents", expectedContents, response.getText() );
552 public void testGetNoProxyDistributionLegacyLayoutManagedLegacy()
555 String expectedContents = "the-contents-of-the-dual-extension";
556 String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip";
558 File checksumFile = new File( repoRootLegacy, dualExtensionPath );
559 checksumFile.getParentFile().mkdirs();
561 FileUtils.writeStringToFile( checksumFile, expectedContents, null );
563 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath );
564 WebResponse response = getServletUnitClient().getResponse( request );
565 assertResponseOK( response );
567 assertEquals( "Expected file contents", expectedContents, response.getText() );