View Javadoc

1   package org.apache.maven.archiva.webdav;
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  import org.apache.commons.io.FileUtils;
26  
27  import java.io.File;
28  
29  /**
30   * RepositoryServletTest 
31   *
32   * @version $Id$
33   */
34  public class RepositoryServletNoProxyTest
35      extends AbstractRepositoryServletTestCase
36  {
37      public void testLastModifiedHeaderExists()
38          throws Exception
39      {
40          String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
41  
42          File checksumFile = new File( repoRootInternal, commonsLangSha1 );
43          checksumFile.getParentFile().mkdirs();
44  
45          FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
46  
47          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
48          WebResponse response = sc.getResponse( request );
49          
50          assertNotNull(response.getHeaderField("last-modified"));
51      }
52      
53      public void testGetNoProxyChecksumDefaultLayout()
54          throws Exception
55      {
56          String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
57  
58          File checksumFile = new File( repoRootInternal, commonsLangSha1 );
59          checksumFile.getParentFile().mkdirs();
60  
61          FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
62  
63          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
64          WebResponse response = sc.getResponse( request );
65          assertResponseOK( response );
66  
67          assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
68      }
69  
70      public void testGetNoProxyChecksumLegacyLayout()
71          throws Exception
72      {
73          String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
74  
75          File checksumFile = new File( repoRootInternal, commonsLangSha1 );
76          checksumFile.getParentFile().mkdirs();
77  
78          FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
79  
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 );
84  
85          assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
86      }
87  
88      public void testGetNoProxyVersionedMetadataDefaultLayout()
89          throws Exception
90      {
91          String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
92          String expectedMetadataContents = "dummy-versioned-metadata";
93  
94          File metadataFile = new File( repoRootInternal, commonsLangMetadata );
95          metadataFile.getParentFile().mkdirs();
96  
97          FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
98  
99          WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
100         WebResponse response = sc.getResponse( request );
101         assertResponseOK( response );
102 
103         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
104     }
105 
106     public void testGetNoProxyProjectMetadataDefaultLayout()
107         throws Exception
108     {
109         String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
110         String expectedMetadataContents = "dummy-project-metadata";
111 
112         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
113         metadataFile.getParentFile().mkdirs();
114 
115         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
116 
117         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
118         WebResponse response = sc.getResponse( request );
119         assertResponseOK( response );
120 
121         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
122     }
123 
124     public void testGetNoProxyGroupMetadataDefaultLayout()
125         throws Exception
126     {
127         String commonsLangMetadata = "commons-lang/maven-metadata.xml";
128         String expectedMetadataContents = "dummy-group-metadata";
129 
130         File metadataFile = new File( repoRootInternal, commonsLangMetadata );
131         metadataFile.getParentFile().mkdirs();
132 
133         FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
134 
135         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
136         WebResponse response = sc.getResponse( request );
137         assertResponseOK( response );
138 
139         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
140     }
141 
142     public void testGetNoProxyArtifactDefaultLayout()
143         throws Exception
144     {
145         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
146         String expectedArtifactContents = "dummy-commons-lang-artifact";
147 
148         File artifactFile = new File( repoRootInternal, commonsLangJar );
149         artifactFile.getParentFile().mkdirs();
150 
151         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
152 
153         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
154         WebResponse response = sc.getResponse( request );
155         assertResponseOK( response );
156 
157         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
158     }
159 
160     public void testGetNoProxyArtifactLegacyLayout()
161         throws Exception
162     {
163         String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
164         String expectedArtifactContents = "dummy-commons-lang-artifact";
165 
166         File artifactFile = new File( repoRootInternal, commonsLangJar );
167         artifactFile.getParentFile().mkdirs();
168 
169         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
170 
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 );
175 
176         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
177     }
178 
179     public void testGetNoProxySnapshotArtifactDefaultLayout()
180         throws Exception
181     {
182         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
183         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
184 
185         File artifactFile = new File( repoRootInternal, commonsLangJar );
186         artifactFile.getParentFile().mkdirs();
187 
188         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
189 
190         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
191         WebResponse response = sc.getResponse( request );
192         assertResponseOK( response );
193 
194         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
195     }
196 
197     public void testGetNoProxySnapshotArtifactLegacyLayout()
198         throws Exception
199     {
200         String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
201         String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
202 
203         File artifactFile = new File( repoRootInternal, commonsLangJar );
204         artifactFile.getParentFile().mkdirs();
205 
206         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
207 
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 );
212 
213         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
214     }
215 
216     public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
217         throws Exception
218     {
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";
221 
222         File artifactFile = new File( repoRootInternal, commonsLangJar );
223         artifactFile.getParentFile().mkdirs();
224 
225         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
226 
227         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
228         WebResponse response = sc.getResponse( request );
229         assertResponseOK( response );
230 
231         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
232     }
233 
234     public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
235         throws Exception
236     {
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";
239 
240         File artifactFile = new File( repoRootInternal, commonsLangJar );
241         artifactFile.getParentFile().mkdirs();
242 
243         FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
244 
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 );
249 
250         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
251     }
252     
253     /**
254      * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
255      */
256     public void testGetNoProxyDualExtensionDefaultLayout()
257         throws Exception
258     {
259         String expectedContents = "the-contents-of-the-dual-extension";
260         String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
261 
262         File checksumFile = new File( repoRootInternal, dualExtensionPath );
263         checksumFile.getParentFile().mkdirs();
264 
265         FileUtils.writeStringToFile( checksumFile, expectedContents, null );
266 
267         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
268         WebResponse response = sc.getResponse( request );
269         assertResponseOK( response );
270 
271         assertEquals( "Expected file contents", expectedContents, response.getText() );
272     }
273 }