summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-06-13 14:21:55 +0000
committerOlivier Lamy <olamy@apache.org>2011-06-13 14:21:55 +0000
commit1eacae0de2a297765f6b25f6eb80ec45d3da050d (patch)
tree2ea0b3bd5807bd35b952eee85ed43817e8e840a7 /archiva-modules
parentcd73ad4d7825b1929ad66b5cebffdb8cb7a3c185 (diff)
downloadarchiva-1eacae0de2a297765f6b25f6eb80ec45d3da050d.tar.gz
archiva-1eacae0de2a297765f6b25f6eb80ec45d3da050d.zip
fix spring configuration for unit test RepositoryServletSecurityTest
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1135112 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java14
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java17
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml2
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml75
4 files changed, 94 insertions, 14 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java
index 203b707ac..fed837c75 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java
@@ -53,7 +53,6 @@ import java.util.Map;
/**
* RepositoryServlet
- *
*/
public class RepositoryServlet
extends AbstractWebdavServlet
@@ -83,7 +82,7 @@ public class RepositoryServlet
/**
* Service the given request. This method has been overridden and copy/pasted to allow better exception handling and
* to support different realms
- *
+ *
* @param request
* @param response
* @throws ServletException
@@ -96,9 +95,8 @@ public class RepositoryServlet
WebdavRequest webdavRequest = new WebdavRequestImpl( request, getLocatorFactory() );
// DeltaV requires 'Cache-Control' header for all methods except 'VERSION-CONTROL' and 'REPORT'.
int methodCode = DavMethods.getMethodCode( request.getMethod() );
- boolean noCache =
- DavMethods.isDeltaVMethod( webdavRequest )
- && !( DavMethods.DAV_VERSION_CONTROL == methodCode || DavMethods.DAV_REPORT == methodCode );
+ boolean noCache = DavMethods.isDeltaVMethod( webdavRequest ) && !( DavMethods.DAV_VERSION_CONTROL == methodCode
+ || DavMethods.DAV_REPORT == methodCode );
WebdavResponse webdavResponse = new WebdavResponseImpl( response, noCache );
DavResource resource = null;
@@ -182,7 +180,7 @@ public class RepositoryServlet
}
}
- resourceFactory = wac.getBean (DavResourceFactory.class);
+ resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class );
locatorFactory = new ArchivaDavLocatorFactory();
ServletAuthenticator servletAuth = wac.getBean( ServletAuthenticator.class );
@@ -280,14 +278,14 @@ public class RepositoryServlet
public void destroy()
{
configuration.removeListener( this );
-
+
resourceFactory = null;
configuration = null;
locatorFactory = null;
sessionProvider = null;
repositoryMap.clear();
repositoryMap = null;
-
+
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( getServletContext() );
if ( wac instanceof ConfigurableApplicationContext )
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java
index 29c7a5282..bb60f61bc 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java
@@ -52,6 +52,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -80,7 +81,6 @@ public class RepositoryServletSecurityTest
private ServletRunner sr;
- @Inject
protected ArchivaConfiguration archivaConfiguration;
private DavSessionProvider davSessionProvider;
@@ -95,26 +95,33 @@ public class RepositoryServletSecurityTest
private RepositoryServlet servlet;
+ @Inject
+ ApplicationContext applicationContext;
+
@Before
public void setUp()
throws Exception
{
super.setUp();
- String appserverBase = new File( "target/appserver-base" ).getAbsolutePath();
- System.setProperty( "appserver.base", appserverBase );
+ String appserverBase = System.getProperty( "appserver.base", new File( "target/appserver-base" ).getAbsolutePath() );
File testConf = new File( "src/test/resources/repository-archiva.xml" );
File testConfDest = new File( appserverBase, "conf/archiva.xml" );
FileUtils.copyFile( testConf, testConfDest );
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
+
+ archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
Configuration config = archivaConfiguration.getConfiguration();
- config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
+ if (!config.getManagedRepositoriesAsMap().containsKey( REPOID_INTERNAL ))
+ {
+ config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
+ }
saveConfiguration( archivaConfiguration );
- CacheManager.getInstance().removeCache( "url-failures-cache" );
+ CacheManager.getInstance().clearAll();
HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml
index 7e3c83277..f1defb60f 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml
@@ -32,7 +32,7 @@
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/META-INF/spring-context.xml
- classpath*:/spring-context.xml
+ classpath*:/spring-context-servlet-security-test.xml
</param-value>
</context-param>
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml
new file mode 100644
index 000000000..b5e2e43f9
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:property-placeholder system-properties-mode="OVERRIDE"/>
+
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.maven.archiva.webdav,org.apache.archiva.metadata.repository"/>
+
+ <bean name="scheduler" class="org.codehaus.redback.components.scheduler.DefaultScheduler">
+ <property name="properties">
+ <props>
+ <prop key="org.quartz.scheduler.instanceName">scheduler1</prop>
+ <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
+ <prop key="org.quartz.threadPool.threadCount">1</prop>
+ <prop key="org.quartz.threadPool.threadPriority">4</prop>
+ <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean name="servletAuthenticator" class="org.apache.maven.archiva.webdav.MockServletAuthenticator"/>
+
+ <bean name="archivaConfiguration#default" class="org.apache.maven.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#default"/>
+ </bean>
+
+ <alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
+
+ <bean name="registry#default" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="${appserver.base}/conf/archiva.xml" config-forceCreate="true"
+ config-optional="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+ <!--
+ <bean name="davResourceFactory#archiva" class="org.apache.maven.archiva.webdav.UnauthenticatedDavResourceFactory">
+ <property name="servletAuth" ref="servletAuthenticator"/>
+ </bean>
+ -->
+
+</beans> \ No newline at end of file