From: Joakim Erdfelt Date: Wed, 24 Oct 2007 00:39:14 +0000 (+0000) Subject: [MRM-567] Unable to download plugin SNAPSHOT's from proxy. X-Git-Tag: archiva-1.0-beta-3~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6ab9c44b0c58bf463adda0f4f8f5fd9da6aee75b;p=archiva.git [MRM-567] Unable to download plugin SNAPSHOT's from proxy. 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 --- diff --git a/archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt b/archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt index 3c580357b..90034d4b0 100644 --- a/archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt +++ b/archiva-web/archiva-webapp/src/main/resources/org/codehaus/plexus/webdav/util/mime-types.txt @@ -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 diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java index fb4560bbe..f78ab2847 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java @@ -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 )