You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/10/03 15:09:46 UTC

svn commit: r452476 - in /cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon: MockWebApplicationContext.java SitemapComponentTestCase.java

Author: cziegeler
Date: Tue Oct  3 06:09:45 2006
New Revision: 452476

URL: http://svn.apache.org/viewvc?view=rev&rev=452476
Log:
Fix bug 1926: test cases work again. Patch submitted by Lars Trieloff

Added:
    cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java   (with props)
Modified:
    cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java

Added: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java?view=auto&rev=452476
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java (added)
+++ cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java Tue Oct  3 06:09:45 2006
@@ -0,0 +1,20 @@
+package org.apache.cocoon;
+
+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;
+	}
+
+	public ServletContext getServletContext() {
+		return this.sc;
+	}
+}

Propchange: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/MockWebApplicationContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java?view=diff&rev=452476&r1=452475&r2=452476
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java (original)
+++ cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/SitemapComponentTestCase.java Tue Oct  3 06:09:45 2006
@@ -40,9 +40,12 @@
 import org.apache.cocoon.components.flow.FlowHelper;
 import org.apache.cocoon.components.flow.Interpreter;
 import org.apache.cocoon.components.source.SourceResolverAdapter;
+import org.apache.cocoon.core.container.spring.CocoonRequestAttributes;
+import org.apache.cocoon.core.container.spring.Container;
 import org.apache.cocoon.core.container.spring.avalon.ComponentInfo;
 import org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo;
 import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 import org.apache.cocoon.environment.mock.MockContext;
 import org.apache.cocoon.environment.mock.MockEnvironment;
@@ -61,6 +64,8 @@
 import org.apache.excalibur.source.SourceResolver;
 import org.apache.excalibur.xml.sax.SAXParser;
 import org.custommonkey.xmlunit.Diff;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.StaticWebApplicationContext;
 import org.w3c.dom.Document;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -115,6 +120,15 @@
         objectmodel.clear();
 
         request.reset();
+        MockContext cont = this.getContext();
+       
+        //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
+        WebApplicationContext staticWebApplicationContext = new MockWebApplicationContext(this.getBeanFactory(), cont);
+		cont.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, staticWebApplicationContext);
+        Container container = Container.getCurrentContainer(cont, new CocoonRequestAttributes(request));
+        request.setAttribute(Container.CONTAINER_REQUEST_ATTRIBUTE, container, Request.REQUEST_SCOPE);
         objectmodel.put(ObjectModelHelper.REQUEST_OBJECT, request);
 
         response.reset();
@@ -363,6 +377,7 @@
         // enter & leave environment, as a manager is looked up using
         // the processing context stack
         MockEnvironment env = new MockEnvironment();
+        env.setObjectModel(this.objectmodel);
         Processor processor = new MockProcessor(this.getBeanFactory());
         
         EnvironmentHelper.enterProcessor(processor, env);