]> source.dussan.org Git - archiva.git/blob
3c5b9cae0db0823b400ad7e5b0fe0edeb38c6b9a
[archiva.git] /
1 package org.apache.maven.archiva.web.repository;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.WebRequest;
24 import com.meterware.httpunit.WebResponse;
25
26 import org.apache.commons.io.FileUtils;
27
28 import java.io.File;
29
30 /**
31  * RepositoryServletTest 
32  *
33  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
34  * @version $Id$
35  */
36 public class RepositoryServletNoProxyTest
37     extends AbstractRepositoryServletTestCase
38 {
39     public void testGetNoProxyChecksumDefaultLayout()
40         throws Exception
41     {
42         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
43
44         File checksumFile = new File( repoRootInternal, commonsLangSha1 );
45         checksumFile.getParentFile().mkdirs();
46
47         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
48
49         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
50         WebResponse response = sc.getResponse( request );
51         assertResponseOK( response );
52
53         assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
54     }
55
56     public void testGetNoProxyChecksumLegacyLayout()
57         throws Exception
58     {
59         String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
60
61         File checksumFile = new File( repoRootInternal, commonsLangSha1 );
62         checksumFile.getParentFile().mkdirs();
63
64         FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
65
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 );
70
71         assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
72     }
73
74     public void testGetNoProxyVersionedMetadataDefaultLayout()
75         throws Exception
76     {
77         String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
78         String expectedMetadataContents = "dummy-versioned-metadata";
79
80         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
81         metadataFile.getParentFile().mkdirs();
82
83         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
84
85         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
86         WebResponse response = sc.getResponse( request );
87         assertResponseOK( response );
88
89         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
90     }
91
92     public void testGetNoProxyProjectMetadataDefaultLayout()
93         throws Exception
94     {
95         String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
96         String expectedMetadataContents = "dummy-project-metadata";
97
98         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
99         metadataFile.getParentFile().mkdirs();
100
101         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
102
103         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
104         WebResponse response = sc.getResponse( request );
105         assertResponseOK( response );
106
107         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
108     }
109
110     public void testGetNoProxyArtifactDefaultLayout()
111         throws Exception
112     {
113         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
114         String expectedArtifactContents = "dummy-commons-lang-artifact";
115
116         File artifactFile = new File( repoRootInternal, commonsLangJar );
117         artifactFile.getParentFile().mkdirs();
118
119         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
120
121         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
122         WebResponse response = sc.getResponse( request );
123         assertResponseOK( response );
124
125         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
126     }
127
128     public void testGetNoProxyArtifactLegacyLayout()
129         throws Exception
130     {
131         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
132         String expectedArtifactContents = "dummy-commons-lang-artifact";
133
134         File artifactFile = new File( repoRootInternal, commonsLangJar );
135         artifactFile.getParentFile().mkdirs();
136
137         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
138
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 );
143
144         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
145     }
146
147     public void testGetNoProxySnapshotArtifactDefaultLayout()
148         throws Exception
149     {
150         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
151         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
152
153         File artifactFile = new File( repoRootInternal, commonsLangJar );
154         artifactFile.getParentFile().mkdirs();
155
156         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
157
158         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
159         WebResponse response = sc.getResponse( request );
160         assertResponseOK( response );
161
162         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
163     }
164
165     public void testGetNoProxySnapshotArtifactLegacyLayout()
166         throws Exception
167     {
168         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
169         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
170
171         File artifactFile = new File( repoRootInternal, commonsLangJar );
172         artifactFile.getParentFile().mkdirs();
173
174         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
175
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 );
180
181         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
182     }
183
184     public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
185         throws Exception
186     {
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";
189
190         File artifactFile = new File( repoRootInternal, commonsLangJar );
191         artifactFile.getParentFile().mkdirs();
192
193         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
194
195         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
196         WebResponse response = sc.getResponse( request );
197         assertResponseOK( response );
198
199         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
200     }
201
202     public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
203         throws Exception
204     {
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";
207
208         File artifactFile = new File( repoRootInternal, commonsLangJar );
209         artifactFile.getParentFile().mkdirs();
210
211         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
212
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 );
217
218         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
219     }
220 }