* 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
{
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;
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();
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
{
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" );
{
sr.shutDown();
}
-
- if (repoRootInternal.exists())
+
+ if ( repoRootInternal.exists() )
{
- FileUtils.deleteDirectory(repoRootInternal);
+ FileUtils.deleteDirectory( repoRootInternal );
}
-
+
+ if ( repoRootLegacy.exists() )
+ {
+ FileUtils.deleteDirectory( repoRootLegacy );
+ }
+
release( archivaConfiguration );
super.tearDown();
import java.io.File;
/**
- * RepositoryServletTest
+ * RepositoryServletTest
*
* @version $Id$
*/
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
{
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 );
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 );
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 );
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
*/
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() );
+ }
+
}