From 5c18f8b344cc97900cb80e46fd6ea410ea700d8f Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 11 Mar 2010 10:34:42 +0000 Subject: [PATCH] [MRM-1359] add tests for legacy format translation in WebDAV and other Maven 1 repository notes git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921789 13f79535-47bb-0310-9956-ffa450edef68 --- .../content/ArtifactExtensionMapping.java | 2 +- .../AbstractRepositoryServletTestCase.java | 60 ++-- .../webdav/RepositoryServletNoProxyTest.java | 283 +++++++++++++++++- .../DefaultArtifactMappingProvider.java | 3 +- 4 files changed, 300 insertions(+), 48 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java index 91d2a20c3..dea81ccc1 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java @@ -31,7 +31,7 @@ public class ArtifactExtensionMapping { public static final String MAVEN_ONE_PLUGIN = "maven-one-plugin"; - // TODO: won't support extensions - need to refactor away this class + // TODO: now only used in Maven 1, we should be using M1 specific mappings private static final ArtifactMappingProvider mapping = new DefaultArtifactMappingProvider(); public static String getExtension( String type ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java index c7bccf47e..0f6016beb 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java @@ -19,24 +19,22 @@ package org.apache.maven.archiva.webdav; * under the License. */ -import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.HttpUnitOptions; +import com.meterware.httpunit.WebResponse; import com.meterware.servletunit.ServletRunner; import com.meterware.servletunit.ServletUnitClient; +import junit.framework.Assert; import net.sf.ehcache.CacheManager; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; -import org.apache.maven.archiva.webdav.RepositoryServlet; import org.codehaus.plexus.spring.PlexusInSpringTestCase; -import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; - -import junit.framework.Assert; +import javax.servlet.http.HttpServletResponse; /** * AbstractRepositoryServletTestCase @@ -48,10 +46,14 @@ public abstract class AbstractRepositoryServletTestCase { protected static final String REPOID_INTERNAL = "internal"; + protected static final String REPOID_LEGACY = "legacy"; + protected ServletUnitClient sc; protected File repoRootInternal; - + + protected File repoRootLegacy; + private ServletRunner sr; protected ArchivaConfiguration archivaConfiguration; @@ -130,6 +132,14 @@ public abstract class AbstractRepositoryServletTestCase return repo; } + protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location, + String layout, boolean blockRedeployments ) + { + ManagedRepositoryConfiguration repo = createManagedRepository( id, name, location, blockRedeployments ); + repo.setLayout( layout ); + return repo; + } + protected RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url ) { RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration(); @@ -139,29 +149,6 @@ public abstract class AbstractRepositoryServletTestCase return repo; } - protected void dumpResponse( WebResponse response ) - { - System.out.println( "---(response)---" ); - System.out.println( "" + response.getResponseCode() + " " + response.getResponseMessage() ); - - String headerNames[] = response.getHeaderFieldNames(); - for ( String headerName : headerNames ) - { - System.out.println( "[header] " + headerName + ": " + response.getHeaderField( headerName ) ); - } - - System.out.println( "---(text)---" ); - try - { - System.out.println( response.getText() ); - } - catch ( IOException e ) - { - System.err.print( "[Exception] : " ); - e.printStackTrace( System.err ); - } - } - protected void saveConfiguration( ArchivaConfiguration archivaConfiguration ) throws Exception { @@ -182,9 +169,11 @@ public abstract class AbstractRepositoryServletTestCase archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); repoRootInternal = new File( appserverBase, "data/repositories/internal" ); + repoRootLegacy = new File( appserverBase, "data/repositories/legacy" ); Configuration config = archivaConfiguration.getConfiguration(); config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal, true ) ); + config.addManagedRepository( createManagedRepository( REPOID_LEGACY, "Legacy Format Test Repo", repoRootLegacy, "legacy", true ) ); saveConfiguration( archivaConfiguration ); CacheManager.getInstance().removeCache( "url-failures-cache" ); @@ -215,12 +204,17 @@ public abstract class AbstractRepositoryServletTestCase { sr.shutDown(); } - - if (repoRootInternal.exists()) + + if ( repoRootInternal.exists() ) { - FileUtils.deleteDirectory(repoRootInternal); + FileUtils.deleteDirectory( repoRootInternal ); } - + + if ( repoRootLegacy.exists() ) + { + FileUtils.deleteDirectory( repoRootLegacy ); + } + release( archivaConfiguration ); super.tearDown(); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletNoProxyTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletNoProxyTest.java index 8c5b568f1..6b36a972e 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletNoProxyTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletNoProxyTest.java @@ -27,7 +27,7 @@ import org.apache.commons.io.FileUtils; import java.io.File; /** - * RepositoryServletTest + * RepositoryServletTest * * @version $Id$ */ @@ -46,10 +46,10 @@ public class RepositoryServletNoProxyTest WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 ); WebResponse response = sc.getResponse( request ); - - assertNotNull(response.getHeaderField("last-modified")); + + assertNotNull( response.getHeaderField( "last-modified" ) ); } - + public void testGetNoProxyChecksumDefaultLayout() throws Exception { @@ -77,8 +77,8 @@ public class RepositoryServletNoProxyTest FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null ); - WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" - + "commons-lang/jars/commons-lang-2.1.jar.sha1" ); + WebRequest request = new GetMethodWebRequest( + "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar.sha1" ); WebResponse response = sc.getResponse( request ); assertResponseOK( response ); @@ -168,8 +168,8 @@ public class RepositoryServletNoProxyTest FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); - WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" - + "commons-lang/jars/commons-lang-2.1.jar" ); + WebRequest request = new GetMethodWebRequest( + "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1.jar" ); WebResponse response = sc.getResponse( request ); assertResponseOK( response ); @@ -205,8 +205,8 @@ public class RepositoryServletNoProxyTest FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); - WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" - + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" ); + WebRequest request = new GetMethodWebRequest( + "http://machine.com/repository/internal/" + "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" ); WebResponse response = sc.getResponse( request ); assertResponseOK( response ); @@ -242,14 +242,14 @@ public class RepositoryServletNoProxyTest 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" ); + 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 ); assertResponseOK( response ); assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); } - + /** * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error */ @@ -270,4 +270,261 @@ public class RepositoryServletNoProxyTest assertEquals( "Expected file contents", expectedContents, response.getText() ); } + + public void testGetNoProxyDistributionLegacyLayout() + throws Exception + { + String expectedContents = "the-contents-of-the-dual-extension"; + String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.zip"; + + File checksumFile = new File( repoRootInternal, dualExtensionPath ); + checksumFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( checksumFile, expectedContents, null ); + + WebRequest request = new GetMethodWebRequest( + "http://machine.com/repository/internal/" + "org.project/distributions/example-presentation-3.2.zip" ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedContents, response.getText() ); + } + + public void testGetNoProxyChecksumDefaultLayoutManagedLegacy() + throws Exception + { + String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1"; + + File checksumFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar.sha1" ); + checksumFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", "dummy-checksum", response.getText() ); + } + + public void testGetNoProxyChecksumLegacyLayoutManagedLegacy() + throws Exception + { + String commonsLangSha1 = "commons-lang/jars/commons-lang-2.1.jar.sha1"; + File checksumFile = new File( repoRootLegacy, commonsLangSha1 ); + checksumFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangSha1 ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", "dummy-checksum", response.getText() ); + } + + public void testGetNoProxyVersionedMetadataDefaultLayoutManagedLegacy() + throws Exception + { + String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml"; + String expectedMetadataContents = "dummy-versioned-metadata"; + + // TODO: find out what this should be from maven-artifact + File metadataFile = new File( repoRootLegacy, commonsLangMetadata ); + metadataFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); + } + + public void testGetNoProxyProjectMetadataDefaultLayoutManagedLegacy() + throws Exception + { + // TODO: find out what it is meant to be from maven-artifact + String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml"; + String expectedMetadataContents = "dummy-project-metadata"; + + File metadataFile = new File( repoRootLegacy, commonsLangMetadata ); + metadataFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); + } + + public void testGetNoProxyGroupMetadataDefaultLayoutManagedLegacy() + throws Exception + { + String commonsLangMetadata = "commons-lang/maven-metadata.xml"; + String expectedMetadataContents = "dummy-group-metadata"; + + File metadataFile = new File( repoRootLegacy, commonsLangMetadata ); + metadataFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangMetadata ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedMetadataContents, response.getText() ); + } + + public void testGetNoProxyArtifactDefaultLayoutManagedLegacy() + throws Exception + { + String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar"; + String expectedArtifactContents = "dummy-commons-lang-artifact"; + + File artifactFile = new File( repoRootLegacy, "commons-lang/jars/commons-lang-2.1.jar" ); + artifactFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); + } + + public void testGetNoProxyArtifactLegacyLayoutManagedLegacy() + throws Exception + { + String commonsLangJar = "commons-lang/jars/commons-lang-2.1.jar"; + String expectedArtifactContents = "dummy-commons-lang-artifact"; + + File artifactFile = new File( repoRootLegacy, commonsLangJar ); + artifactFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); + } + + public void testGetNoProxySnapshotArtifactDefaultLayoutManagedLegacy() + throws Exception + { + 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( repoRootLegacy, "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar" ); + artifactFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); + } + + public void testGetNoProxySnapshotArtifactLegacyLayoutManagedLegacy() + throws Exception + { + String commonsLangJar = "commons-lang/jars/commons-lang-2.1-SNAPSHOT.jar"; + String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact"; + + File artifactFile = new File( repoRootLegacy, commonsLangJar ); + artifactFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); + } + + public void testGetNoProxyTimestampedSnapshotArtifactDefaultLayoutManagedLegacy() + throws Exception + { + String filename = "commons-lang-2.1-20050821.023400-1.jar"; + String commonsLangJar = "commons-lang/commons-lang/2.1-SNAPSHOT/" + filename; + String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact"; + + File artifactFile = new File( repoRootLegacy, "commons-lang/jars/" + filename ); + artifactFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); + } + + public void testGetNoProxyTimestampedSnapshotArtifactLegacyLayoutManagedLegacy() + throws Exception + { + String commonsLangJar = "commons-lang/jars/commons-lang-2.1-20050821.023400-1.jar"; + String expectedArtifactContents = "dummy-commons-lang-snapshot-artifact"; + + File artifactFile = new File( repoRootLegacy, commonsLangJar ); + artifactFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + commonsLangJar ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedArtifactContents, response.getText() ); + } + + /** + * [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error + */ + public void testGetNoProxyDualExtensionDefaultLayoutManagedLegacy() + throws Exception + { + String expectedContents = "the-contents-of-the-dual-extension"; + String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip"; + + File checksumFile = new File( repoRootLegacy, "org.project/distributions/example-presentation-3.2.xml.zip" ); + checksumFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( checksumFile, expectedContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedContents, response.getText() ); + } + + public void testGetNoProxyDistributionLegacyLayoutManagedLegacy() + throws Exception + { + String expectedContents = "the-contents-of-the-dual-extension"; + String dualExtensionPath = "org.project/distributions/example-presentation-3.2.zip"; + + File checksumFile = new File( repoRootLegacy, dualExtensionPath ); + checksumFile.getParentFile().mkdirs(); + + FileUtils.writeStringToFile( checksumFile, expectedContents, null ); + + WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/legacy/" + dualExtensionPath ); + WebResponse response = sc.getResponse( request ); + assertResponseOK( response ); + + assertEquals( "Expected file contents", expectedContents, response.getText() ); + } + } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java index e57e05ced..d5e0add7e 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java @@ -55,7 +55,8 @@ public class DefaultArtifactMappingProvider // Additional type typeToExtensionMap.put( "maven-archetype", "jar" ); - // TODO: move to maven 1 plugin + // TODO: move to maven 1 plugin - but note that it won't have the interface type and might need to reproduce the + // same thing typeToExtensionMap.put( "maven-one-plugin", "jar" ); typeToExtensionMap.put( "javadoc.jar", "jar" ); typeToExtensionMap.put( "uberjar", "jar" ); -- 2.39.5