1 package org.apache.maven.archiva.web.repository;
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
32 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
35 public class RepositoryServletNoProxyTest
36 extends AbstractRepositoryServletTestCase
38 public void testGetNoProxyChecksumDefaultLayout()
41 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
43 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
44 checksumFile.getParentFile().mkdirs();
46 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
48 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
49 WebResponse response = sc.getResponse( request );
50 assertResponseOK( response );
52 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
55 public void testGetNoProxyChecksumLegacyLayout()
58 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
60 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
61 checksumFile.getParentFile().mkdirs();
63 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
65 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
66 + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
67 WebResponse response = sc.getResponse( request );
68 assertResponseOK( response );
70 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
73 public void testGetNoProxyVersionedMetadataDefaultLayout()
76 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
77 String expectedMetadataContents = "dummy-versioned-metadata";
79 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
80 metadataFile.getParentFile().mkdirs();
82 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
84 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
85 WebResponse response = sc.getResponse( request );
86 assertResponseOK( response );
88 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
91 public void testGetNoProxyProjectMetadataDefaultLayout()
94 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
95 String expectedMetadataContents = "dummy-project-metadata";
97 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
98 metadataFile.getParentFile().mkdirs();
100 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
102 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
103 WebResponse response = sc.getResponse( request );
104 assertResponseOK( response );
106 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
109 public void testGetNoProxyGroupMetadataDefaultLayout()
112 String commonsLangMetadata = "commons-lang/maven-metadata.xml";
113 String expectedMetadataContents = "dummy-group-metadata";
115 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
116 metadataFile.getParentFile().mkdirs();
118 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
120 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
121 WebResponse response = sc.getResponse( request );
122 assertResponseOK( response );
124 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
127 public void testGetNoProxyArtifactDefaultLayout()
130 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
131 String expectedArtifactContents = "dummy-commons-lang-artifact";
133 File artifactFile = new File( repoRootInternal, commonsLangJar );
134 artifactFile.getParentFile().mkdirs();
136 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
138 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
139 WebResponse response = sc.getResponse( request );
140 assertResponseOK( response );
142 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
145 public void testGetNoProxyArtifactLegacyLayout()
148 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
149 String expectedArtifactContents = "dummy-commons-lang-artifact";
151 File artifactFile = new File( repoRootInternal, commonsLangJar );
152 artifactFile.getParentFile().mkdirs();
154 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
156 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
157 + "commons-lang/jars/commons-lang-2.1.jar" );
158 WebResponse response = sc.getResponse( request );
159 assertResponseOK( response );
161 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
164 public void testGetNoProxySnapshotArtifactDefaultLayout()
167 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
168 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
170 File artifactFile = new File( repoRootInternal, commonsLangJar );
171 artifactFile.getParentFile().mkdirs();
173 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
175 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
176 WebResponse response = sc.getResponse( request );
177 assertResponseOK( response );
179 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
182 public void testGetNoProxySnapshotArtifactLegacyLayout()
185 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
186 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
188 File artifactFile = new File( repoRootInternal, commonsLangJar );
189 artifactFile.getParentFile().mkdirs();
191 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
193 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
194 + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
195 WebResponse response = sc.getResponse( request );
196 assertResponseOK( response );
198 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
201 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
204 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.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 = sc.getResponse( request );
214 assertResponseOK( response );
216 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
219 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
222 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
223 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
225 File artifactFile = new File( repoRootInternal, commonsLangJar );
226 artifactFile.getParentFile().mkdirs();
228 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
230 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
231 + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
232 WebResponse response = sc.getResponse( request );
233 assertResponseOK( response );
235 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
239 * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
241 public void testGetNoProxyDualExtensionDefaultLayout()
244 String expectedContents = "the-contents-of-the-dual-extension";
245 String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
247 File checksumFile = new File( repoRootInternal, dualExtensionPath );
248 checksumFile.getParentFile().mkdirs();
250 FileUtils.writeStringToFile( checksumFile, expectedContents, null );
252 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
253 WebResponse response = sc.getResponse( request );
254 assertResponseOK( response );
256 assertEquals( "Expected file contents", expectedContents, response.getText() );