]> source.dussan.org Git - archiva.git/commitdiff
fix spring configuration for unit test RepositoryServletSecurityTest
authorOlivier Lamy <olamy@apache.org>
Mon, 13 Jun 2011 14:21:55 +0000 (14:21 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 13 Jun 2011 14:21:55 +0000 (14:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1135112 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java
archiva-modules/archiva-web/archiva-webdav/src/test/resources/WEB-INF/repository-servlet-security-test/web.xml
archiva-modules/archiva-web/archiva-webdav/src/test/resources/spring-context-servlet-security-test.xml [new file with mode: 0644]

index 203b707ac89f9165dd2a689ea57d9b568ae4f602..fed837c75d77c41d9a5986ba5bacded54b611e3d 100644 (file)
@@ -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 )
index 29c7a52825273fcd0afbd4484f3e2459369d77f9..bb60f61bc6eb8c1b1a245087975a09890a6d130a 100644 (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();
 
-        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 );
 
index 7e3c832776dfa477e61a06764d304fc6afeb47e1..f1defb60f753233963b7b5a2ce72f886d203851f 100644 (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>
 
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 (file)
index 0000000..b5e2e43
--- /dev/null
@@ -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