]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1359] add tests for legacy format translation in WebDAV and other Maven 1 reposi...
authorBrett Porter <brett@apache.org>
Thu, 11 Mar 2010 10:34:42 +0000 (10:34 +0000)
committerBrett Porter <brett@apache.org>
Thu, 11 Mar 2010 10:34:42 +0000 (10:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@921789 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ArtifactExtensionMapping.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletNoProxyTest.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DefaultArtifactMappingProvider.java

index 91d2a20c35b9ae5c109f94e0485f2b0f308562bd..dea81ccc1c825b3af647e74df135ab0f9a42de37 100644 (file)
@@ -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 )
index c7bccf47e6949e33abf816b030af32e078a25889..0f6016beb9295aada9a30091d8f97f8622ae63fc 100644 (file)
@@ -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();
index 8c5b568f199b06840a224c3a5d22a48793cd919a..6b36a972e6962081375daae94582757d05e96a5f 100644 (file)
@@ -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() );
+    }
+
 }
index e57e05ced834efbff2147aca1fe9364d819bcff4..d5e0add7e18407be8d916f3041bf06cef2d90496 100644 (file)
@@ -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" );