cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r582816 - in /cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/test/java/org/apache/cocoon: AbstractTestCase.java MockWebApplicationContext.java
Date Mon, 08 Oct 2007 13:18:41 GMT
Author: lgawron
Date: Mon Oct  8 06:18:41 2007
New Revision: 582816

URL: http://svn.apache.org/viewvc?rev=582816&view=rev
Log:
WebApplicationContext is the parent of cocoon's bean factory, not the other way around.

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

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=582816&r1=582815&r2=582816&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 06:18:41 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.
@@ -42,8 +42,7 @@
 import org.springframework.web.context.request.RequestContextHolder;
 
 /**
- * This class sets up all necessary environment information to implement
- * own test cases.
+ * This class sets up all necessary environment information to implement own test cases.
  *
  * @version $Id$
  * @since 2.2
@@ -59,6 +58,7 @@
 
     /** The bean factory. */
     private DefaultListableBeanFactory beanFactory;
+    private MockWebApplicationContext staticWebApplicationContext;
 
     public final MockRequest getRequest() {
         return this.request;
@@ -89,8 +89,14 @@
         // 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();
+
         // initialize bean factory
         this.initBeanFactory();
 
@@ -98,23 +104,19 @@
         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();
     }
 
     /**
      * @see junit.framework.TestCase#tearDown()
      */
     protected void tearDown() throws Exception {
-        if ( this.requestAttributes != null ) {
+        if (this.requestAttributes != null) {
             this.requestAttributes.requestCompleted();
             this.requestAttributes = null;
         }
         RequestContextHolder.resetRequestAttributes();
 
-        if( this.beanFactory != null ) {
+        if (this.beanFactory != null) {
             this.beanFactory.destroySingletons();
             this.beanFactory = null;
         }
@@ -132,7 +134,7 @@
 
         this.objectmodel.put(ObjectModelHelper.REQUEST_OBJECT, this.getRequest());
         this.objectmodel.put(ObjectModelHelper.RESPONSE_OBJECT, this.getResponse());
-        this.objectmodel.put(ObjectModelHelper.CONTEXT_OBJECT, this.getContext());      
 
+        this.objectmodel.put(ObjectModelHelper.CONTEXT_OBJECT, this.getContext());
     }
 
     protected void setUpRootApplicationContext() {
@@ -140,23 +142,24 @@
         final ServletContextFactoryBean scfb = new ServletContextFactoryBean();
         scfb.setServletContext(this.getContext());
 
-        WebApplicationContext staticWebApplicationContext = new MockWebApplicationContext(this.getBeanFactory(),
this.getContext());
-        this.getContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
staticWebApplicationContext);
+        this.staticWebApplicationContext = new MockWebApplicationContext(this.getContext());
+        this.getContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
+                staticWebApplicationContext);
     }
 
     protected void createBeanFactory() throws Exception {
         ClassPathResource cpr = new ClassPathResource(getClass().getName().replace('.', '/')
+ ".spring.xml");
-        if(cpr.exists()) {
-            this.beanFactory = new XmlBeanFactory(cpr);                
+        if (cpr.exists()) {
+            this.beanFactory = new XmlBeanFactory(cpr, this.staticWebApplicationContext);
         } else {
-            this.beanFactory = new DefaultListableBeanFactory();
+            this.beanFactory = new DefaultListableBeanFactory(this.staticWebApplicationContext);
         }
         this.addSettings();
         this.addProcessingInfoProvider();
     }
 
     protected void initBeanFactory() {
-        this.beanFactory.preInstantiateSingletons();        
+        this.beanFactory.preInstantiateSingletons();
     }
 
     protected void addSettings() {
@@ -170,7 +173,7 @@
         BeanDefinitionHolder holder = new BeanDefinitionHolder(def, Settings.ROLE);
         BeanDefinitionReaderUtils.registerBeanDefinition(holder, this.beanFactory);
     }
-    
+
     protected void addProcessingInfoProvider() {
         RootBeanDefinition def = new RootBeanDefinition();
         def.setBeanClass(MockProcessInfoProvider.class);

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=582816&r1=582815&r2=582816&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 06:18:41 2007
@@ -2,19 +2,17 @@
 
 import javax.servlet.ServletContext;
 
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-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(ConfigurableListableBeanFactory factory, ServletContext
context) {
-		super((DefaultListableBeanFactory) factory);
-		this.sc = context;
-	}
+    ServletContext sc;
 
-	public ServletContext getServletContext() {
-		return this.sc;
-	}
+    public MockWebApplicationContext(ServletContext context) {
+        this.sc = context;
+    }
+
+    public ServletContext getServletContext() {
+        return this.sc;
+    }
 }



Mime
View raw message