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;
26 import org.apache.commons.io.FileUtils;
31 * RepositoryServletTest
33 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36 public class RepositoryServletNoProxyTest
37 extends AbstractRepositoryServletTestCase
39 public void testGetNoProxyChecksumDefaultLayout()
42 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
44 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
45 checksumFile.getParentFile().mkdirs();
47 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
49 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
50 WebResponse response = sc.getResponse( request );
51 assertResponseOK( response );
53 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
56 public void testGetNoProxyChecksumLegacyLayout()
59 String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
61 File checksumFile = new File( repoRootInternal, commonsLangSha1 );
62 checksumFile.getParentFile().mkdirs();
64 FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
66 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
67 + "commons-lang/jars/commons-lang-2.1.jar.sha1" );
68 WebResponse response = sc.getResponse( request );
69 assertResponseOK( response );
71 assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
74 public void testGetNoProxyVersionedMetadataDefaultLayout()
77 String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
78 String expectedMetadataContents = "dummy-versioned-metadata";
80 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
81 metadataFile.getParentFile().mkdirs();
83 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
85 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
86 WebResponse response = sc.getResponse( request );
87 assertResponseOK( response );
89 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
92 public void testGetNoProxyProjectMetadataDefaultLayout()
95 String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
96 String expectedMetadataContents = "dummy-project-metadata";
98 File metadataFile = new File( repoRootInternal, commonsLangMetadata );
99 metadataFile.getParentFile().mkdirs();
101 FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
103 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
104 WebResponse response = sc.getResponse( request );
105 assertResponseOK( response );
107 assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
110 public void testGetNoProxyArtifactDefaultLayout()
113 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
114 String expectedArtifactContents = "dummy-commons-lang-artifact";
116 File artifactFile = new File( repoRootInternal, commonsLangJar );
117 artifactFile.getParentFile().mkdirs();
119 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
121 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
122 WebResponse response = sc.getResponse( request );
123 assertResponseOK( response );
125 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
128 public void testGetNoProxyArtifactLegacyLayout()
131 String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
132 String expectedArtifactContents = "dummy-commons-lang-artifact";
134 File artifactFile = new File( repoRootInternal, commonsLangJar );
135 artifactFile.getParentFile().mkdirs();
137 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
139 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
140 + "commons-lang/jars/commons-lang-2.1.jar" );
141 WebResponse response = sc.getResponse( request );
142 assertResponseOK( response );
144 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
147 public void testGetNoProxySnapshotArtifactDefaultLayout()
150 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
151 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
153 File artifactFile = new File( repoRootInternal, commonsLangJar );
154 artifactFile.getParentFile().mkdirs();
156 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
158 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
159 WebResponse response = sc.getResponse( request );
160 assertResponseOK( response );
162 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
165 public void testGetNoProxySnapshotArtifactLegacyLayout()
168 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
169 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
171 File artifactFile = new File( repoRootInternal, commonsLangJar );
172 artifactFile.getParentFile().mkdirs();
174 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
176 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
177 + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
178 WebResponse response = sc.getResponse( request );
179 assertResponseOK( response );
181 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
184 public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
187 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
188 String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
190 File artifactFile = new File( repoRootInternal, commonsLangJar );
191 artifactFile.getParentFile().mkdirs();
193 FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
195 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
196 WebResponse response = sc.getResponse( request );
197 assertResponseOK( response );
199 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
202 public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
205 String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.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, null );
213 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
214 + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
215 WebResponse response = sc.getResponse( request );
216 assertResponseOK( response );
218 assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );