You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2008/10/30 12:07:50 UTC

svn commit: r709140 - in /tiles/framework/trunk: tiles-compat/src/main/java/org/apache/tiles/compat/preparer/ tiles-compat/src/test/java/org/apache/tiles/compat/preparer/ tiles-core/src/main/java/org/apache/tiles/context/ tiles-jsp/src/main/java/org/ap...

Author: apetrelli
Date: Thu Oct 30 04:07:50 2008
New Revision: 709140

URL: http://svn.apache.org/viewvc?rev=709140&view=rev
Log:
TILES-326
Now every class that implement TilesRequestContext and TilesApplicationContext extend TilesApplicationContextWrapper.

Added:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java   (with props)
Modified:
    tiles/framework/trunk/tiles-compat/src/main/java/org/apache/tiles/compat/preparer/UrlPreparer.java
    tiles/framework/trunk/tiles-compat/src/test/java/org/apache/tiles/compat/preparer/UrlPreparerTest.java
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesRequestContextWrapper.java
    tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesContextFactory.java
    tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
    tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesApplicationContext.java
    tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesContextFactory.java
    tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesRequestContext.java
    tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesApplicationContext.java
    tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesContextFactory.java
    tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java
    tiles/framework/trunk/tiles-servlet/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java

Modified: tiles/framework/trunk/tiles-compat/src/main/java/org/apache/tiles/compat/preparer/UrlPreparer.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-compat/src/main/java/org/apache/tiles/compat/preparer/UrlPreparer.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-compat/src/main/java/org/apache/tiles/compat/preparer/UrlPreparer.java (original)
+++ tiles/framework/trunk/tiles-compat/src/main/java/org/apache/tiles/compat/preparer/UrlPreparer.java Thu Oct 30 04:07:50 2008
@@ -70,7 +70,7 @@
             HttpServletRequest request = servletTilesContext.getRequest();
             HttpServletResponse response = servletTilesContext.getResponse();
             ServletContext servletContext = (ServletContext) servletTilesContext
-                    .getContext();
+                    .getApplicationContext().getContext();
             RequestDispatcher rd = servletContext.getRequestDispatcher(url);
             if (rd == null) {
                 throw new PreparerException(

Modified: tiles/framework/trunk/tiles-compat/src/test/java/org/apache/tiles/compat/preparer/UrlPreparerTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-compat/src/test/java/org/apache/tiles/compat/preparer/UrlPreparerTest.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-compat/src/test/java/org/apache/tiles/compat/preparer/UrlPreparerTest.java (original)
+++ tiles/framework/trunk/tiles-compat/src/test/java/org/apache/tiles/compat/preparer/UrlPreparerTest.java Thu Oct 30 04:07:50 2008
@@ -30,7 +30,9 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tiles.AttributeContext;
+import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
 import org.apache.tiles.servlet.context.ServletTilesRequestContext;
 import org.easymock.EasyMock;
 
@@ -69,8 +71,10 @@
         ServletContext servletContext = EasyMock
                 .createMock(ServletContext.class);
         RequestDispatcher rd = EasyMock.createMock(RequestDispatcher.class);
+        TilesApplicationContext applicationContext = new ServletTilesApplicationContext(
+                servletContext);
         TilesRequestContext requestContext = new ServletTilesRequestContext(
-                servletContext, request, response);
+                applicationContext, request, response);
         AttributeContext attributeContext = EasyMock
                 .createMock(AttributeContext.class);
 

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java?rev=709140&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java Thu Oct 30 04:07:50 2008
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ *
+ * 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.
+ */
+package org.apache.tiles.context;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tiles.TilesApplicationContext;
+
+/**
+ * Delegate for ease of customization.
+ *
+ * @since Tiles 2.1.1
+ * @version $Rev$ $Date$
+ */
+public class TilesApplicationContextWrapper implements TilesApplicationContext {
+
+    /**
+     * The original context.
+     */
+    private TilesApplicationContext context;
+
+    /**
+     * Constructor.
+     *
+     * @param context The original context.
+     */
+    public TilesApplicationContextWrapper(TilesApplicationContext context) {
+        this.context = context;
+    }
+
+    /**
+     * Returns the wrapped application context.
+     *
+     * @return The wrapped application context.
+     */
+    public TilesApplicationContext getWrappedApplicationContext() {
+        return context;
+    }
+
+    /** {@inheritDoc} */
+    public Map<String, Object> getApplicationScope() {
+        return context.getApplicationScope();
+    }
+
+    /** {@inheritDoc} */
+    public Object getContext() {
+        return context.getContext();
+    }
+
+    /** {@inheritDoc} */
+    public Map<String, String> getInitParams() {
+        return context.getInitParams();
+    }
+
+    /** {@inheritDoc} */
+    public URL getResource(String path) throws IOException {
+        return getResource(path);
+    }
+
+    /** {@inheritDoc} */
+    public Set<URL> getResources(String path) throws IOException {
+        return getResources(path);
+    }
+}

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesApplicationContextWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesRequestContextWrapper.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesRequestContextWrapper.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesRequestContextWrapper.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/TilesRequestContextWrapper.java Thu Oct 30 04:07:50 2008
@@ -70,9 +70,9 @@
     }
 
     /** {@inheritDoc} */
