You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/10/26 01:39:07 UTC
svn commit: r588391 [1/2] - in
/maven/archiva/trunk/archiva-web/archiva-webapp: ./
src/main/java/org/apache/maven/archiva/web/repository/ src/main/resources/
src/main/resources/META-INF/plexus/ src/main/resources/org/codehaus/
src/test/java/org/apache/...
Author: joakime
Date: Thu Oct 25 16:39:05 2007
New Revision: 588391
URL: http://svn.apache.org/viewvc?rev=588391&view=rev
Log:
[MRM-567] Unable to download plugin SNAPSHOT's from proxy.
Adding unit tests for Artifact downloads via proxied requests.
Splitting RepositoryServlet testcase up to work around PlexusTestCase bug (the configuration within the plexus container consumed the entire java heap, causing an OOM, switching to smaller test cases gets around this bug, but its still not nice bug to hit.)
Reworking MimeTypes to allow for loading of archiva custom configuration. (mainly to get around the .getClassLoader().getResource() differences between command line / ide unit testing)
Added:
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java
- copied, changed from r587923, maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedReleasePolicyTest.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedSnapshotPolicyTest.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.java (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/resources/META-INF/
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/resources/META-INF/plexus/
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/resources/META-INF/plexus/components.xml (with props)
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletSecurityTest.xml (with props)
Removed:
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/org/codehaus/
Modified:
maven/archiva/trunk/archiva-web/archiva-webapp/pom.xml
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/UnauthenticatedRepositoryServlet.java
maven/archiva/trunk/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/repository/RepositoryServletTest.xml
Modified: maven/archiva/trunk/archiva-web/archiva-webapp/pom.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/pom.xml?rev=588391&r1=588390&r2=588391&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/pom.xml (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/pom.xml Thu Oct 25 16:39:05 2007
@@ -192,10 +192,12 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xwork-integration</artifactId>
</dependency>
+ <!--
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
+ -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
@@ -211,6 +213,13 @@
<artifactId>activation</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- Test Scoped -->
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>6.1.5</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>httpunit</groupId>
<artifactId>httpunit</artifactId>
@@ -238,6 +247,22 @@
</dependencies>
<build>
<plugins>
+ <!--
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <argLine>-agentlib:yjpagent</argLine>
+ <excludes>
+ <exclude>**/Abstract*</exclude>
+ <exclude>**/*TestCase.java</exclude>
+ <exclude>**/*Tests.java</exclude>
+ <exclude>**/*TestSuite.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,72 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.webdav.util.MimeTypes;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Custom Archiva MimeTypes loader for plexus-webdav's {@link MimeTypes}
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ * @todo Support custom mime types from archiva-configuration.
+ *
+ * @plexus.component role="org.apache.maven.archiva.web.repository.ArchivaMimeTypeLoader"
+ */
+public class ArchivaMimeTypeLoader
+ implements Initializable
+{
+ /**
+ * @plexus.requirement
+ */
+ private MimeTypes mimeTypes;
+
+ public void initialize()
+ throws InitializationException
+ {
+ // TODO: Make mime types loading configurable.
+ // Load the mime types from archiva location.
+ if ( mimeTypes.getMimeType( "sha1" ) == null )
+ {
+ URL url = this.getClass().getClassLoader().getResource( "/archiva-mime-types.txt" );
+ if ( url == null )
+ {
+ url = this.getClass().getClassLoader().getResource( "archiva-mime-types.txt" );
+ }
+
+ if ( url != null )
+ {
+ try
+ {
+ mimeTypes.load( url.openStream() );
+ }
+ catch ( IOException e )
+ {
+ throw new InitializationException( "Unable to load archiva-mime-types.txt : " + e.getMessage(), e );
+ }
+ }
+ }
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoader.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java?rev=588391&r1=588390&r2=588391&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java Thu Oct 25 16:39:05 2007
@@ -68,12 +68,16 @@
private ArchivaConfiguration configuration;
private Map<String, ManagedRepositoryConfiguration> repositoryMap;
+
+ private ArchivaMimeTypeLoader mimeTypeLoader;
public synchronized void initComponents()
throws ServletException
{
super.initComponents();
-
+
+ mimeTypeLoader = (ArchivaMimeTypeLoader) lookup( ArchivaMimeTypeLoader.class.getName() );
+
securitySystem = (SecuritySystem) lookup( SecuritySystem.ROLE );
httpAuth = (HttpAuthenticator) lookup( HttpAuthenticator.ROLE, "basic" );
audit = (AuditLog) lookup( AuditLog.ROLE );
@@ -106,6 +110,53 @@
server.setUseIndexHtml( true );
server.addListener( audit );
}
+ }
+
+ @Override
+ public void destroy()
+ {
+ try
+ {
+ release( securitySystem );
+ }
+ catch ( ServletException e )
+ {
+ log( "Unable to release SecuritySystem : " + e.getMessage(), e );
+ }
+ try
+ {
+ release( httpAuth );
+ }
+ catch ( ServletException e )
+ {
+ log( "Unable to release HttpAuth : " + e.getMessage(), e );
+ }
+ try
+ {
+ release( audit );
+ }
+ catch ( ServletException e )
+ {
+ log( "Unable to release AuditLog : " + e.getMessage(), e );
+ }
+ try
+ {
+ release( configuration );
+ }
+ catch ( ServletException e )
+ {
+ log( "Unable to release ArchivaConfiguration : " + e.getMessage(), e );
+ }
+ try
+ {
+ release( mimeTypeLoader );
+ }
+ catch ( ServletException e )
+ {
+ log( "Unable to release ArchivaMimeTypeLoader : " + e.getMessage(), e );
+ }
+
+ super.destroy();
}
@Override
Modified: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml?rev=588391&r1=588390&r2=588391&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/META-INF/plexus/application.xml Thu Oct 25 16:39:05 2007
@@ -198,6 +198,15 @@
</otherProperties>
</configuration>
</component>
+
+ <component>
+ <role>org.codehaus.plexus.webdav.util.MimeTypes</role>
+ <implementation>org.codehaus.plexus.webdav.util.MimeTypes</implementation>
+ <description>MimeTypes</description>
+ <configuration>
+ <resource>archiva-mime-types.txt</resource>
+ </configuration>
+ </component>
<!--
| Logger manager
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt Thu Oct 25 16:39:05 2007
@@ -0,0 +1,127 @@
+# This file controls what Internet media types are sent to the client for
+# given file extension(s). Sending the correct media type to the client
+# is important so they know how to handle the content of the file.
+# Extra types can either be added here or by using an AddType directive
+# in your config files. For more information about Internet media types,
+# please read RFC 2045, 2046, 2047, 2048, and 2077. The Internet media type
+# registry is at <http://www.iana.org/assignments/media-types/>.
+
+# MIME type Extensions
+
+application/andrew-inset ez
+application/atom+xml atom
+application/java-archive jar
+application/mac-binhex40 hqx
+application/mac-compactpro cpt
+application/mathml+xml mathml
+application/msword doc
+application/octet-stream bin dms lha lzh exe class so dll dmg
+application/oda oda
+application/ogg ogg
+application/pdf pdf
+application/pgp-encrypted pgp
+application/postscript ai eps ps
+application/rdf+xml rdf
+application/smil smi smil
+application/srgs gram
+application/srgs+xml grxml
+application/vnd.mif mif
+application/vnd.mozilla.xul+xml xul
+application/vnd.ms-excel xls
+application/vnd.ms-powerpoint ppt
+application/vnd.rn-realmedia rm
+application/vnd.wap.wbxml wbxml
+application/vnd.wap.wmlc wmlc
+application/vnd.wap.wmlscriptc wmlsc
+application/voicexml+xml vxml
+application/x-bcpio bcpio
+application/x-cdlink vcd
+application/x-chess-pgn pgn
+application/x-cpio cpio
+application/x-csh csh
+application/x-director dcr dir dxr
+application/x-dvi dvi
+application/x-futuresplash spl
+application/x-gtar gtar
+application/x-hdf hdf
+application/x-java-jnlp-file jnlp
+application/x-javascript js
+application/x-koan skp skd skt skm
+application/x-latex latex
+application/x-netcdf nc cdf
+application/x-sh sh
+application/x-shar shar
+application/x-shockwave-flash swf
+application/x-stuffit sit
+application/x-sv4cpio sv4cpio
+application/x-sv4crc sv4crc
+application/x-tar tar
+application/x-tcl tcl
+application/x-tex tex
+application/x-texinfo texinfo texi
+application/x-troff t tr roff
+application/x-troff-man man
+application/x-troff-me me
+application/x-troff-ms ms
+application/x-ustar ustar
+application/x-wais-source src
+application/xhtml+xml xhtml xht
+application/xml xml xsl
+application/xml-dtd dtd
+application/xslt+xml xslt
+application/zip zip
+audio/basic au snd
+audio/midi mid midi kar
+audio/mpeg mpga mp2 mp3
+audio/x-aiff aif aiff aifc
+audio/x-mpegurl m3u
+audio/x-pn-realaudio ram ra
+audio/x-wav wav
+chemical/x-pdb pdb
+chemical/x-xyz xyz
+image/bmp bmp
+image/cgm cgm
+image/gif gif
+image/ief ief
+image/jp2 jp2
+image/jpeg jpeg jpg jpe
+image/pict pict pic pct
+image/png png
+image/svg+xml svg
+image/tiff tiff tif
+image/vnd.djvu djvu djv
+image/vnd.wap.wbmp wbmp
+image/x-cmu-raster ras
+image/x-icon ico
+image/x-macpaint pntg pnt mac
+image/x-portable-anymap pnm
+image/x-portable-bitmap pbm
+image/x-portable-graymap pgm
+image/x-portable-pixmap ppm
+image/x-quicktime qtif qti
+image/x-rgb rgb
+image/x-xbitmap xbm
+image/x-xpixmap xpm
+image/x-xwindowdump xwd
+model/iges igs iges
+model/mesh msh mesh silo
+model/vrml wrl vrml
+text/calendar ics ifb
+text/css css
+text/html html htm
+text/plain asc txt sha1 md5
+text/richtext rtx
+text/rtf rtf
+text/sgml sgml sgm
+text/tab-separated-values tsv
+text/vnd.wap.wml wml
+text/vnd.wap.wmlscript wmls
+text/x-setext etx
+video/mp4 mp4
+video/mpeg mpeg mpg mpe
+video/quicktime qt mov
+video/vnd.mpegurl mxu m4u
+video/x-dv dv dif
+video/x-msvideo avi
+video/x-sgi-movie movie
+x-conference/x-cooltalk ice
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/archiva-mime-types.txt
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,301 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebResponse;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.policies.CachedFailuresPolicy;
+import org.apache.maven.archiva.policies.ChecksumPolicy;
+import org.apache.maven.archiva.policies.ReleasesPolicy;
+import org.apache.maven.archiva.policies.SnapshotsPolicy;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
+import org.mortbay.jetty.servlet.DefaultServlet;
+import org.mortbay.jetty.servlet.ServletHandler;
+
+import java.io.File;
+
+/**
+ * AbstractRepositoryServletProxiedTestCase
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractRepositoryServletProxiedTestCase
+ extends AbstractRepositoryServletTestCase
+{
+ class RemoteRepoInfo
+ {
+ public String id;
+
+ public String url;
+
+ public String context;
+
+ public Server server;
+
+ public File root;
+
+ public RemoteRepositoryConfiguration config;
+ }
+
+ protected static final long ONE_SECOND = ( 1000 * 60 );
+
+ protected static final long ONE_MINUTE = ( ONE_SECOND * 60 );
+
+ protected static final long ONE_HOUR = ( ONE_MINUTE * 60 );
+
+ protected static final long ONE_DAY = ( ONE_HOUR * 24 );
+
+ protected static final long OVER_ONE_HOUR = ( ONE_HOUR + ONE_MINUTE );
+
+ protected static final long OVER_ONE_DAY = ( ONE_DAY + ONE_HOUR );
+
+ protected static final long OLDER = ( -1 );
+
+ protected static final long NEWER = 0;
+
+ protected static final int EXPECT_MANAGED_CONTENTS = 1;
+
+ protected static final int EXPECT_REMOTE_CONTENTS = 2;
+
+ protected static final int EXPECT_NOT_FOUND = 3;
+
+ protected static final boolean HAS_MANAGED_COPY = true;
+
+ protected static final boolean NO_MANAGED_COPY = false;
+
+ protected RemoteRepoInfo remoteCentral;
+
+ protected RemoteRepoInfo remoteSnapshots;
+
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ }
+
+ public RemoteRepoInfo createSnapshotsRepo()
+ throws Exception
+ {
+ RemoteRepoInfo snapshots = new RemoteRepoInfo();
+ snapshots.id = "snapshots";
+ snapshots.context = "/snapshots";
+ snapshots.root = getTestFile( "target/remote-repos/snapshots/" );
+
+ // Remove exising root contents.
+ if ( snapshots.root.exists() )
+ {
+ FileUtils.deleteDirectory( snapshots.root );
+ }
+
+ // Establish root directory.
+ if ( !snapshots.root.exists() )
+ {
+ snapshots.root.mkdirs();
+ }
+
+ snapshots.server = new Server();
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ snapshots.server.setHandler( contexts );
+
+ SocketConnector connector = new SocketConnector();
+ connector.setPort( 0 ); // 0 means, choose and empty port. (we'll find out which, later)
+
+ snapshots.server.setConnectors( new Connector[] { connector } );
+
+ ContextHandler context = new ContextHandler();
+ context.setContextPath( snapshots.context );
+ context.setAttribute( "dirAllowed", true );
+ context.setAttribute( "maxCacheSize", 0 );
+ context.setResourceBase( snapshots.root.getAbsolutePath() );
+ ServletHandler servlet = new ServletHandler();
+ servlet.addServletWithMapping( DefaultServlet.class.getName(), "/" );
+ context.setHandler( servlet );
+ contexts.addHandler( context );
+
+ snapshots.server.start();
+
+ int port = connector.getLocalPort();
+ snapshots.url = "http://localhost:" + port + snapshots.context;
+ System.out.println( "Snapshot HTTP Server started on " + snapshots.url );
+
+ snapshots.config = createRemoteRepository( snapshots.id, "Testable [" + snapshots.id + "] Remote Repo",
+ snapshots.url );
+
+ return snapshots;
+ }
+
+ private void assertServerSetupCorrectly( RemoteRepoInfo remoteRepo )
+ throws Exception
+ {
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( remoteRepo.url );
+ assertResponseOK( response );
+ }
+
+ private RemoteRepoInfo createCentralRepo()
+ throws Exception
+ {
+ RemoteRepoInfo central = new RemoteRepoInfo();
+ central.id = "central";
+ central.context = "/central";
+ central.root = getTestFile( "target/remote-repos/central/" );
+
+ // Remove exising root contents.
+ if ( central.root.exists() )
+ {
+ FileUtils.deleteDirectory( central.root );
+ }
+
+ // Establish root directory.
+ if ( !central.root.exists() )
+ {
+ central.root.mkdirs();
+ }
+
+ central.server = new Server();
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ central.server.setHandler( contexts );
+
+ SocketConnector connector = new SocketConnector();
+ connector.setPort( 0 ); // 0 means, choose and empty port. (we'll find out which, later)
+
+ central.server.setConnectors( new Connector[] { connector } );
+
+ ContextHandler context = new ContextHandler();
+ context.setContextPath( central.context );
+ context.setResourceBase( central.root.getAbsolutePath() );
+ context.setAttribute( "dirAllowed", true );
+ context.setAttribute( "maxCacheSize", 0 );
+ ServletHandler servlet = new ServletHandler();
+ servlet.addServletWithMapping( DefaultServlet.class.getName(), "/" );
+ context.setHandler( servlet );
+ contexts.addHandler( context );
+
+ central.server.start();
+
+ int port = connector.getLocalPort();
+ central.url = "http://localhost:" + port + central.context;
+ System.out.println( "Central HTTP Server started on " + central.url );
+
+ central.config = createRemoteRepository( central.id, "Testable [" + central.id + "] Remote Repo", central.url );
+
+ return central;
+ }
+
+ private void setupConnector( String repoId, RemoteRepoInfo remoteRepo, String releasesPolicy, String snapshotsPolicy )
+ {
+ ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
+ connector.setSourceRepoId( repoId );
+ connector.setTargetRepoId( remoteRepo.id );
+ connector.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, releasesPolicy );
+ connector.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, snapshotsPolicy );
+ connector.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.IGNORED );
+ connector.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.IGNORED );
+
+ archivaConfiguration.getConfiguration().addProxyConnector( connector );
+ }
+
+ private void shutdownServer( RemoteRepoInfo remoteRepo )
+ {
+ if ( remoteRepo != null )
+ {
+ if ( remoteRepo.server != null )
+ {
+ if ( remoteRepo.server.isRunning() )
+ {
+ try
+ {
+ remoteRepo.server.stop();
+ // int graceful = remoteRepo.server.getGracefulShutdown();
+ // System.out.println( "server set to graceful shutdown: " + graceful );
+ // remoteRepo = null;
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace( System.err );
+ }
+ }
+ }
+ }
+ }
+
+ protected File populateRepo( RemoteRepoInfo remoteRepo, String path, String contents )
+ throws Exception
+ {
+ File destFile = new File( remoteRepo.root, path );
+ destFile.getParentFile().mkdirs();
+ FileUtils.writeStringToFile( destFile, contents, null );
+ return destFile;
+ }
+
+ protected void setupCentralRemoteRepo()
+ throws Exception
+ {
+ remoteCentral = createCentralRepo();
+
+ assertServerSetupCorrectly( remoteCentral );
+ archivaConfiguration.getConfiguration().addRemoteRepository( remoteCentral.config );
+ setupCleanRepo( remoteCentral.root );
+ }
+
+ protected void setupConnector( String repoId, RemoteRepoInfo remoteRepo )
+ {
+ setupConnector( repoId, remoteRepo, ReleasesPolicy.IGNORED, SnapshotsPolicy.IGNORED );
+ }
+
+ protected void setupReleaseConnector( String managedRepoId, RemoteRepoInfo remoteRepo, String releasePolicy )
+ {
+ setupConnector( managedRepoId, remoteRepo, releasePolicy, SnapshotsPolicy.IGNORED );
+ }
+
+ protected void setupSnapshotConnector( String managedRepoId, RemoteRepoInfo remoteRepo, String snapshotsPolicy )
+ {
+ setupConnector( managedRepoId, remoteRepo, ReleasesPolicy.IGNORED, snapshotsPolicy );
+ }
+
+ protected void setupSnapshotsRemoteRepo()
+ throws Exception
+ {
+ remoteSnapshots = createSnapshotsRepo();
+
+ assertServerSetupCorrectly( remoteSnapshots );
+ archivaConfiguration.getConfiguration().addRemoteRepository( remoteSnapshots.config );
+ setupCleanRepo( remoteSnapshots.root );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ shutdownServer( remoteCentral );
+ shutdownServer( remoteSnapshots );
+ super.tearDown();
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,226 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+
+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.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * AbstractRepositoryServletTestCase
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractRepositoryServletTestCase
+ extends PlexusTestCase
+{
+ protected static final String REPOID_INTERNAL = "internal";
+
+ protected ServletUnitClient sc;
+
+ protected ArchivaConfiguration archivaConfiguration;
+
+ protected File repoRootInternal;
+
+ private ServletRunner sr;
+
+ protected void assertFileContents( String expectedContents, File repoRoot, String path )
+ throws IOException
+ {
+ File actualFile = new File( repoRoot, path );
+ assertTrue( "File <" + actualFile.getAbsolutePath() + "> should exist.", actualFile.exists() );
+ assertTrue( "File <" + actualFile.getAbsolutePath() + "> should be a file (not a dir/link/device/etc).",
+ actualFile.isFile() );
+
+ String actualContents = FileUtils.readFileToString( actualFile, null );
+ assertEquals( "File Contents of <" + actualFile.getAbsolutePath() + ">", expectedContents, actualContents );
+ }
+
+ protected void assertRepositoryValid( RepositoryServlet servlet, String repoId )
+ {
+ 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() );
+ }
+
+ protected void assertResponseOK( WebResponse response )
+ {
+ assertNotNull( "Should have recieved a response", response );
+ assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
+ }
+
+ protected void assertResponseNotFound( WebResponse response )
+ {
+ assertNotNull( "Should have recieved a response", response );
+ assertEquals( "Should have been an 404/Not Found response code.", HttpServletResponse.SC_NOT_FOUND, response
+ .getResponseCode() );
+ }
+
+ protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location )
+ {
+ ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setLocation( location.getAbsolutePath() );
+ return repo;
+ }
+
+ protected RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
+ {
+ RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setUrl( url );
+ 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()
+ throws Exception
+ {
+ archivaConfiguration.save( archivaConfiguration.getConfiguration() );
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
+ System.setProperty( "appserver.base", appserverBase );
+
+ File testConf = getTestFile( "src/test/resources/repository-archiva.xml" );
+ File testConfDest = new File( appserverBase, "conf/archiva.xml" );
+ FileUtils.copyFile( testConf, testConfDest );
+
+ archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
+ repoRootInternal = new File( appserverBase, "data/repositories/internal" );
+ Configuration config = archivaConfiguration.getConfiguration();
+
+ config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
+ saveConfiguration();
+
+ sr = new ServletRunner();
+ sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
+ sc = sr.newClient();
+ HttpSession session = sc.getSession( true );
+ ServletContext servletContext = session.getServletContext();
+ servletContext.setAttribute( PlexusConstants.PLEXUS_KEY, getContainer() );
+ }
+
+ @Override
+ protected String getConfigurationName( String subname )
+ throws Exception
+ {
+ return "org/apache/maven/archiva/web/repository/RepositoryServletTest.xml";
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ release( archivaConfiguration );
+
+ if ( sc != null )
+ {
+ sc.clearContents();
+ }
+
+ if ( sr != null )
+ {
+ sr.shutDown();
+ }
+
+ super.tearDown();
+ }
+
+ protected void setupCleanRepo( File repoRootDir )
+ throws IOException
+ {
+ FileUtils.deleteDirectory( repoRootDir );
+ if ( !repoRootDir.exists() )
+ {
+ repoRootDir.mkdirs();
+ }
+ }
+
+ protected void assertManagedFileNotExists( File repoRootInternal, String resourcePath )
+ {
+ File repoFile = new File( repoRootInternal, resourcePath );
+ assertFalse( "Managed Repository File <" + repoFile.getAbsolutePath() + "> should not exist.", repoFile
+ .exists() );
+ }
+
+ protected void setupCleanInternalRepo()
+ throws Exception
+ {
+ setupCleanRepo( repoRootInternal );
+ }
+
+ protected File populateRepo( File repoRootManaged, String path, String contents )
+ throws Exception
+ {
+ File destFile = new File( repoRootManaged, path );
+ destFile.getParentFile().mkdirs();
+ FileUtils.writeStringToFile( destFile, contents, null );
+ return destFile;
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,47 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.webdav.util.MimeTypes;
+
+/**
+ * ArchivaMimeTypesTest
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArchivaMimeTypeLoaderTest
+ extends PlexusTestCase
+{
+ public void testArchivaTypes()
+ throws Exception
+ {
+ lookup( ArchivaMimeTypeLoader.class );
+ MimeTypes mimeTypes = (MimeTypes) lookup( MimeTypes.class );
+ assertNotNull( mimeTypes );
+
+ // Test for some added types.
+ 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" ) );
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/ArchivaMimeTypeLoaderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,134 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.memory.MemoryKeyManager;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.DefaultUserSecurityPolicy;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.DefaultSecuritySystem;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.memory.MemoryUserManager;
+
+/**
+ * BypassSecuritySystem - used to bypass the security system for testing reasons and allow
+ * for every request to respond as success / true.
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component
+ * role="org.codehaus.plexus.redback.system.SecuritySystem"
+ */
+public class BypassSecuritySystem
+ extends DefaultSecuritySystem
+ implements SecuritySystem
+{
+ private KeyManager bypassKeyManager;
+ private UserSecurityPolicy bypassPolicy;
+ private UserManager bypassUserManager;
+
+ public BypassSecuritySystem()
+ {
+ bypassKeyManager = new MemoryKeyManager();
+ bypassPolicy = new DefaultUserSecurityPolicy();
+ bypassUserManager = new MemoryUserManager();
+ }
+
+ public SecuritySession authenticate( AuthenticationDataSource source )
+ throws AuthenticationException, UserNotFoundException, AccountLockedException
+ {
+ AuthenticationResult result = new AuthenticationResult( true, source.getPrincipal(), null );
+ return new DefaultSecuritySession( result );
+ }
+
+ public AuthorizationResult authorize( SecuritySession session, Object permission )
+ throws AuthorizationException
+ {
+ return new AuthorizationResult( true, session.getUser(), null );
+ }
+
+ public AuthorizationResult authorize( SecuritySession session, Object permission, Object resource )
+ throws AuthorizationException
+ {
+ return new AuthorizationResult( true, session.getUser(), null );
+ }
+
+ public String getAuthenticatorId()
+ {
+ return "bypass-authenticator";
+ }
+
+ public String getAuthorizerId()
+ {
+ return "bypass-authorizer";
+ }
+
+ public KeyManager getKeyManager()
+ {
+ return bypassKeyManager;
+ }
+
+ public UserSecurityPolicy getPolicy()
+ {
+ return bypassPolicy;
+ }
+
+ public String getUserManagementId()
+ {
+ return "bypass-managementid";
+ }
+
+ public UserManager getUserManager()
+ {
+ return bypassUserManager;
+ }
+
+ public boolean isAuthenticated( AuthenticationDataSource source )
+ throws AuthenticationException, UserNotFoundException, AccountLockedException
+ {
+ // Always true
+ return true;
+ }
+
+ public boolean isAuthorized( SecuritySession session, Object permission )
+ throws AuthorizationException
+ {
+ // Always true
+ return true;
+ }
+
+ public boolean isAuthorized( SecuritySession session, Object permission, Object resource )
+ throws AuthorizationException
+ {
+ // Always true
+ return true;
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/BypassSecuritySystem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,62 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebLink;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import java.io.File;
+
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * RepositoryServletBrowseTest
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletBrowseTest
+ extends AbstractRepositoryServletTestCase
+{
+ public void testBrowse()
+ throws Exception
+ {
+ new File( repoRootInternal, "org/apache/archiva" ).mkdirs();
+ new File( repoRootInternal, "net/sourceforge" ).mkdirs();
+ new File( repoRootInternal, "commons-lang" ).mkdirs();
+
+ WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
+ WebResponse response = sc.getResponse( request );
+ assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+ // dumpResponse( response );
+
+ WebLink links[] = response.getLinks();
+ String expectedLinks[] = new String[] { "./commons-lang/", "./net/", "./org/" };
+
+ assertEquals( "Links.length", expectedLinks.length, links.length );
+ for ( int i = 0; i < links.length; i++ )
+ {
+ assertEquals( "Link[" + i + "]", expectedLinks[i], links[i].getURLString() );
+ }
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletBrowseTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java?rev=588391&view=auto
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java (added)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java Thu Oct 25 16:39:05 2007
@@ -0,0 +1,62 @@
+package org.apache.maven.archiva.web.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.meterware.httpunit.PutMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * Deploy / Put Test cases for RepositoryServlet.
+ *
+ * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryServletDeployTest
+ extends AbstractRepositoryServletTestCase
+{
+ public void testPutWithMissingParentCollection()
+ throws Exception
+ {
+ setupCleanRepo( repoRootInternal );
+
+ String putUrl = "http://machine.com/repository/internal/path/to/artifact.jar";
+ InputStream is = getClass().getResourceAsStream( "/artifact.jar" );
+ assertNotNull( "artifact.jar inputstream", is );
+
+ WebRequest request = new PutMethodWebRequest( putUrl, is, "application/octet-stream" );
+
+ WebResponse response = sc.getResponse( request );
+ assertResponseCreated( response );
+ assertFileContents( "artifact.jar\n", repoRootInternal, "path/to/artifact.jar" );
+ }
+
+ protected void assertResponseCreated( WebResponse response )
+ {
+ assertNotNull( "Should have recieved a response", response );
+ assertEquals( "Should have been a 201/CREATED response code.", HttpServletResponse.SC_CREATED, response
+ .getResponseCode() );
+ }
+}
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Propchange: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletDeployTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java (from r587923, maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java)
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java?p2=maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java&p1=maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java&r1=587923&r2=588391&rev=588391&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletTest.java (original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java Thu Oct 25 16:39:05 2007
@@ -20,28 +20,12 @@
*/
import com.meterware.httpunit.GetMethodWebRequest;
-import com.meterware.httpunit.PutMethodWebRequest;
-import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletRunner;
-import com.meterware.servletunit.ServletUnitClient;
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.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.webdav.util.MimeTypes;
import java.io.File;
-import java.io.IOException;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
/**
* RepositoryServletTest
@@ -49,350 +33,179 @@
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
* @version $Id$
*/
-public class RepositoryServletTest
- extends PlexusTestCase
+public class RepositoryServletNoProxyTest
+ extends AbstractRepositoryServletTestCase
{
- private ServletUnitClient sc;
-
- private static final String REQUEST_PATH = "http://localhost/repository/internal/path/to/artifact.jar";
-
- private File repositoryLocation;
-
- private ArchivaConfiguration configuration;
-
- private static final String REPOSITORY_ID = "internal";
-
- private static final String NEW_REPOSITORY_ID = "new-id";
-
- private static final String NEW_REPOSITORY_NAME = "New Repository";
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
- System.setProperty( "appserver.base", appserverBase );
-
- File testConf = getTestFile( "src/test/resources/repository-archiva.xml" );
- File testConfDest = new File( appserverBase, "conf/archiva.xml" );
- FileUtils.copyFile( testConf, testConfDest );
-
- configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE );
- repositoryLocation = new File( appserverBase, "data/repositories/internal" );
- Configuration config = configuration.getConfiguration();
-
- config.addManagedRepository( createManagedRepository( "internal", "Internal Test Repo", repositoryLocation ) );
- saveConfiguration();
-
- ServletRunner sr = new ServletRunner();
- sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
- sc = sr.newClient();
- HttpSession session = sc.getSession( true );
- ServletContext servletContext = session.getServletContext();
- servletContext.setAttribute( PlexusConstants.PLEXUS_KEY, getContainer() );
- }
-
- public void testPutWithMissingParentCollection()
- throws Exception
- {
- FileUtils.deleteDirectory( repositoryLocation );
-
- WebRequest request = new PutMethodWebRequest( REQUEST_PATH, getClass().getResourceAsStream( "/artifact.jar" ),
- "application/octet-stream" );
- WebResponse response = sc.getResponse( request );
- assertNotNull( "Should have received response", response );
- assertEquals( "file contents", "artifact.jar\n", FileUtils
- .readFileToString( new File( repositoryLocation, "path/to/artifact.jar" ), null ) );
- }
-
- public void testGetRepository()
- throws Exception
- {
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
-
- assertRepositoryValid( servlet, REPOSITORY_ID );
- }
-
- public void testGetRepositoryAfterDelete()
- throws Exception
- {
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
-
- Configuration c = configuration.getConfiguration();
- c.removeManagedRepository( c.findManagedRepositoryById( REPOSITORY_ID ) );
- saveConfiguration();
-
- ManagedRepositoryConfiguration repository = servlet.getRepository( REPOSITORY_ID );
- assertNull( repository );
- }
-
- public void testGetRepositoryAfterAdd()
- throws Exception
- {
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
-
- Configuration c = configuration.getConfiguration();
- ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
- repo.setId( NEW_REPOSITORY_ID );
- repo.setName( NEW_REPOSITORY_NAME );
- File repoRoot = new File( getBasedir(), "target/test-repository-root" );
- if ( !repoRoot.exists() )
- {
- repoRoot.mkdirs();
- }
- repo.setLocation( repoRoot.getAbsolutePath() );
- c.addManagedRepository( repo );
- saveConfiguration();
-
- ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID );
- assertNotNull( repository );
- assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
-
- // check other is still intact
- assertRepositoryValid( servlet, REPOSITORY_ID );
- }
-
- public void testBrowse()
- throws Exception
- {
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
- new File( repositoryLocation, "org/apache/archiva" ).mkdirs();
- new File( repositoryLocation, "net/sourceforge" ).mkdirs();
- new File( repositoryLocation, "commons-lang" ).mkdirs();
-
- WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" );
- WebResponse response = sc.getResponse( request );
- assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
-
- // dumpResponse( response );
-
- WebLink links[] = response.getLinks();
- String expectedLinks[] = new String[] { "./commons-lang/", "./net/", "./org/", "./path/" };
-
- assertEquals( "Links.length", expectedLinks.length, links.length );
- for ( int i = 0; i < links.length; i++ )
- {
- assertEquals( "Link[" + i + "]", expectedLinks[i], links[i].getURLString() );
- }
- }
-
public void testGetNoProxyChecksumDefaultLayout()
throws Exception
{
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
- File checksumFile = new File( repositoryLocation, commonsLangSha1 );
+ File checksumFile = new File( repoRootInternal, commonsLangSha1 );
checksumFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( checksumFile, "dummy-checksum", null );
-
+
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangSha1 );
WebResponse response = sc.getResponse( request );
- assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+ assertResponseOK( response );
assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
}
-
+
public void testGetNoProxyChecksumLegacyLayout()
throws Exception
{
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
String commonsLangSha1 = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar.sha1";
- File checksumFile = new File( repositoryLocation, commonsLangSha1 );
+ File checksumFile = new File( repoRootInternal, commonsLangSha1 );
checksumFile.getParentFile().mkdirs();
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 );
- assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+ assertResponseOK( response );
assertEquals( "Expected file contents", "dummy-checksum", response.getText() );
}
-
+
public void testGetNoProxyVersionedMetadataDefaultLayout()
throws Exception
{
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
String expectedMetadataContents = "dummy-versioned-metadata";
- File metadataFile = new File( repositoryLocation, commonsLangMetadata );
+ File metadataFile = new File( repoRootInternal, commonsLangMetadata );
metadataFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
WebResponse response = sc.getResponse( request );
- assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+ assertResponseOK( response );
assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
}
-
+
public void testGetNoProxyProjectMetadataDefaultLayout()
throws Exception
{
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
String commonsLangMetadata = "commons-lang/commons-lang/maven-metadata.xml";
String expectedMetadataContents = "dummy-project-metadata";
- File metadataFile = new File( repositoryLocation, commonsLangMetadata );
+ File metadataFile = new File( repoRootInternal, commonsLangMetadata );
metadataFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
WebResponse response = sc.getResponse( request );
- assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+ assertResponseOK( response );
assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
}
-
+
public void testGetNoProxyArtifactDefaultLayout()
throws Exception
{
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
String expectedArtifactContents = "dummy-commons-lang-artifact";
- File artifactFile = new File( repositoryLocation, commonsLangJar );
+ File artifactFile = new File( repoRootInternal, 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() );
+ assertResponseOK( response );
assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
}
-
+
public void testGetNoProxyArtifactLegacyLayout()
throws Exception
{
- RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
- assertNotNull( servlet );
- assertRepositoryValid( servlet, REPOSITORY_ID );
-
String commonsLangJar = "commons-lang/commons-lang/2.1/commons-lang-2.1.jar";
String expectedArtifactContents = "dummy-commons-lang-artifact";
- File artifactFile = new File( repositoryLocation, commonsLangJar );
+ File artifactFile = new File( repoRootInternal, 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.jar" );
+ WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/"
+ + "commons-lang/jars/commons-lang-2.1.jar" );
WebResponse response = sc.getResponse( request );
- assertEquals( "Response OK", HttpServletResponse.SC_OK, response.getResponseCode() );
+ assertResponseOK( response );
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 );
+ File artifactFile = new File( repoRootInternal, 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() );
+ assertResponseOK( response );
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 );
+ File artifactFile = new File( repoRootInternal, 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" );
+ 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() );
+ assertResponseOK( response );
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 );
+ File artifactFile = new File( repoRootInternal, 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() );
+ assertResponseOK( response );
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 );
+ File artifactFile = new File( repoRootInternal, commonsLangJar );
artifactFile.getParentFile().mkdirs();
FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, null );
@@ -400,77 +213,8 @@
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() );
+ assertResponseOK( response );
assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
- }
-
- public void testMimeTypesAvailable()
- throws Exception
- {
- MimeTypes mimeTypes = (MimeTypes) lookup( MimeTypes.class );
- assertNotNull( mimeTypes );
-
- // Test for some added types.
- 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" ) );
- }
-
- public static 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 );
- }
- }
-
- private void assertRepositoryValid( RepositoryServlet servlet, String repoId )
- {
- 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() );
- }
-
- private void saveConfiguration()
- throws Exception
- {
- configuration.save( configuration.getConfiguration() );
- }
-
- private ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location )
- {
- ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
- repo.setId( id );
- repo.setName( name );
- repo.setLocation( location.getAbsolutePath() );
- return repo;
- }
-
- private RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
- {
- RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
- repo.setId( id );
- repo.setName( name );
- repo.setUrl( url );
- return repo;
}
}