fix spring configuration for unit test RepositoryServletSecurityTest

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1135112 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-13 14:21:55 +00:00
parent cd73ad4d78
commit 1eacae0de2
4 changed files with 94 additions and 14 deletions

View File

@ -53,7 +53,6 @@ import java.util.Map;
/**
* RepositoryServlet
*
*/
public class RepositoryServlet
extends AbstractWebdavServlet
@ -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 );

View File

@ -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();
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 );

View File

@ -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>

View File

@ -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>