You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by lg...@apache.org on 2007/10/08 18:17:58 UTC

svn commit: r582863 - in /cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon: AbstractTestCase.java MockWebApplicationContext.java environment/mock/MockContext.java

Author: lgawron
Date: Mon Oct  8 09:17:57 2007
New Revision: 582863

URL: http://svn.apache.org/viewvc?rev=582863&view=rev
Log:
a little hacky way to have cocoon beans configured

Modified:
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/AbstractTestCase.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/MockWebApplicationContext.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/environment/mock/MockContext.java

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/AbstractTestCase.java?rev=582863&r1=582862&r2=582863&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/AbstractTestCase.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/AbstractTestCase.java Mon Oct  8 09:17:57 2007
@@ -31,6 +31,7 @@
 import org.apache.cocoon.processing.ProcessInfoProvider;
 import org.apache.cocoon.processing.impl.MockProcessInfoProvider;
 import org.apache.cocoon.spring.configurator.impl.ServletContextFactoryBean;
+import org.apache.cocoon.spring.configurator.impl.SettingsBeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.BeanDefinitionHolder;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
@@ -89,10 +90,6 @@
         // setup object model
         this.setUpObjectModel();
 
-        // setting up an webapplicationcontext is neccesarry to make spring believe
-        // it runs in a servlet container. we initialize it with our current
-        // bean factory to get consistent bean resolution behaviour
-        this.setUpRootApplicationContext();
 
         // create bean factory
         this.createBeanFactory();
@@ -104,6 +101,10 @@
         this.requestAttributes = new MockRequestAttributes(this.getRequest());
         RequestContextHolder.setRequestAttributes(this.requestAttributes);
 
+        // setting up an webapplicationcontext is neccesarry to make spring believe
+        // it runs in a servlet container. we initialize it with our current
+        // bean factory to get consistent bean resolution behaviour
+        this.setUpRootApplicationContext();
     }
 
     /**
@@ -142,7 +143,7 @@
         final ServletContextFactoryBean scfb = new ServletContextFactoryBean();
         scfb.setServletContext(this.getContext());
 
-        this.staticWebApplicationContext = new MockWebApplicationContext(this.getContext());
+        this.staticWebApplicationContext = new MockWebApplicationContext(this.beanFactory, this.getContext());
         this.getContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
                 staticWebApplicationContext);
     }
@@ -150,12 +151,13 @@
     protected void createBeanFactory() throws Exception {
         ClassPathResource cpr = new ClassPathResource(getClass().getName().replace('.', '/') + ".spring.xml");
         if (cpr.exists()) {
-            this.beanFactory = new XmlBeanFactory(cpr, this.staticWebApplicationContext);
+            this.beanFactory = new XmlBeanFactory(cpr);
         } else {
-            this.beanFactory = new DefaultListableBeanFactory(this.staticWebApplicationContext);
+            this.beanFactory = new DefaultListableBeanFactory();
         }
         this.addSettings();
         this.addProcessingInfoProvider();
+        this.addSettingsBeanFactoryPostProcessor();
     }
 
     protected void initBeanFactory() {
@@ -185,6 +187,17 @@
         def.getPropertyValues().addPropertyValue("servletContext", getContext());
         BeanDefinitionHolder holder = new BeanDefinitionHolder(def, ProcessInfoProvider.ROLE);
         BeanDefinitionReaderUtils.registerBeanDefinition(holder, this.beanFactory);
+    }
+
+    protected void addSettingsBeanFactoryPostProcessor() {
+        SettingsBeanFactoryPostProcessor processor = new SettingsBeanFactoryPostProcessor();
+        processor.setBeanFactory(this.beanFactory);
+        try {
+            processor.init();
+        } catch (Exception e) {
+            throw new RuntimeException("unable to create SettingsBeanFactoryPostProcessor", e);
+        }
+        processor.postProcessBeanFactory(beanFactory);
     }
 
     protected MockRequest createRequest() {

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/MockWebApplicationContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/MockWebApplicationContext.java?rev=582863&r1=582862&r2=582863&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/MockWebApplicationContext.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/MockWebApplicationContext.java Mon Oct  8 09:17:57 2007
@@ -2,11 +2,17 @@
 
 import javax.servlet.ServletContext;
 
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
 import org.springframework.context.support.GenericApplicationContext;
 import org.springframework.web.context.WebApplicationContext;
 
 public class MockWebApplicationContext extends GenericApplicationContext implements WebApplicationContext {
     ServletContext sc;
+
+    public MockWebApplicationContext(DefaultListableBeanFactory parent, ServletContext context) {
+        super(parent);
+        this.sc = context;
+    }
 
     public MockWebApplicationContext(ServletContext context) {
         this.sc = context;

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/environment/mock/MockContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/environment/mock/MockContext.java?rev=582863&r1=582862&r2=582863&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/environment/mock/MockContext.java (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon/environment/mock/MockContext.java Mon Oct  8 09:17:57 2007
@@ -5,9 +5,9 @@
  * 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.
@@ -60,7 +60,7 @@
     }
 
     public String getMimeType(String file) {
-        return (String)mappings.get(file.substring(file.lastIndexOf(".")+1)); 
+        return (String)mappings.get(file.substring(file.lastIndexOf(".")+1));
     }
 
     public void setInitParameter(String name, String value) {
@@ -83,11 +83,14 @@
     }
 
     public void log(Exception arg0, String arg1) {
+        System.err.println("log");
     }
 
     public void log(String arg0, Throwable arg1) {
+        System.err.println("log");
     }
 
     public void log(String arg0) {
+        System.err.println("log");
     }
 }