]> source.dussan.org Git - archiva.git/commitdiff
[MRM-567] Unable to download plugin SNAPSHOT's from proxy.
authorJoakim Erdfelt <joakime@apache.org>
Wed, 24 Oct 2007 00:39:14 +0000 (00:39 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Wed, 24 Oct 2007 00:39:14 +0000 (00:39 +0000)
Adding tests for non-proxy downloads of SNAPSHOT first (gotta test the basics)

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@587719 13f79535-47bb-0310-9956-ffa450edef68

archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java

index 3c580357bfc7cc29e0438ef60bda6af3b0fd2d9d..90034d4b08a11f9347d7a96dd9f5da098e23b8df 100644 (file)
@@ -12,6 +12,7 @@
 
 application/andrew-inset                 ez
 application/atom+xml                     atom
+application/java-archive                 jar
 application/mac-binhex40                 hqx
 application/mac-compactpro               cpt
 application/mathml+xml                   mathml
@@ -45,7 +46,6 @@ application/x-dvi                        dvi
 application/x-futuresplash               spl
 application/x-gtar                       gtar
 application/x-hdf                        hdf
-application/x-jar                        jar
 application/x-java-jnlp-file             jnlp
 application/x-javascript                 js
 application/x-koan                       skp skd skt skm
index fb4560bbe63af6d5f4c6e5a81e0bf2e208a3a779..f78ab2847ec2d50e58679763d53f4de0fb880512 100644 (file)
@@ -315,6 +315,96 @@ public class RepositoryServletTest
         assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
     }
     
+    public void testGetNoProxySnapshotArtifactDefaultLayout()
+        throws Exception
+    {
+        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+        assertNotNull( servlet );
+        assertRepositoryValid( servlet, REPOSITORY_ID );
+
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repositoryLocation, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
+        WebResponse response = sc.getResponse( request );
+        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+    
+    public void testGetNoProxySnapshotArtifactLegacyLayout()
+        throws Exception
+    {
+        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+        assertNotNull( servlet );
+        assertRepositoryValid( servlet, REPOSITORY_ID );
+
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-SNAPSHOT.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repositoryLocation, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + 
+                                                      "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" );
+        WebResponse response = sc.getResponse( request );
+        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+    
+    public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayout()
+        throws Exception
+    {
+        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+        assertNotNull( servlet );
+        assertRepositoryValid( servlet, REPOSITORY_ID );
+
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repositoryLocation, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
+        WebResponse response = sc.getResponse( request );
+        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+    
+    public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayout()
+        throws Exception
+    {
+        RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+        assertNotNull( servlet );
+        assertRepositoryValid( servlet, REPOSITORY_ID );
+
+        String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/commons-lang-2.1-20050821.023400-1.jar";
+        String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact";
+
+        File artifactFile = new File( repositoryLocation, commonsLangJar );
+        artifactFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
+            + "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar" );
+        WebResponse response = sc.getResponse( request );
+        assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
+    }
+    
     public void testMimeTypesAvailable()
         throws Exception
     {
@@ -325,9 +415,10 @@ public class RepositoryServletTest
         assertEquals( "sha1", "text/plain", mimeTypes.getMimeType( "foo.sha1" ) );
         assertEquals( "md5", "text/plain", mimeTypes.getMimeType( "foo.md5" ) );
         assertEquals( "pgp", "application/pgp-encrypted", mimeTypes.getMimeType( "foo.pgp" ) );
+        assertEquals( "jar", "application/java-archive", mimeTypes.getMimeType( "foo.jar" ) );
     }
 
-    private void dumpResponse( WebResponse response )
+    public static void dumpResponse( WebResponse response )
     {
         System.out.println( "---(response)---" );
         System.out.println( "" + response.getResponseCode() + " " + response.getResponseMessage() );
@@ -355,18 +446,14 @@ public class RepositoryServletTest
         ManagedRepositoryConfiguration repository = servlet.getRepository( repoId );
         assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository );
         File repoRoot = new File( repository.getLocation() );
-        assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", repoRoot
-            .exists()
-            && repoRoot.isDirectory() );
+        assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", 
+                    repoRoot.exists() && repoRoot.isDirectory() );
     }
 
     private void saveConfiguration()
         throws Exception
     {
         configuration.save( configuration.getConfiguration() );
-        // TODO it would be better to use a mock configuration and "save" to more accurately reflect the calls made
-        // RepositoryServlet servlet
-        // servlet.configurationEvent( new ConfigurationEvent( ConfigurationEvent.SAVED ) );
     }
 
     private ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location )