You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/07/01 02:15:54 UTC

svn commit: r959476 [1/2] - /myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/

Author: lu4242
Date: Thu Jul  1 00:15:53 2010
New Revision: 959476

URL: http://svn.apache.org/viewvc?rev=959476&view=rev
Log:
MYFACESTEST-17 Update MockExternalContext so it delegate to mock request and response objects and add new methods present on facelets mocks

Added:
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockRequestDispatcher.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletInputStream.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_NullEnumeration.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterValuesMap.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_SessionMap.java
Modified:
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java
    myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletContext.java

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java?rev=959476&r1=959475&r2=959476&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockExternalContext.java Thu Jul  1 00:15:53 2010
@@ -21,9 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Collections;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
@@ -31,7 +29,10 @@ import java.util.Set;
 
 import javax.faces.FacesException;
 import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -43,12 +44,11 @@ import javax.servlet.http.HttpSession;
  * $Id$
  */
 
-public class MockExternalContext extends ExternalContext {
-
+public class MockExternalContext extends ExternalContext
+{
 
     // ------------------------------------------------------------ Constructors
 
-
     /**
      * <p>Construct a wrapper instance.</p>
      *
@@ -58,74 +58,98 @@ public class MockExternalContext extends
      */
     public MockExternalContext(ServletContext context,
                                HttpServletRequest request,
-                               HttpServletResponse response) {
+                               HttpServletResponse response)
+    {
 
         this.context = context;
         this.request = request;
         this.response = response;
-        applicationMap = new MockApplicationMap(context);
-        requestMap = new MockRequestMap(request);
-
+        this.applicationMap = null;
+        this.initParameterMap = null;
+        this.requestMap = null;
+        this.requestCookieMap = null;
+        this.requestHeaderMap = null;
+        this.requestParameterMap = null;
+        this.requestParameterValuesMap = null;
+        this.requestHeaderValuesMap = null;
+        this.sessionMap = null;
     }
 
-
     // ----------------------------------------------------- Mock Object Methods
 
-
     // ------------------------------------------------------ Instance Variables
 
-
-    private Map applicationMap = null;
-    protected ServletContext context = null;
-    protected HttpServletRequest request = null;
-    private Map requestMap = null;
-    protected HttpServletResponse response = null;
-    private Map sessionMap = null;
-    private Map requestCookieMap = new HashMap();
-    private Map requestHeaderMap = new HashMap();
-    private Map requestParameterMap = new HashMap();
-
+    protected ServletContext context;
+    protected HttpServletRequest request;
+    protected HttpServletResponse response;
+    private Map applicationMap;
+    private Map initParameterMap;
+    private Map requestMap;
+    private Map requestCookieMap;
+    private Map requestHeaderMap;
+    private Map requestParameterMap;
+    private Map requestParameterValuesMap;
+    private Map requestHeaderValuesMap;
+    private Map sessionMap;
 
     // ------------------------------------------------- setters for the mock object
 
-
     /**
      * <p>Add a new cookie for this request.</p>
      *
      * @param cookie The new cookie
      */
-    public void addRequestCookieMap(Cookie cookie) {
-        requestParameterMap.put(cookie.getName(), cookie);
+    public void addRequestCookieMap(Cookie cookie)
+    {
+        Map map = getRequestCookieMap();
+        if (request instanceof MockHttpServletRequest &&
+            map instanceof _CookieMap)
+        {
+            ((MockHttpServletRequest)request).addCookie(cookie);
+        }
+        else
+        {
+            map.put(cookie.getName(), cookie);
+        }
     }
 
-
     /**
      * <p>Set the request cookie map for this request.</p>
      *
      * @param map The new request cookie map
      */
-    public void setRequestCookieMap(Map map) {
-        requestParameterMap = map;
+    public void setRequestCookieMap(Map map)
+    {
+        requestCookieMap = map;
     }
 
-
     /**
      * <p>Add the specified request parameter for this request.</p>
      *
      * @param key Parameter name
      * @param value Parameter value
      */
-    public void addRequestParameterMap(String key, String value) {
-        requestParameterMap.put(key, value);
+    public void addRequestParameterMap(String key, String value)
+    {
+        Map map = getRequestParameterMap();
+        if (request instanceof MockHttpServletRequest &&
+            map instanceof _RequestParameterMap)
+        {
+            ((MockHttpServletRequest)request).addParameter(key, value);
+        }
+        else
+        {
+            map.put(key, value);
+        }
     }
 
-
     /**
      * <p>Set the request parameter map for this request.</p>
      *
      * @param map The new request parameter map
      */
-    public void setRequestParameterMap(Map map) {
+    public void setRequestParameterMap(Map map)
+    {
         requestParameterMap = map;
     }
 
@@ -135,316 +159,320 @@ public class MockExternalContext extends
      * @param key Parameter name
      * @param value Parameter value
      */
-    public void addRequestHeader(String key, String value) {
-        requestHeaderMap.put(key, value);
+    public void addRequestHeader(String key, String value)
+    {
+        Map map = getRequestHeaderMap();
+        if (request instanceof MockHttpServletRequest &&
+            map instanceof _RequestHeaderMap)
+        {
+            ((MockHttpServletRequest)request).addHeader(key, value);
+        }
+        else
+        {
+            map.put(key, value);
+        }
     }
 
-
     /**
      * <p>Set the request header map for this request.</p>
      *
      * @param map The new request header map
      */
-    public void setRequestHeaderMap(Map map) {
+    public void setRequestHeaderMap(Map map)
+    {
         requestHeaderMap = map;
     }
 
-
-
-
-
     // ------------------------------------------------- ExternalContext Methods
 
-
     /** {@inheritDoc} */
-    public void dispatch(String requestURI)
-      throws IOException, FacesException {
-
-        throw new UnsupportedOperationException();
-
+    public void dispatch(String requestURI) throws IOException, FacesException
+    {
+        RequestDispatcher requestDispatcher = request
+                .getRequestDispatcher(requestURI);
+        // If there is no dispatcher, send NOT_FOUND
+        if (requestDispatcher == null)
+        {
+            ((HttpServletResponse) response)
+                    .sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+        try
+        {
+            requestDispatcher.forward(request, response);
+        }
+        catch (ServletException e)
+        {
+            if (e.getMessage() != null)
+            {
+                throw new FacesException(e.getMessage(), e);
+            }
+            throw new FacesException(e);
+        }
     }
 
-
     /** {@inheritDoc} */
-    public String encodeActionURL(String sb) {
-
+    public String encodeActionURL(String sb)
+    {
         return sb;
-
     }
 
-
     /** {@inheritDoc} */
-    public String encodeNamespace(String aValue) {
-
+    public String encodeNamespace(String aValue)
+    {
         return aValue;
-
     }
 
-
     /** {@inheritDoc} */
-    public String encodeResourceURL(String sb) {
-
+    public String encodeResourceURL(String sb)
+    {
         return sb;
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getApplicationMap() {
-
-        return this.applicationMap;
-
+    public Map getApplicationMap()
+    {
+        if (applicationMap == null)
+        {
+            applicationMap = new _ApplicationMap(context);
+        }
+        return applicationMap;
     }
 
-
     /** {@inheritDoc} */
-    public String getAuthType() {
-
+    public String getAuthType()
+    {
         return request.getAuthType();
-
     }
 
-
     /** {@inheritDoc} */
-    public Object getContext() {
-
+    public Object getContext()
+    {
         return context;
-
     }
 
-
     /** {@inheritDoc} */
-    public String getInitParameter(String name) {
-
+    public String getInitParameter(String name)
+    {
         return context.getInitParameter(name);
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getInitParameterMap() {
-
-        Map parameterMap = new HashMap();
-        Enumeration names = context.getInitParameterNames();
-        while (names.hasMoreElements()) {
-            String name = (String) names.nextElement();
-            parameterMap.put(name, context.getInitParameter(name));
+    public Map getInitParameterMap()
+    {
+        if (initParameterMap == null)
+        {
+            initParameterMap = new _InitParameterMap(context);
         }
-        return Collections.unmodifiableMap(parameterMap);
-
+        return initParameterMap;
     }
 
-
     /** {@inheritDoc} */
-    public String getRemoteUser() {
-
+    public String getRemoteUser()
+    {
         return request.getRemoteUser();
-
     }
 
-
     /** {@inheritDoc} */
-    public Object getRequest() {
-
+    public Object getRequest()
+    {
         return request;
-
     }
 
-
     /** {@inheritDoc} */
-    public String getRequestContextPath() {
-
+    public String getRequestContextPath()
+    {
         return request.getContextPath();
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getRequestCookieMap() {
-
+    public Map getRequestCookieMap()
+    {
+        if (requestCookieMap == null)
+        {
+            requestCookieMap = new _CookieMap(request);
+        }
         return requestCookieMap;
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getRequestHeaderMap() {
-
+    public Map getRequestHeaderMap()
+    {
+        if (requestHeaderMap == null)
+        {
+            requestHeaderMap = new _RequestHeaderMap(request);
+        }
         return requestHeaderMap;
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getRequestHeaderValuesMap() {
-
-        throw new UnsupportedOperationException();
-
+    public Map getRequestHeaderValuesMap()
+    {
+        if (requestHeaderValuesMap == null)
+        {
+            requestHeaderValuesMap = new _RequestHeaderValuesMap(request);
+        }
+        return requestHeaderValuesMap;
     }
 
-
     /** {@inheritDoc} */
-    public Locale getRequestLocale() {
-
+    public Locale getRequestLocale()
+    {
         return request.getLocale();
-
     }
 
-
     /** {@inheritDoc} */
-    public Iterator getRequestLocales() {
-
+    public Iterator getRequestLocales()
+    {
         return new LocalesIterator(request.getLocales());
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getRequestMap() {
-
+    public Map getRequestMap()
+    {
+        if (requestMap == null)
+        {
+            requestMap = new _RequestMap(request);
+        }
         return requestMap;
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getRequestParameterMap() {
-
+    public Map getRequestParameterMap()
+    {
+        if (requestParameterMap == null)
+        {
+            requestParameterMap = new _RequestParameterMap(request);
+        }
         return requestParameterMap;
-
     }
 
-
     /** {@inheritDoc} */
-    public Iterator getRequestParameterNames() {
-
-        throw new UnsupportedOperationException();
-
+    public Iterator getRequestParameterNames()
+    {
+        final Enumeration enumer = request.getParameterNames();
+        Iterator it = new Iterator()
+        {
+            public boolean hasNext()
+            {
+                return enumer.hasMoreElements();
+            }
+
+            public Object next()
+            {
+                return enumer.nextElement();
+            }
+
+            public void remove()
+            {
+                throw new UnsupportedOperationException(this.getClass()
+                        .getName()
+                        + " UnsupportedOperationException");
+            }
+        };
+        return it;
     }
 
-
     /** {@inheritDoc} */
-    public Map getRequestParameterValuesMap() {
-
-        throw new UnsupportedOperationException();
-
+    public Map getRequestParameterValuesMap()
+    {
+        if (requestParameterValuesMap == null)
+        {
+            requestParameterValuesMap = new _RequestParameterValuesMap(request);
+        }
+        return requestParameterValuesMap;
     }
 
-
     /** {@inheritDoc} */
-    public String getRequestPathInfo() {
-
+    public String getRequestPathInfo()
+    {
         return request.getPathInfo();
-
     }
 
-
     /** {@inheritDoc} */
-    public String getRequestServletPath() {
-
+    public String getRequestServletPath()
+    {
         return request.getServletPath();
-
     }
 
-
     /** {@inheritDoc} */
-    public URL getResource(String path) throws MalformedURLException {
-
+    public URL getResource(String path) throws MalformedURLException
+    {
         return context.getResource(path);
-
     }
 
-
     /** {@inheritDoc} */
-    public InputStream getResourceAsStream(String path) {
-
+    public InputStream getResourceAsStream(String path)
+    {
         return context.getResourceAsStream(path);
-
     }
 
-
     /** {@inheritDoc} */
-    public Set getResourcePaths(String path) {
-
+    public Set getResourcePaths(String path)
+    {
         return context.getResourcePaths(path);
-
     }
 
-
     /** {@inheritDoc} */
-    public Object getResponse() {
-
+    public Object getResponse()
+    {
         return response;
-
     }
 
-
     /** {@inheritDoc} */
-    public Object getSession(boolean create) {
-
+    public Object getSession(boolean create)
+    {
         return request.getSession(create);
-
     }
 
-
     /** {@inheritDoc} */
-    public Map getSessionMap() {
-
-        if (sessionMap == null) {
+    public Map getSessionMap()
+    {
+        if (sessionMap == null)
+        {
             HttpSession session = request.getSession(true);
             sessionMap = new MockSessionMap(session);
         }
         return sessionMap;
-
     }
 
-
     /** {@inheritDoc} */
-    public java.security.Principal getUserPrincipal() {
-
+    public java.security.Principal getUserPrincipal()
+    {
         return request.getUserPrincipal();
-
     }
 
-
     /** {@inheritDoc} */
-    public boolean isUserInRole(String role) {
-
+    public boolean isUserInRole(String role)
+    {
         return request.isUserInRole(role);
-
     }
 
-
     /** {@inheritDoc} */
-    public void log(String message) {
-
+    public void log(String message)
+    {
         context.log(message);
-
     }
 
-
     /** {@inheritDoc} */
-    public void log(String message, Throwable throwable) {
-
+    public void log(String message, Throwable throwable)
+    {
         context.log(message, throwable);
-
     }
 
-
     /** {@inheritDoc} */
-    public void redirect(String requestURI)
-      throws IOException {
-
-        throw new UnsupportedOperationException();
-
+    public void redirect(String requestURI) throws IOException
+    {
+        response.sendRedirect(requestURI);
+        FacesContext.getCurrentInstance().responseComplete();
     }
 
-
     /**
      * <p>Iterator implementation that wraps an enumeration
      * of Locales for the current request.</p>
      */
-    private class LocalesIterator implements Iterator {
+    private class LocalesIterator implements Iterator
+    {
 
         /**
          * <p>Construct an iterator wrapping the specified
@@ -452,7 +480,8 @@ public class MockExternalContext extends
          *
          * @param locales Locales enumeration to wrap
          */
-        public LocalesIterator(Enumeration locales) {
+        public LocalesIterator(Enumeration locales)
+        {
             this.locales = locales;
         }
 
@@ -462,15 +491,23 @@ public class MockExternalContext extends
         private Enumeration locales;
 
         /** {@inheritDoc} */
-        public boolean hasNext() { return locales.hasMoreElements(); }
+        public boolean hasNext()
+        {
+            return locales.hasMoreElements();
+        }
 
         /** {@inheritDoc} */
-        public Object next() { return locales.nextElement(); }
+        public Object next()
+        {
+            return locales.nextElement();
+        }
 
         /** {@inheritDoc} */
-        public void remove() { throw new UnsupportedOperationException(); }
+        public void remove()
+        {
+            throw new UnsupportedOperationException();
+        }
 
     }
 
-
 }

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java?rev=959476&r1=959475&r2=959476&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletRequest.java Thu Jul  1 00:15:53 2010
@@ -18,10 +18,15 @@
 package org.apache.myfaces.test.mock;
 
 import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
 import java.security.Principal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -163,7 +168,19 @@ public class MockHttpServletRequest impl
         parameters.put(name, results);
 
     }
-
+    
+    public void addCookie(Cookie c)
+    {
+        for (int i = 0; i < cookies.size(); i++)
+        {
+            if ( ((Cookie)cookies.get(i)).getName().equals(c.getName()) )
+            {
+                cookies.set(i, c);
+                return;
+            }
+        }
+        cookies.add(c);
+    }
 
     /**
      * <p>Return the <code>ServletContext</code> associated with
@@ -259,7 +276,9 @@ public class MockHttpServletRequest impl
     private String servletPath = null;
     private HttpSession session = null;
     private String characterEncoding = null;
-
+    private ServletInputStream inputStream = null;
+    private List cookies = new ArrayList();
+    private Vector locales = null; 
 
     // ---------------------------------------------- HttpServletRequest Methods
 
@@ -283,8 +302,12 @@ public class MockHttpServletRequest impl
     /** {@inheritDoc} */
     public Cookie[] getCookies() {
 
-        throw new UnsupportedOperationException();
-
+        Cookie[] array = new Cookie[cookies.size()];
+        for (int i = 0; i < cookies.size(); i++)
+        {
+            array[i] = (Cookie) cookies.get(i);
+        }
+        return array;
     }
 
 
@@ -474,7 +497,7 @@ public class MockHttpServletRequest impl
     public HttpSession getSession(boolean create) {
 
         if (create && (session == null)) {
-            throw new UnsupportedOperationException();
+            this.session = new MockHttpSession(this.servletContext);
         }
         return session;
 
@@ -573,13 +596,16 @@ public class MockHttpServletRequest impl
 
 
     /** {@inheritDoc} */
-    public ServletInputStream getInputStream() {
-
-        throw new UnsupportedOperationException();
-
+    public ServletInputStream getInputStream()
+    {
+        return this.inputStream;
+    }
+    
+    public void setInputStream(MockServletInputStream stream)
+    {
+        this.inputStream = stream;
     }
 
-
     /** {@inheritDoc} */
     public Locale getLocale() {
 
@@ -589,10 +615,14 @@ public class MockHttpServletRequest impl
 
 
     /** {@inheritDoc} */
-    public Enumeration getLocales() {
-
-        throw new UnsupportedOperationException();
-
+    public Enumeration getLocales()
+    {
+        if (this.locales == null)
+        {
+            locales = new Vector(Arrays.asList(Locale
+                    .getAvailableLocales()));
+        }
+        return this.locales.elements();
     }
 
 
@@ -666,10 +696,22 @@ public class MockHttpServletRequest impl
 
 
     /** {@inheritDoc} */
-    public BufferedReader getReader() {
-
-        throw new UnsupportedOperationException();
-
+    public BufferedReader getReader()
+    {
+        if (this.inputStream != null) {
+            try{
+                Reader sourceReader = (this.characterEncoding != null) ? new InputStreamReader(
+                        this.inputStream, this.characterEncoding)
+                        : new InputStreamReader(this.inputStream);
+                return new BufferedReader(sourceReader);
+            }
+            catch(UnsupportedEncodingException e)
+            {
+                throw new RuntimeException(e);
+            }
+        } else {
+            return null;
+        }
     }
 
 
@@ -709,10 +751,9 @@ public class MockHttpServletRequest impl
 
 
     /** {@inheritDoc} */
-    public RequestDispatcher getRequestDispatcher(String path) {
-
-        throw new UnsupportedOperationException();
-
+    public RequestDispatcher getRequestDispatcher(String path)
+    {
+        return servletContext.getRequestDispatcher(path);
     }
 
 

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java?rev=959476&r1=959475&r2=959476&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockHttpServletResponse.java Thu Jul  1 00:15:53 2010
@@ -23,10 +23,13 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.TimeZone;
 
 import javax.servlet.ServletOutputStream;
@@ -71,8 +74,12 @@ public class MockHttpServletResponse imp
         }
         return null;
     }
-
-
+    
+    public Cookie getCookie(String name)
+    {
+        return (Cookie)cookies.get(name);
+    }
+    
     /**
      * <p>Return the text message for the HTTP status that was set.</p>
      */
@@ -127,16 +134,20 @@ public class MockHttpServletResponse imp
     private int status = HttpServletResponse.SC_OK;
     private ServletOutputStream stream = null;
     private PrintWriter writer = null;
-
+    
+    private boolean committed = false;
+    private long contentLength = 0;
+    private int bufferSize = 0;
+    private Locale locale = Locale.getDefault();
+    private Map cookies = new HashMap(4);
 
     // -------------------------------------------- HttpServletResponse Methods
 
 
     /** {@inheritDoc} */
-    public void addCookie(Cookie cookie) {
-
-        throw new UnsupportedOperationException();
-
+    public void addCookie(Cookie cookie)
+    {
+        cookies.put(cookie.getName(), cookie);
     }
 
 
@@ -205,28 +216,38 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public void sendError(int status) {
-
+    public void sendError(int status)
+    {
+        if (this.committed)
+        {
+            throw new IllegalStateException("Response is already committed");
+        }
         this.status = status;
-
+        this.committed = true;
     }
 
 
     /** {@inheritDoc} */
-    public void sendError(int status, String message) {
-
+    public void sendError(int status, String message)
+    {
+        if (this.committed)
+        {
+            throw new IllegalStateException("Response is already committed");
+        }
         this.status = status;
         this.message = message;
-
+        this.committed = true;
     }
 
 
     /** {@inheritDoc} */
     public void sendRedirect(String location) {
-
+        if (this.committed) {
+            throw new IllegalStateException("Response is already committed");
+        }
         this.status = HttpServletResponse.SC_MOVED_TEMPORARILY;
         this.message = location;
-
+        this.committed = true;
     }
 
 
@@ -258,18 +279,16 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public void setStatus(int status) {
-
-        throw new UnsupportedOperationException();
-
+    public void setStatus(int status)
+    {
+        this.status = status;
     }
 
 
     /** {@inheritDoc} */
     public void setStatus(int status, String message) {
-
-        throw new UnsupportedOperationException();
-
+        this.status = status;
+        this.message = message;
     }
 
 
@@ -277,18 +296,15 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public void flushBuffer() {
-
-        throw new UnsupportedOperationException();
-
+    public void flushBuffer()
+    {
+    
     }
 
 
     /** {@inheritDoc} */
     public int getBufferSize() {
-
-        throw new UnsupportedOperationException();
-
+        return bufferSize;
     }
 
 
@@ -309,10 +325,9 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public Locale getLocale() {
-
-        throw new UnsupportedOperationException();
-
+    public Locale getLocale()
+    {
+        return this.locale;
     }
 
 
@@ -345,34 +360,28 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public boolean isCommitted() {
-
-        throw new UnsupportedOperationException();
-
+    public boolean isCommitted()
+    {
+        return committed;
     }
 
 
     /** {@inheritDoc} */
-    public void reset() {
-
-        throw new UnsupportedOperationException();
-
+    public void reset()
+    {
     }
 
 
     /** {@inheritDoc} */
-    public void resetBuffer() {
-
-        throw new UnsupportedOperationException();
-
+    public void resetBuffer()
+    {
     }
 
 
     /** {@inheritDoc} */
-    public void setBufferSize(int size) {
-
-        throw new UnsupportedOperationException();
-
+    public void setBufferSize(int size)
+    {
+        this.bufferSize = size;
     }
 
 
@@ -385,10 +394,9 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public void setContentLength(int length) {
-
-        throw new UnsupportedOperationException();
-
+    public void setContentLength(int length)
+    {
+        this.contentLength = length;
     }
 
 
@@ -401,10 +409,9 @@ public class MockHttpServletResponse imp
 
 
     /** {@inheritDoc} */
-    public void setLocale(Locale locale) {
-
-        throw new UnsupportedOperationException();
-
+    public void setLocale(Locale locale)
+    {
+        this.locale = locale;
     }
 
 

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockRequestDispatcher.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockRequestDispatcher.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockRequestDispatcher.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockRequestDispatcher.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,59 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * 
+ * @author Jacob Hookom
+ * @version $Id: MockRequestDispatcher.java 804043 2009-08-13 22:08:44Z lu4242 $
+ */
+public class MockRequestDispatcher implements RequestDispatcher
+{
+
+    protected final URL url;
+
+    public MockRequestDispatcher(URL url)
+    {
+        this.url = url;
+    }
+
+    public void forward(ServletRequest request, ServletResponse response)
+            throws ServletException, IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void include(ServletRequest request, ServletResponse response)
+            throws ServletException, IOException
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Modified: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletContext.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletContext.java?rev=959476&r1=959475&r2=959476&view=diff
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletContext.java (original)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletContext.java Thu Jul  1 00:15:53 2010
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -37,7 +38,6 @@ import javax.servlet.ServletContextAttri
 import javax.servlet.ServletContextAttributeListener;
 import javax.servlet.ServletException;
 
-
 /**
  * <p>Mock implementation of <code>ServletContext</code>.</p>
  *
@@ -51,24 +51,11 @@ import javax.servlet.ServletException;
  * $Id$
  */
 
-public class MockServletContext implements ServletContext {
-
-
+public class MockServletContext implements ServletContext
+{
 
     // ----------------------------------------------------- Mock Object Methods
 
-
-    /**
-     * <p>Add a new listener instance that should be notified about
-     * attribute changes.</p>
-     *
-     * @param listener Listener to be added
-     */
-    public void addAttributeListener(ServletContextAttributeListener listener) {
-        attributeListeners.add(listener);
-    }
-
-
     /**
      * <p>Add a context initialization parameter to the set of
      * parameters recognized by this instance.</p>
@@ -76,11 +63,11 @@ public class MockServletContext implemen
      * @param name Parameter name
      * @param value Parameter value
      */
-    public void addInitParameter(String name, String value) {
+    public void addInitParameter(String name, String value)
+    {
         parameters.put(name, value);
     }
 
-
     /**
      * <p>Add a new MIME type mapping to the set of mappings
      * recognized by this instance.</p>
@@ -88,11 +75,11 @@ public class MockServletContext implemen
      * @param extension Extension to check for (without the period)
      * @param contentType Corresponding content type
      */
-    public void addMimeType(String extension, String contentType) {
+    public void addMimeType(String extension, String contentType)
+    {
         mimeTypes.put(extension, contentType);
     }
 
-
     /**
      * <p>Set the document root for <code>getRealPath()</code>
      * resolution.  This parameter <strong>MUST</strong> represent
@@ -100,84 +87,90 @@ public class MockServletContext implemen
      *
      * @param documentRoot The new base directory
      */
-    public void setDocumentRoot(File documentRoot) {
+    public void setDocumentRoot(File documentRoot)
+    {
         this.documentRoot = documentRoot;
     }
 
+    public void setDocumentRoot(URI base)
+    {
+        File f = new File(base);
+        if (!f.exists())
+        {
+            throw new IllegalArgumentException("File: " + base.getPath()
+                    + " doesn't exist");
+        }
+        this.documentRoot = f;
+    }
 
-    // ------------------------------------------------------ Instance Variables
+    /**
+     * <p>Add a new listener instance that should be notified about
+     * attribute changes.</p>
+     *
+     * @param listener Listener to be added
+     */
+    public void addAttributeListener(ServletContextAttributeListener listener)
+    {
+        attributeListeners.add(listener);
+    }
 
+    // ------------------------------------------------------ Instance Variables
 
-    private List attributeListeners = new ArrayList();
     private Hashtable attributes = new Hashtable();
     private File documentRoot = null;
     private Hashtable mimeTypes = new Hashtable();
     private Hashtable parameters = new Hashtable();
-
+    private List attributeListeners = new ArrayList();
 
     // -------------------------------------------------- ServletContext Methods
 
-
     /** {@inheritDoc} */
-    public Object getAttribute(String name) {
+    public Object getAttribute(String name)
+    {
 
         return attributes.get(name);
 
     }
 
-
     /** {@inheritDoc} */
-    public Enumeration getAttributeNames() {
+    public Enumeration getAttributeNames()
+    {
 
         return attributes.keys();
 
     }
 
-
-    /** {@inheritDoc} */
-    public ServletContext getContext(String uripath) {
-
-        throw new UnsupportedOperationException();
-
-    }
-
     /** {@inheritDoc} */
-    public String getContextPath() {
-
-        throw new UnsupportedOperationException();
-
-    }
-
-
-    /** {@inheritDoc} */
-    public String getInitParameter(String name) {
+    public String getInitParameter(String name)
+    {
 
         return (String) parameters.get(name);
 
     }
 
-
     /** {@inheritDoc} */
-    public Enumeration getInitParameterNames() {
+    public Enumeration getInitParameterNames()
+    {
 
         return parameters.keys();
 
     }
 
-
     /** {@inheritDoc} */
-    public int getMajorVersion() {
+    public int getMajorVersion()
+    {
 
         return 2;
 
     }
 
-
     /** {@inheritDoc} */
-    public String getMimeType(String path) {
+    public String getMimeType(String path)
+    {
 
         int period = path.lastIndexOf('.');
-        if (period < 0) {
+        if (period < 0)
+        {
             return null;
         }
         String extension = path.substring(period + 1);
@@ -185,121 +178,128 @@ public class MockServletContext implemen
 
     }
 
-
     /** {@inheritDoc} */
-    public int getMinorVersion() {
+    public int getMinorVersion()
+    {
 
         return 4;
 
     }
 
-
     /** {@inheritDoc} */
-    public RequestDispatcher getNamedDispatcher(String name) {
-
-        throw new UnsupportedOperationException();
+    public String getRealPath(String path)
+    {
 
-    }
-
-
-    /** {@inheritDoc} */
-    public String getRealPath(String path) {
-
-        if (documentRoot != null) {
-            if (!path.startsWith("/")) {
+        if (documentRoot != null)
+        {
+            if (!path.startsWith("/"))
+            {
                 throw new IllegalArgumentException("The specified path ('"
                         + path + "') does not start with a '/' character");
             }
             File resolved = new File(documentRoot, path.substring(1));
-            try {
+            try
+            {
                 return resolved.getCanonicalPath();
-            } catch (IOException e) {
+            }
+            catch (IOException e)
+            {
                 return resolved.getAbsolutePath();
             }
-        } else {
+        }
+        else
+        {
             return null;
         }
 
     }
 
-
-    /** {@inheritDoc} */
-    public RequestDispatcher getRequestDispatcher(String path) {
-
-        throw new UnsupportedOperationException();
-
-    }
-
-
     /** {@inheritDoc} */
-    public URL getResource(String path) throws MalformedURLException {
+    public URL getResource(String path) throws MalformedURLException
+    {
 
-        if (documentRoot != null) {
-            if (!path.startsWith("/")) {
-                throw new MalformedURLException("The specified path ('"
-                        + path + "') does not start with a '/' character");
+        if (documentRoot != null)
+        {
+            if (!path.startsWith("/"))
+            {
+                throw new MalformedURLException("The specified path ('" + path
+                        + "') does not start with a '/' character");
             }
             File resolved = new File(documentRoot, path.substring(1));
-            if (resolved.exists()) {
+            if (resolved.exists())
+            {
                 return resolved.toURL();
-            } else {
+            }
+            else
+            {
                 return null;
             }
-        } else {
+        }
+        else
+        {
             return null;
         }
 
     }
 
-
     /** {@inheritDoc} */
-    public InputStream getResourceAsStream(String path) {
-
-        try {
+    public InputStream getResourceAsStream(String path)
+    {
+        try
+        {
             URL url = getResource(path);
-            if (url != null) {
+            if (url != null)
+            {
                 return url.openStream();
             }
-        } catch (Exception e) {
+        }
+        catch (Exception e)
+        {
             ;
         }
         return null;
-
     }
 
-
     /** {@inheritDoc} */
-    public Set getResourcePaths(String path) {
+    public Set getResourcePaths(String path)
+    {
 
-        if (documentRoot == null) {
+        if (documentRoot == null)
+        {
             return null;
         }
 
         // Enforce the leading slash restriction
-        if (!path.startsWith("/")) {
-            throw new IllegalArgumentException("The specified path ('"
-                    + path + "') does not start with a '/' character");
+        if (!path.startsWith("/"))
+        {
+            throw new IllegalArgumentException("The specified path ('" + path
+                    + "') does not start with a '/' character");
         }
 
         // Locate the File node for this path's directory (if it exists)
         File node = new File(documentRoot, path.substring(1));
-        if (!node.exists()) {
+        if (!node.exists())
+        {
             return null;
         }
-        if (!node.isDirectory()) {
+        if (!node.isDirectory())
+        {
             return null;
         }
 
         // Construct a Set containing the paths to the contents of this directory
         Set set = new HashSet();
         String[] files = node.list();
-        if (files == null) {
+        if (files == null)
+        {
             return null;
         }
-        for (int i = 0; i < files.length; i++) {
+        for (int i = 0; i < files.length; i++)
+        {
             String subfile = path + files[i];
             File subnode = new File(node, files[i]);
-            if (subnode.isDirectory()) {
+            if (subnode.isDirectory())
+            {
                 subfile += "/";
             }
             set.add(subfile);
@@ -307,111 +307,153 @@ public class MockServletContext implemen
 
         // Return the completed set
         return set;
-
     }
 
-
     /** {@inheritDoc} */
-    public Servlet getServlet(String name) throws ServletException {
-
-        throw new UnsupportedOperationException();
-
+    public void log(String message)
+    {
+        System.out.println(message);
     }
 
-
     /** {@inheritDoc} */
-    public String getServletContextName() {
-
-        return "MockServletContext";
-
+    public void log(Exception exception, String message)
+    {
+        System.out.println(message);
+        exception.printStackTrace();
     }
 
-
     /** {@inheritDoc} */
-    public String getServerInfo() {
-
-        return "MockServletContext";
-
+    public void log(String message, Throwable exception)
+    {
+        System.out.println(message);
+        exception.printStackTrace();
     }
 
+    /** {@inheritDoc} */
+    public void removeAttribute(String name)
+    {
+        if (attributes.containsKey(name))
+        {
+            Object value = attributes.remove(name);
+            fireAttributeRemoved(name, value);
+        }
+    }
 
     /** {@inheritDoc} */
-    public Enumeration getServlets() {
+    public void setAttribute(String name, Object value)
+    {
+        if (name == null)
+        {
+            throw new IllegalArgumentException("Attribute name cannot be null");
+        }
+        if (value == null)
+        {
+            removeAttribute(name);
+            return;
+        }
+        if (attributes.containsKey(name))
+        {
+            Object oldValue = attributes.get(name);
+            attributes.put(name, value);
+            fireAttributeReplaced(name, oldValue);
+        }
+        else
+        {
+            attributes.put(name, value);
+            fireAttributeAdded(name, value);
+        }
+    }
 
+    /** {@inheritDoc} */
+    public ServletContext getContext(String uripath)
+    {
         throw new UnsupportedOperationException();
-
     }
 
-
     /** {@inheritDoc} */
-    public Enumeration getServletNames() {
-
+    public String getContextPath()
+    {
         throw new UnsupportedOperationException();
-
     }
 
-
     /** {@inheritDoc} */
-    public void log(String message) {
-
-        System.out.println(message);
-
+    public Servlet getServlet(String name) throws ServletException
+    {
+        throw new UnsupportedOperationException();
     }
 
-
     /** {@inheritDoc} */
-    public void log(Exception exception, String message) {
-
-        System.out.println(message);
-        exception.printStackTrace();
-
+    public String getServletContextName()
+    {
+        return "MockServletContext";
     }
 
-
     /** {@inheritDoc} */
-    public void log(String message, Throwable exception) {
-
-        System.out.println(message);
-        exception.printStackTrace();
-
+    public String getServerInfo()
+    {
+        return "MockServletContext";
     }
 
-
     /** {@inheritDoc} */
-    public void removeAttribute(String name) {
-
-        if (attributes.containsKey(name)) {
-            Object value = attributes.remove(name);
-            fireAttributeRemoved(name, value);
-        }
+    public Enumeration getServlets()
+    {
+        throw new UnsupportedOperationException();
+    }
 
+    /** {@inheritDoc} */
+    public Enumeration getServletNames()
+    {
+        throw new UnsupportedOperationException();
     }
 
+    /** {@inheritDoc} */
+    public RequestDispatcher getNamedDispatcher(String name)
+    {
+        throw new UnsupportedOperationException();
+    }
 
     /** {@inheritDoc} */
-    public void setAttribute(String name, Object value) {
+    public RequestDispatcher getRequestDispatcher(String path)
+    {
+        URI uri = this.resolve(path);
+        if (uri != null)
+        {
+            File f = new File(uri);
+            if (f.exists())
+            {
+                try
+                {
+                    return new MockRequestDispatcher(uri.toURL());
+                }
+                catch (MalformedURLException e)
+                {
+                    this.log(e.getMessage());
+                    return null;
+                }
+            }
 
-        if (name == null) {
-            throw new IllegalArgumentException("Attribute name cannot be null");
-        }
-        if (value == null) {
-            removeAttribute(name);
-            return;
         }
-        if (attributes.containsKey(name)) {
-            Object oldValue = attributes.get(name);
-            attributes.put(name, value);
-            fireAttributeReplaced(name, oldValue);
-        } else {
-            attributes.put(name, value);
-            fireAttributeAdded(name, value);
-        }
-
+        return null;
     }
 
-
     // --------------------------------------------------------- Private Methods
 
+    private final URI resolve(String path)
+    {
+        if (path == null)
+        {
+            throw new NullPointerException("Path cannot be null");
+        }
+        if (path.charAt(0) == '/')
+        {
+            if (path.length() > 1)
+            {
+                return documentRoot.toURI().resolve(path.substring(1));
+            }
+            return documentRoot.toURI();
+        }
+        return null;
+    }
 
     /**
      * <p>Fire an attribute added event to interested listeners.</p>
@@ -419,61 +461,66 @@ public class MockServletContext implemen
      * @param key Attribute whose value has been added
      * @param value The new value
      */
-    private void fireAttributeAdded(String key, Object value) {
-        if (attributeListeners.size() < 1) {
+    void fireAttributeAdded(String key, Object value)
+    {
+        if (attributeListeners.size() < 1)
+        {
             return;
         }
-        ServletContextAttributeEvent event =
-                new ServletContextAttributeEvent(this, key, value);
+        ServletContextAttributeEvent event = new ServletContextAttributeEvent(
+                this, key, value);
         Iterator listeners = attributeListeners.iterator();
-        while (listeners.hasNext()) {
-            ServletContextAttributeListener listener =
-                    (ServletContextAttributeListener) listeners.next();
+        while (listeners.hasNext())
+        {
+            ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners
+                    .next();
             listener.attributeAdded(event);
         }
     }
 
-
     /**
      * <p>Fire an attribute removed event to interested listeners.</p>
      *
      * @param key Attribute whose value has been removed
      * @param value The value that was removed
      */
-    private void fireAttributeRemoved(String key, Object value) {
-        if (attributeListeners.size() < 1) {
+    void fireAttributeRemoved(String key, Object value)
+    {
+        if (attributeListeners.size() < 1)
+        {
             return;
         }
-        ServletContextAttributeEvent event =
-                new ServletContextAttributeEvent(this, key, value);
+        ServletContextAttributeEvent event = new ServletContextAttributeEvent(
+                this, key, value);
         Iterator listeners = attributeListeners.iterator();
-        while (listeners.hasNext()) {
-            ServletContextAttributeListener listener =
-                    (ServletContextAttributeListener) listeners.next();
+        while (listeners.hasNext())
+        {
+            ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners
+                    .next();
             listener.attributeRemoved(event);
         }
     }
 
-
     /**
      * <p>Fire an attribute replaced event to interested listeners.</p>
      *
      * @param key Attribute whose value has been replaced
      * @param value The original value
      */
-    private void fireAttributeReplaced(String key, Object value) {
-        if (attributeListeners.size() < 1) {
+    void fireAttributeReplaced(String key, Object value)
+    {
+        if (attributeListeners.size() < 1)
+        {
             return;
         }
-        ServletContextAttributeEvent event =
-                new ServletContextAttributeEvent(this, key, value);
+        ServletContextAttributeEvent event = new ServletContextAttributeEvent(
+                this, key, value);
         Iterator listeners = attributeListeners.iterator();
-        while (listeners.hasNext()) {
-            ServletContextAttributeListener listener =
-                    (ServletContextAttributeListener) listeners.next();
+        while (listeners.hasNext())
+        {
+            ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners
+                    .next();
             listener.attributeReplaced(event);
         }
     }
-
-
 }

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletInputStream.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletInputStream.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletInputStream.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/MockServletInputStream.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.ServletInputStream;
+
+/**
+ * 
+ * @author Jacob Hookom
+ * @version $Id: MockServletInputStream.java 804043 2009-08-13 22:08:44Z lu4242 $
+ */
+public class MockServletInputStream extends ServletInputStream
+{
+
+    private final InputStream source;
+
+    public MockServletInputStream()
+    {
+        this.source = new ByteArrayInputStream(new byte[0]);
+    }
+
+    public MockServletInputStream(InputStream source)
+    {
+        this.source = source;
+    }
+
+    public int read() throws IOException
+    {
+        return this.source.read();
+    }
+
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_AbstractAttributeMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,351 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+
+/**
+ * Helper Map implementation for use with different Attribute Maps.
+ *
+ * @author Anton Koinov (latest modification by $Author: grantsmith $)
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+abstract class _AbstractAttributeMap
+    extends AbstractMap
+{
+    private Set              _keySet;
+    private Collection       _values;
+    private Set              _entrySet;
+
+    public void clear()
+    {
+        List names = new ArrayList();
+        for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
+        {
+            names.add(e.nextElement());
+        }
+
+        for (Iterator it = names.iterator(); it.hasNext();)
+        {
+            removeAttribute((String) it.next());
+        }
+    }
+
+    public boolean containsKey(Object key)
+    {
+        return getAttribute(key.toString()) != null;
+    }
+
+    public boolean containsValue(Object findValue)
+    {
+        if (findValue == null)
+        {
+            return false;
+        }
+
+        for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
+        {
+            Object value = getAttribute((String) e.nextElement());
+            if (findValue.equals(value))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public Set entrySet()
+    {
+        return (_entrySet != null) ? _entrySet : (_entrySet = new EntrySet());
+    }
+
+    public Object get(Object key)
+    {
+        return getAttribute(key.toString());
+    }
+
+    public boolean isEmpty()
+    {
+        return !getAttributeNames().hasMoreElements();
+    }
+
+    public Set keySet()
+    {
+        return (_keySet != null) ? _keySet : (_keySet = new KeySet());
+    }
+
+    public Object put(Object key, Object value)
+    {
+        String key_ = key.toString();
+        Object retval = getAttribute(key_);
+        setAttribute(key_, value);
+        return retval;
+    }
+
+    public void putAll(Map t)
+    {
+        for (Iterator it = t.entrySet().iterator(); it.hasNext();)
+        {
+            Entry entry = (Entry) it.next();
+            setAttribute(entry.getKey().toString(), entry.getValue());
+        }
+    }
+
+    public Object remove(Object key)
+    {
+        String key_ = key.toString();
+        Object retval = getAttribute(key_);
+        removeAttribute(key_);
+        return retval;
+    }
+
+    public int size()
+    {
+        int size = 0;
+        for (Enumeration e = getAttributeNames(); e.hasMoreElements();)
+        {
+            size++;
+            e.nextElement();
+        }
+        return size;
+    }
+
+    public Collection values()
+    {
+        return (_values != null) ? _values : (_values = new Values());
+    }
+
+
+    abstract protected Object getAttribute(String key);
+
+    abstract protected void setAttribute(String key, Object value);
+
+    abstract protected void removeAttribute(String key);
+
+    abstract protected Enumeration getAttributeNames();
+
+
+    private class KeySet extends AbstractSet
+    {
+        public Iterator iterator()
+        {
+            return new KeyIterator();
+        }
+
+        public boolean isEmpty()
+        {
+            return _AbstractAttributeMap.this.isEmpty();
+        }
+
+        public int size()
+        {
+            return _AbstractAttributeMap.this.size();
+        }
+
+        public boolean contains(Object o)
+        {
+            return _AbstractAttributeMap.this.containsKey(o);
+        }
+
+        public boolean remove(Object o)
+        {
+            return _AbstractAttributeMap.this.remove(o) != null;
+        }
+
+        public void clear()
+        {
+            _AbstractAttributeMap.this.clear();
+        }
+    }
+
+    private class KeyIterator
+        implements Iterator
+    {
+        protected final Enumeration _e = getAttributeNames();
+        protected Object            _currentKey;
+
+        public void remove()
+        {
+            // remove() may cause ConcurrentModificationException.
+            // We could throw an exception here, but not throwing an exception
+            //   allows one call to remove() to succeed
+            if (_currentKey == null)
+            {
+                throw new NoSuchElementException(
+                    "You must call next() at least once");
+            }
+            _AbstractAttributeMap.this.remove(_currentKey);
+        }
+
+        public boolean hasNext()
+        {
+            return _e.hasMoreElements();
+        }
+
+        public Object next()
+        {
+            return _currentKey = _e.nextElement();
+        }
+    }
+
+    private class Values extends KeySet
+    {
+        public Iterator iterator()
+        {
+            return new ValuesIterator();
+        }
+
+        public boolean contains(Object o)
+        {
+            return _AbstractAttributeMap.this.containsValue(o);
+        }
+
+        public boolean remove(Object o)
+        {
+            if (o == null)
+            {
+                return false;
+            }
+
+            for (Iterator it = iterator(); it.hasNext();)
+            {
+                if (o.equals(it.next()))
+                {
+                    it.remove();
+                    return true;
+                }
+            }
+
+            return false;
+        }
+    }
+
+    private class ValuesIterator extends KeyIterator
+    {
+        public Object next()
+        {
+            super.next();
+            return _AbstractAttributeMap.this.get(_currentKey);
+        }
+    }
+
+    private class EntrySet extends KeySet
+    {
+        public Iterator iterator() {
+            return new EntryIterator();
+        }
+
+        public boolean contains(Object o) {
+            if (!(o instanceof Entry))
+            {
+                return false;
+            }
+
+            Entry entry = (Entry) o;
+            Object key = entry.getKey();
+            Object value = entry.getValue();
+            if (key == null || value == null)
+            {
+                return false;
+            }
+
+            return value.equals(_AbstractAttributeMap.this.get(key));
+        }
+
+        public boolean remove(Object o) {
+            if (!(o instanceof Entry))
+            {
+                return false;
+            }
+
+            Entry entry = (Entry) o;
+            Object key = entry.getKey();
+            Object value = entry.getValue();
+            if (key == null || value == null
+                || !value.equals(_AbstractAttributeMap.this.get(key)))
+            {
+                return false;
+            }
+
+            return _AbstractAttributeMap.this.remove(((Entry) o).getKey()) != null;
+        }
+    }
+
+    /**
+     * Not very efficient since it generates a new instance of <code>Entry</code>
+     * for each element and still internaly uses the <code>KeyIterator</code>.
+     * It is more efficient to use the <code>KeyIterator</code> directly.
+     */
+    private class EntryIterator extends KeyIterator
+    {
+        public Object next()
+        {
+            super.next();
+            // Must create new Entry every time--value of the entry must stay
+            // linked to the same attribute name
+            return new EntrySetEntry(_currentKey);
+        }
+    }
+
+    private class EntrySetEntry implements Entry
+    {
+        private final Object _currentKey;
+
+        public EntrySetEntry(Object currentKey)
+        {
+            _currentKey = currentKey;
+        }
+
+        public Object getKey()
+        {
+            return _currentKey;
+        }
+
+        public Object getValue()
+        {
+            return _AbstractAttributeMap.this.get(_currentKey);
+        }
+
+        public Object setValue(Object value)
+        {
+            return _AbstractAttributeMap.this.put(_currentKey, value);
+        }
+
+        public int hashCode() {
+            return _currentKey == null ? 0 : _currentKey.hashCode();
+        }
+
+        public boolean equals(Object obj) {
+            if (!(obj instanceof EntrySetEntry))
+                return false;
+            return _currentKey != null && _currentKey.equals(obj);
+        }
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_ApplicationMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,87 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+
+
+/**
+ * ServletContext attributes as a Map.
+ *
+ * @author Anton Koinov (latest modification by $Author: grantsmith $)
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+class _ApplicationMap extends _AbstractAttributeMap
+{
+    final ServletContext _servletContext;
+
+    _ApplicationMap(ServletContext servletContext)
+    {
+        _servletContext = servletContext;
+    }
+
+    protected Object getAttribute(String key)
+    {
+        return _servletContext.getAttribute(key);
+    }
+
+    protected void setAttribute(String key, Object value)
+    {
+        _servletContext.setAttribute(key, value);
+    }
+
+    protected void removeAttribute(String key)
+    {
+        _servletContext.removeAttribute(key);
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        return _servletContext.getAttributeNames();
+    }
+
+    public void putAll(Map t)
+    {
+        for (Iterator it = t.entrySet().iterator(); it.hasNext();)
+        {
+            Map.Entry entry = (Map.Entry) it.next();
+            _servletContext.setAttribute((String)entry.getKey(), entry.getValue());
+        }
+    }
+
+    public void clear()
+    {
+        List names = new ArrayList();
+        for (Enumeration e = _servletContext.getAttributeNames(); e.hasMoreElements();)
+        {
+            String name = (String) e.nextElement();
+            names.add(name);
+        }
+        for (int i = 0; i < names.size(); i++)
+        {
+            _servletContext.removeAttribute((String) names.get(i));
+        }
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_CookieMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,173 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * HttpServletRequest Cookies as Map.
+ *
+ * @author Dimitry D'hondt
+ * @author Anton Koinov
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+class _CookieMap extends _AbstractAttributeMap
+{
+    private static final Cookie[] EMPTY_ARRAY = new Cookie[0];
+
+    final HttpServletRequest _httpServletRequest;
+
+    _CookieMap(HttpServletRequest httpServletRequest)
+    {
+        _httpServletRequest = httpServletRequest;
+    }
+
+    public void clear()
+    {
+        throw new UnsupportedOperationException(
+            "Cannot clear HttpRequest Cookies");
+    }
+
+    public boolean containsKey(Object key)
+    {
+        Cookie[] cookies = _httpServletRequest.getCookies();
+        if (cookies == null) return false;
+        for (int i = 0, len = cookies.length; i < len; i++)
+        {
+            if (cookies[i].getName().equals(key))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean containsValue(Object findValue)
+    {
+        if (findValue == null)
+        {
+            return false;
+        }
+
+        Cookie[] cookies = _httpServletRequest.getCookies();
+        if (cookies == null) return false;
+        for (int i = 0, len = cookies.length; i < len; i++)
+        {
+            if (findValue.equals(cookies[i]))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    public boolean isEmpty()
+    {
+        Cookie[] cookies = _httpServletRequest.getCookies();
+        return cookies == null || cookies.length == 0;
+    }
+
+    public int size()
+    {
+        Cookie[] cookies = _httpServletRequest.getCookies();
+        return cookies == null ? 0 : cookies.length;
+    }
+
+    public void putAll(Map t)
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    protected Object getAttribute(String key)
+    {
+        Cookie[] cookies = _httpServletRequest.getCookies();
+        if (cookies == null) return null;
+        for (int i = 0, len = cookies.length; i < len; i++)
+        {
+            if (cookies[i].getName().equals(key))
+            {
+                return cookies[i];
+            }
+        }
+
+        return null;
+    }
+
+    protected void setAttribute(String key, Object value)
+    {
+        if (_httpServletRequest instanceof MockHttpServletRequest)
+        {
+            ((MockHttpServletRequest) _httpServletRequest).addCookie((Cookie) value);
+        }
+        else
+        {
+            throw new UnsupportedOperationException(
+                "Cannot set HttpRequest Cookies");
+        }
+    }
+
+    protected void removeAttribute(String key)
+    {
+        throw new UnsupportedOperationException(
+            "Cannot remove HttpRequest Cookies");
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        Cookie[] cookies = _httpServletRequest.getCookies();
+        if (cookies == null)
+        {
+            return new CookieNameEnumeration(EMPTY_ARRAY);
+        }
+        else
+        {
+            return new CookieNameEnumeration(cookies);
+        }
+    }
+
+    private static class CookieNameEnumeration implements Enumeration
+    {
+        private final Cookie[] _cookies;
+        private final int _length;
+        private int _index;
+
+        public CookieNameEnumeration(Cookie[] cookies)
+        {
+            _cookies = cookies;
+            _length = cookies.length;
+        }
+
+        public boolean hasMoreElements()
+        {
+            return _index < _length;
+        }
+
+        public Object nextElement()
+        {
+            return _cookies[_index++].getName();
+        }
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_InitParameterMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.servlet.ServletContext;
+
+
+/**
+ * ServletContext init parameters as Map.
+ * 
+ * @author Anton Koinov (latest modification by $Author: grantsmith $)
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+class _InitParameterMap extends _AbstractAttributeMap
+{
+    final ServletContext _servletContext;
+
+    _InitParameterMap(ServletContext servletContext)
+    {
+        _servletContext = servletContext;
+    }
+
+    protected Object getAttribute(String key)
+    {
+        return _servletContext.getInitParameter(key);
+    }
+
+    protected void setAttribute(String key, Object value)
+    {
+        if (_servletContext instanceof MockServletContext)
+        {
+            ((MockServletContext)_servletContext).addInitParameter(key, (String) value);
+        }
+        else
+        {
+            throw new UnsupportedOperationException(
+                "Cannot set ServletContext InitParameter");
+        }
+    }
+
+    protected void removeAttribute(String key)
+    {
+        throw new UnsupportedOperationException(
+            "Cannot remove ServletContext InitParameter");
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        return _servletContext.getInitParameterNames();
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_NullEnumeration.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_NullEnumeration.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_NullEnumeration.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_NullEnumeration.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,48 @@
+/*
+ *  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.myfaces.test.mock;
+
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * Enumeration without elements
+ *
+ * @author Anton Koinov (latest modification by $Author: matzew $)
+ * @version $Revision: 557350 $ $Date: 2007-07-18 13:19:50 -0500 (Mié, 18 Jul 2007) $
+ */
+final class _NullEnumeration implements Enumeration
+{
+    private static final _NullEnumeration s_nullEnumeration = new _NullEnumeration();
+
+    public static final _NullEnumeration instance()
+    {
+        return s_nullEnumeration;
+    }
+
+    public boolean hasMoreElements()
+    {
+        return false;
+    }
+
+    public Object nextElement()
+    {
+        throw new NoSuchElementException("NullEnumeration has no elements");
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * HttpServletRequest headers as Map.
+ * 
+ * @author Anton Koinov (latest modification by $Author: grantsmith $)
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+class _RequestHeaderMap extends _AbstractAttributeMap
+{
+    private final HttpServletRequest _httpServletRequest;
+
+    _RequestHeaderMap(HttpServletRequest httpServletRequest)
+    {
+        _httpServletRequest = httpServletRequest;
+    }
+
+    protected Object getAttribute(String key)
+    {
+        return _httpServletRequest.getHeader(key);
+    }
+
+    protected void setAttribute(String key, Object value)
+    {
+        if (_httpServletRequest instanceof MockHttpServletRequest)
+        {
+            ((MockHttpServletRequest)_httpServletRequest).addHeader(key, (String)value);
+        }
+        else
+        {
+            throw new UnsupportedOperationException(
+                "Cannot set HttpServletRequest Header");
+        }
+    }
+
+    protected void removeAttribute(String key)
+    {
+        throw new UnsupportedOperationException(
+            "Cannot remove HttpServletRequest Header");
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        return _httpServletRequest.getHeaderNames();
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestHeaderValuesMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+class _RequestHeaderValuesMap extends _AbstractAttributeMap
+{
+    private final HttpServletRequest _httpServletRequest;
+    private final Map _valueCache = new HashMap();
+
+    _RequestHeaderValuesMap(final HttpServletRequest httpServletRequest)
+    {
+        _httpServletRequest = httpServletRequest;
+    }
+
+    protected Object getAttribute(final String key)
+    {
+        String[] ret = (String[])_valueCache.get(key);
+        if (ret == null)
+        {
+            _valueCache.put(key, ret = toArray(_httpServletRequest.getHeaders(key)));
+        }
+
+        return ret;
+    }
+
+    protected void setAttribute(final String key, final Object value)
+    {
+        throw new UnsupportedOperationException("Cannot set HttpServletRequest HeaderValues");
+    }
+
+    protected void removeAttribute(final String key)
+    {
+        throw new UnsupportedOperationException("Cannot remove HttpServletRequest HeaderValues");
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        return _httpServletRequest.getHeaderNames();
+    }
+
+    private String[] toArray(Enumeration e)
+    {
+        List ret = new ArrayList();
+
+        while (e.hasMoreElements())
+        {
+            ret.add(e.nextElement());
+        }
+
+        return (String[]) ret.toArray(new String[ret.size()]);
+    }
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.Enumeration;
+import java.util.Map;
+
+import javax.servlet.ServletRequest;
+
+
+/**
+ * ServletRequest attributes Map.
+ * 
+ * @author Anton Koinov (latest modification by $Author: grantsmith $)
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+class _RequestMap extends _AbstractAttributeMap
+{
+    final ServletRequest _servletRequest;
+
+    _RequestMap(ServletRequest servletRequest)
+    {
+        _servletRequest = servletRequest;
+    }
+
+    protected Object getAttribute(String key)
+    {
+        return _servletRequest.getAttribute(key);
+    }
+
+    protected void setAttribute(String key, Object value)
+    {
+        _servletRequest.setAttribute(key, value);
+    }
+
+    protected void removeAttribute(String key)
+    {
+        _servletRequest.removeAttribute(key);
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        return _servletRequest.getAttributeNames();
+    }   
+}

Added: myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java
URL: http://svn.apache.org/viewvc/myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java?rev=959476&view=auto
==============================================================================
--- myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java (added)
+++ myfaces/test/trunk/test12/src/main/java/org/apache/myfaces/test/mock/_RequestParameterMap.java Thu Jul  1 00:15:53 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.myfaces.test.mock;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletRequest;
+
+/**
+ * ServletRequest parameters as Map.
+ * 
+ * @author Anton Koinov (latest modification by $Author: grantsmith $)
+ * @version $Revision: 472618 $ $Date: 2006-11-08 15:06:54 -0500 (Mié, 08 Nov 2006) $
+ */
+class _RequestParameterMap extends _AbstractAttributeMap
+{
+    private final ServletRequest _servletRequest;
+
+    _RequestParameterMap(ServletRequest servletRequest)
+    {
+        _servletRequest = servletRequest;
+    }
+
+    protected Object getAttribute(String key)
+    {
+        return _servletRequest.getParameter(key);
+    }
+
+    protected void setAttribute(String key, Object value)
+    {
+        if( _servletRequest instanceof MockHttpServletRequest)
+        {
+            ((MockHttpServletRequest)_servletRequest).addParameter(key, (String)value);
+        }
+        else
+        {
+            throw new UnsupportedOperationException(
+                "Cannot set ServletRequest Parameter");
+        }
+    }
+
+    protected void removeAttribute(String key)
+    {
+        throw new UnsupportedOperationException(
+            "Cannot remove ServletRequest Parameter");
+    }
+
+    protected Enumeration getAttributeNames()
+    {
+        return _servletRequest.getParameterNames();
+    }
+}
\ No newline at end of file