-	public TilesApplicationContext getApplicationContext() {
-		return context.getApplicationContext();
-	}
+    public TilesApplicationContext getApplicationContext() {
+        return context.getApplicationContext();
+    }
 
     /** {@inheritDoc} */
     public void dispatch(String path) throws IOException {

Modified: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesContextFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesContextFactory.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesContextFactory.java (original)
+++ tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesContextFactory.java Thu Oct 30 04:07:50 2008
@@ -54,11 +54,8 @@
     /** {@inheritDoc} */
     public TilesRequestContext createRequestContext(TilesApplicationContext context,
                                                     Object... requestItems) {
-        if (requestItems.length == 1) {
-            ServletContext servletContext = getServletContext(context);
-            if (servletContext != null) {
-                return new JspTilesRequestContext(servletContext, (PageContext) requestItems[0]);
-            }
+        if (requestItems.length == 1 && requestItems[0] instanceof PageContext) {
+            return new JspTilesRequestContext(context, (PageContext) requestItems[0]);
         }
 
         return null;

Modified: tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java (original)
+++ tiles/framework/trunk/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspTilesRequestContext.java Thu Oct 30 04:07:50 2008
@@ -20,6 +20,7 @@
  */
 package org.apache.tiles.jsp.context;
 
+import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.servlet.context.ServletTilesRequestContext;
 
@@ -52,9 +53,26 @@
     /**
      * Constructor.
      *
+     * @param applicationContext The Tiles application context.
+     * @param pageContext The page context to use.
+     */
+    public JspTilesRequestContext(TilesApplicationContext applicationContext,
+            PageContext pageContext) {
+        super(applicationContext,
+            (HttpServletRequest) pageContext.getRequest(),
+            (HttpServletResponse) pageContext.getResponse());
+        this.pageContext = pageContext;
+    }
+
+    /**
+     * Constructor.
+     *
      * @param context The servlet context to use.
      * @param pageContext The page context to use.
+     * @deprecated Use
+     * {@link #JspTilesRequestContext(TilesApplicationContext, PageContext)}.
      */
+    @Deprecated
     public JspTilesRequestContext(ServletContext context, PageContext pageContext) {
         super(context,
             (HttpServletRequest) pageContext.getRequest(),

Modified: tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesApplicationContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesApplicationContext.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesApplicationContext.java (original)
+++ tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesApplicationContext.java Thu Oct 30 04:07:50 2008
@@ -151,6 +151,9 @@
      * @param request The request object.
      * @param response The response object.
      * @return The corresponding Tiles request context.
+     * @deprecated Use
+     * {@link org.apache.tiles.context.TilesContextFactory#createRequestContext(TilesApplicationContext, Object...)}
+     * .
      */
     public TilesRequestContext createRequestContext(Object request, Object response) {
         if (request instanceof PortletRequest && response instanceof PortletResponse) {

Modified: tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesContextFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesContextFactory.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesContextFactory.java (original)
+++ tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesContextFactory.java Thu Oct 30 04:07:50 2008
@@ -57,10 +57,9 @@
         if (requestItems.length == 2) {
             PortletContext portletContext = getPortletContext(context);
             if (portletContext != null) {
-                PortletTilesApplicationContext app = (PortletTilesApplicationContext) context;
-                return new PortletTilesRequestContext(app.getPortletContext(),
-                    (PortletRequest) requestItems[0],
-                    (PortletResponse) requestItems[1]);
+                return new PortletTilesRequestContext(context, portletContext,
+                        (PortletRequest) requestItems[0],
+                        (PortletResponse) requestItems[1]);
             }
         }
 

Modified: tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesRequestContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesRequestContext.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesRequestContext.java (original)
+++ tiles/framework/trunk/tiles-portlet/src/main/java/org/apache/tiles/portlet/context/PortletTilesRequestContext.java Thu Oct 30 04:07:50 2008
@@ -34,6 +34,7 @@
 import javax.portlet.RenderResponse;
 
 import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.context.TilesApplicationContextWrapper;
 import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.util.TilesIOException;
 
@@ -42,7 +43,8 @@
  *
  * @version $Rev$ $Date$
  */
-public class PortletTilesRequestContext extends PortletTilesApplicationContext implements TilesRequestContext {
+public class PortletTilesRequestContext extends TilesApplicationContextWrapper
+        implements TilesRequestContext {
 
     /**
      * <p>The lazily instantiated <code>Map</code> of header name-value
@@ -57,6 +59,10 @@
      */
     private Map<String, String[]> headerValues = null;
 
+    /**
+     * The <code>PortletContext</code> for this application.
+     */
+    private PortletContext context = null;
 
     /**
      * <p>The <code>PortletRequest</code> for this request.</p>
@@ -103,13 +109,35 @@
     /**
      * Creates a new instance of PortletTilesRequestContext.
      *
+     * @param applicationContext The Tiles application context.
      * @param context The portlet context to use.
      * @param request The request object to use.
      * @param response The response object to use.
+     * @since 2.1.1
      */
+    public PortletTilesRequestContext(
+            TilesApplicationContext applicationContext, PortletContext context,
+            PortletRequest request, PortletResponse response) {
+        super(applicationContext);
+        this.context = context;
+        initialize(request, response);
+    }
+
+    /**
+     * Creates a new instance of PortletTilesRequestContext.
+     *
+     * @param context The portlet context to use.
+     * @param request The request object to use.
+     * @param response The response object to use.
+     * @deprecated Use
+     * {@link #PortletTilesRequestContext(TilesApplicationContext, PortletContext, PortletRequest, PortletResponse)}
+     * .
+     */
+    @Deprecated
     public PortletTilesRequestContext(PortletContext context, PortletRequest request,
                                       PortletResponse response) {
-        super(context);
+        super(new PortletTilesApplicationContext(context));
+        this.context = context;
         initialize(request, response);
     }
 
@@ -133,7 +161,6 @@
                 isRenderRequest = true;
             }
         }
-
     }
 
     /**
@@ -156,8 +183,6 @@
         context = null;
         request = null;
         response = null;
-        super.release();
-
     }
 
     /**
@@ -230,9 +255,9 @@
     }
 
     /** {@inheritDoc} */
-	public TilesApplicationContext getApplicationContext() {
-		return this;
-	}
+    public TilesApplicationContext getApplicationContext() {
+        return getWrappedApplicationContext();
+    }
 
     /** {@inheritDoc} */
     public void dispatch(String path) throws IOException {

Modified: tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesApplicationContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesApplicationContext.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesApplicationContext.java (original)
+++ tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesApplicationContext.java Thu Oct 30 04:07:50 2008
@@ -155,6 +155,9 @@
      * @param request The request object.
      * @param response The response object.
      * @return The corresponding Tiles request context.
+     * @deprecated Use
+     * {@link org.apache.tiles.context.TilesContextFactory#createRequestContext(TilesApplicationContext, Object...)}
+     * .
      */
     public TilesRequestContext createRequestContext(Object request, Object response) {
         if (request instanceof HttpServletRequest) {

Modified: tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesContextFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesContextFactory.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesContextFactory.java (original)
+++ tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesContextFactory.java Thu Oct 30 04:07:50 2008
@@ -53,14 +53,12 @@
     /** {@inheritDoc} */
     public TilesRequestContext createRequestContext(TilesApplicationContext context,
                                                     Object... requestItems) {
-        if (requestItems.length == 2) {
-            ServletContext servletContext = (ServletContext) context
-                    .getContext();
-            if (servletContext != null) {
-                return new ServletTilesRequestContext(servletContext,
-                    (HttpServletRequest) requestItems[0],
-                    (HttpServletResponse) requestItems[1]);
-            }
+        if (requestItems.length == 2
+                && requestItems[0] instanceof HttpServletRequest
+                && requestItems[1] instanceof HttpServletResponse) {
+            return new ServletTilesRequestContext(context,
+                (HttpServletRequest) requestItems[0],
+                (HttpServletResponse) requestItems[1]);
         }
 
         return null;

Modified: tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java (original)
+++ tiles/framework/trunk/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletTilesRequestContext.java Thu Oct 30 04:07:50 2008
@@ -31,6 +31,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.context.TilesApplicationContextWrapper;
 import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.util.TilesIOException;
 
@@ -39,7 +40,8 @@
  *
  * @version $Rev$ $Date$
  */
-public class ServletTilesRequestContext extends ServletTilesApplicationContext implements TilesRequestContext {
+public class ServletTilesRequestContext extends TilesApplicationContextWrapper
+        implements TilesRequestContext {
 
     /**
      * The request object to use.
@@ -51,7 +53,6 @@
      */
     private HttpServletResponse response;
 
-
     /**
      * <p>The lazily instantiated <code>Map</code> of header name-value
      * combinations (immutable).</p>
@@ -95,14 +96,33 @@
     /**
      * Creates a new instance of ServletTilesRequestContext.
      *
+     * @param applicationContext The application context.
+     * @param request The request object.
+     * @param response The response object.
+     * @since 2.1.1
+     */
+    public ServletTilesRequestContext(
+            TilesApplicationContext applicationContext,
+            HttpServletRequest request, HttpServletResponse response) {
+        super(applicationContext);
+        initialize(request, response);
+    }
+
+    /**
+     * Creates a new instance of ServletTilesRequestContext.
+     *
      * @param servletContext The servlet context.
      * @param request The request object.
      * @param response The response object.
+     * @deprecated Use
+     * {@link #ServletTilesRequestContext(TilesApplicationContext, HttpServletRequest, HttpServletResponse)}
+     * .
      */
+    @Deprecated
     public ServletTilesRequestContext(ServletContext servletContext,
                                       HttpServletRequest request,
                                       HttpServletResponse response) {
-        super(servletContext);
+        super(new ServletTilesApplicationContext(servletContext));
         initialize(request, response);
     }
 
@@ -173,9 +193,9 @@
     }
 
     /** {@inheritDoc} */
-	public TilesApplicationContext getApplicationContext() {
-		return this;
-	}
+    public TilesApplicationContext getApplicationContext() {
+        return getWrappedApplicationContext();
+    }
 
     /** {@inheritDoc} */
     public void dispatch(String path) throws IOException {
@@ -277,8 +297,6 @@
         // Release references to Servlet API objects
         request = null;
         response = null;
-        super.release();
-
     }
 
 

Modified: tiles/framework/trunk/tiles-servlet/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-servlet/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java?rev=709140&r1=709139&r2=709140&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-servlet/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java (original)
+++ tiles/framework/trunk/tiles-servlet/src/test/java/org/apache/tiles/servlet/context/ServletTilesRequestContextTest.java Thu Oct 30 04:07:50 2008
@@ -22,9 +22,9 @@
 package org.apache.tiles.servlet.context;
 
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
 
-import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -34,6 +34,7 @@
 import org.apache.shale.test.mock.MockServletContext;
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.context.TilesRequestContext;
+import org.easymock.EasyMock;
 
 import junit.framework.TestCase;
 
@@ -57,13 +58,26 @@
      */
     private MockServletContext servletContext;
 
+    /**
+     * The Tiles application context.
+     */
+    private TilesApplicationContext applicationContext;
+
     /** {@inheritDoc} */
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         servletContext = new MockServletContext();
-        servletContext
-                .addInitParameter("initParameter1", "initParameterValue1");
+        applicationContext = EasyMock.createMock(TilesApplicationContext.class);
+        Map<String, Object> applicationScope = new HashMap<String, Object>();
+        applicationScope.put("applicationAttribute1", "applicationValue1");
+        applicationScope.put("applicationAttribute2", "applicationValue2");
+        EasyMock.expect(applicationContext.getApplicationScope()).andReturn(
+                applicationScope);
+        Map<String, String> initParams = new HashMap<String, String>();
+        initParams.put("initParameter1", "initParameterValue1");
+        EasyMock.expect(applicationContext.getInitParams()).andReturn(
+                initParams);
         MockHttpSession session = new MockHttpSession(servletContext);
         MockHttpServletRequest request = new MockHttpServletRequest(session);
         MockHttpServletResponse response = new MockHttpServletResponse();
@@ -71,7 +85,7 @@
         request.addParameter("myParam", "value1");
         request.addParameter("myParam", "value2");
 
-        context = new ServletTilesRequestContext(servletContext, request,
+        context = new ServletTilesRequestContext(applicationContext, request,
                 response);
 
         Map<String, Object> requestScope = context.getRequestScope();
@@ -81,11 +95,7 @@
         Map<String, Object> sessionScope = context.getSessionScope();
         sessionScope.put("sessionAttribute1", "sessionValue1");
         sessionScope.put("sessionAttribute2", "sessionValue2");
-
-        Map<String, Object> applicationScope = ((TilesApplicationContext) context)
-                .getApplicationScope();
-        applicationScope.put("applicationAttribute1", "applicationValue1");
-        applicationScope.put("applicationAttribute2", "applicationValue2");
+        EasyMock.replay(applicationContext);
     }
 
     /**
@@ -163,10 +173,10 @@
      * Tests {@link ServletTilesRequestContext#getApplicationContext()}.
      */
     public void testGetApplicationContext() {
-    	assertTrue("The objects are not the same", context == context
-				.getApplicationContext());
+        assertTrue("The objects are not the same",
+                applicationContext == context.getApplicationContext());
     }
-    
+
     /**
      * Tests getting application scope attributes.
      */
@@ -201,7 +211,7 @@
         MockHttpServletRequest request = new MockHttpServletRequest();
         MockHttpServletResponse response = new CommitSupportMockHttpServletResponse();
         MockServletTilesRequestContext context = new MockServletTilesRequestContext(
-                servletContext, request, response);
+                applicationContext, request, response);
         context.dispatch(TEST_PATH);
         assertEquals("Forward has not been called", 1, context.getForwardCount());
         assertEquals("Include has been called", 0, context.getIncludeCount());
@@ -275,13 +285,14 @@
         /**
          * Constructor.
          *
-         * @param servletContext The servlet context.
+         * @param applicationContext The Tiles application context.
          * @param request The request.
          * @param response The response.
          */
-        public MockServletTilesRequestContext(ServletContext servletContext,
+        public MockServletTilesRequestContext(
+                TilesApplicationContext applicationContext,
                 HttpServletRequest request, HttpServletResponse response) {
-            super(servletContext, request, response);
+            super(applicationContext, request, response);
         }
 
         /** {@inheritDoc} */