1 package org.apache.maven.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;
30 * RepositoryServletTest
34 public class RepositoryServletNoProxyTest
35 extends AbstractRepositoryServletTestCase
37 public void testLastModifiedHeaderExists()
40 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
42 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
43 checksumFile.getParentFile().mkdirs();
45 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
47 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
48 WebResponse response = sc.getResponse( request );
50 assertNotNull(response.getHeaderField("last-modified"));
53 public void testGetNoProxyChecksumDefaultLayout()
56 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
58 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
59 checksumFile.getParentFile().mkdirs();
61 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
63 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
64 WebResponse response = sc.getResponse( request );
65 assertResponseOK( response );
67 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
70 public void testGetNoProxyChecksumLegacyLayout()
73 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
75 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
76 checksumFile.getParentFile().mkdirs();
78 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
80 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
81 + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
82 WebResponse response = sc.getResponse( request );
83 assertResponseOK( response );
85 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
88 public void testGetNoProxyVersionedMetadataDefaultLayout()
91 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
92 String expectedMetadataContents = "dummy-versioned-metadata";
94 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
95 metadataFile.getParentFile().mkdirs();
97 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
99 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
100 WebResponse response = sc.getResponse( request );
101 assertResponseOK( response );
103 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
106 public void testGetNoProxyProjectMetadataDefaultLayout()
109 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
110 String expectedMetadataContents = "dummy-project-metadata";
112 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
113 metadataFile.getParentFile().mkdirs();
115 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
117 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
118 WebResponse response = sc.getResponse( request );
119 assertResponseOK( response );
121 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
124 public void testGetNoProxyGroupMetadataDefaultLayout()
127 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
128 String expectedMetadataContents = "dummy-group-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 = sc.getResponse( request );
137 assertResponseOK( response );
139 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
142 public void testGetNoProxyArtifactDefaultLayout()
145 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
146 String expectedArtifactContents = "dummy-commons-lang-artifact";
148 File artifactFile = new File( repoRootInternal, commonsLangJar );
149 artifactFile.getParentFile().mkdirs();
151 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
153 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
154 WebResponse response = sc.getResponse( request );
155 assertResponseOK( response );
157 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
160 public void testGetNoProxyArtifactLegacyLayout()
163 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
164 String expectedArtifactContents = "dummy-commons-lang-artifact";
166 File artifactFile = new File( repoRootInternal, commonsLangJar );
167 artifactFile.getParentFile().mkdirs();
169 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
171 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
172 + "commons-lang/jars/commons-lang-2.1.jar" );
173 WebResponse response = sc.getResponse( request );
174 assertResponseOK( response );
176 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
179 public void testGetNoProxySnapshotArtifactDefaultLayout()
182 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
183 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
185 File artifactFile = new File( repoRootInternal, commonsLangJar );
186 artifactFile.getParentFile().mkdirs();
188 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
190 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
191 WebResponse response = sc.getResponse( request );
192 assertResponseOK( response );
194 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
197 public void testGetNoProxySnapshotArtifactLegacyLayout()
200 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
201 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
203 File artifactFile = new File( repoRootInternal, commonsLangJar );
204 artifactFile.getParentFile().mkdirs();
206 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
208 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
209 + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
210 WebResponse response = sc.getResponse( request );
211 assertResponseOK( response );
213 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
216 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
219 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
220 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
222 File artifactFile = new File( repoRootInternal, commonsLangJar );
223 artifactFile.getParentFile().mkdirs();
225 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
227 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
228 WebResponse response = sc.getResponse( request );
229 assertResponseOK( response );
231 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
234 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
237 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
238 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
240 File artifactFile = new File( repoRootInternal, commonsLangJar );
241 artifactFile.getParentFile().mkdirs();
243 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
245 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
246 + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
247 WebResponse response = sc.getResponse( request );
248 assertResponseOK( response );
250 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
254 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
256 public void testGetNoProxyDualExtensionDefaultLayout()
259 String expectedContents = "the-contents-of-the-dual-extension";
260 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
262 File checksumFile = new File( repoRootInternal, dualExtensionPath );
263 checksumFile.getParentFile().mkdirs();
265 FileUtils.writeStringToFile( checksumFile, expectedContents, null );
267 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
268 WebResponse response = sc.getResponse( request );
269 assertResponseOK( response );
271 assertEquals( "Expected file contents", expectedContents, response.getText() );