Fish & Chips Club 4.10.0.0

hirondelle.fish.test.doubles
Class FakeRequest

Object
  extended by hirondelle.fish.test.doubles.FakeRequest
All Implemented Interfaces:
HttpServletRequest, ServletRequest

public final class FakeRequest
extends Object
implements HttpServletRequest

Fake implementation of HttpServletRequest, used only for testing outside of the regular runtime environment.

Various methods have been added to make testing more convenient.

The logInAuthenticatedUser(String, List) method allows you to mimic an authenticated user.


Nested Class Summary
static class FakeRequest.HttpMethod
          Used by factory methods to distinguish between GET and POST requests.
 
Field Summary
 
Fields inherited from interface HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
FakeRequest(String aScheme, String aServerName, Integer aServerPort, String aContextPath, String aServletMatchingPath, String aExtraPath, String aQueryString, FakeRequest.HttpMethod aMethod)
          Full constructor.
 
Method Summary
 void addCookie(String aName, String aValue)
          Method added for testing.
 void addHeader(String aName, String aValue)
          Date/time headers must use RFC 1123 format.
 void addParameter(String aName, String aValue)
          Method added for testing.
static FakeRequest forGET(String aServletMatchingPath, String aQueryString)
          Factory method for GET requests .
static FakeRequest forPOST(String aServletMatchingPath, String aQueryString)
          Factory method for POST requests .
 Object getAttribute(String aName)
           
 Enumeration getAttributeNames()
           
 String getAuthType()
          Returns null - not authenticated.
 String getCharacterEncoding()
          Default value 'UTF-8'.
 int getContentLength()
          Default value 0.
 String getContentType()
          Default value 'text/html'.
 String getContextPath()
           
 Cookie[] getCookies()
           
 long getDateHeader(String aName)
           
 String getHeader(String aName)
           
 Enumeration getHeaderNames()
           
 Enumeration getHeaders(String aName)
           
 ServletInputStream getInputStream()
          Returns null - not implemented.
 int getIntHeader(String aName)
           
 String getLocalAddr()
          Default value '127.0.0.1'.
 Locale getLocale()
          Default value Locale.ENGLISH.
 Enumeration getLocales()
          Returns only one Locale.
 String getLocalName()
          Default value '127.0.0.1'.
 int getLocalPort()
          Default value 8080.
 String getMethod()
           
 String getParameter(String aName)
           
 Map getParameterMap()
           
 Enumeration getParameterNames()
           
 String[] getParameterValues(String aName)
           
 String getPathInfo()
           
 String getPathTranslated()
          Returns null - not implemented.
 String getProtocol()
           
 String getQueryString()
          Created from the given request parameters.
 BufferedReader getReader()
          Returns null - not implemented.
 String getRealPath(String aPath)
          Returns null - deprecated.
 String getRemoteAddr()
          Default value '127.0.0.1'.
 String getRemoteHost()
          Default value '127.0.0.1'.
 int getRemotePort()
          Default value '80'.
 String getRemoteUser()
           
 RequestDispatcher getRequestDispatcher(String aPath)
          Returns null - not implemented.
 String getRequestedSessionId()
           
 String getRequestURI()
           
 StringBuffer getRequestURL()
           
 String getScheme()
          Default value 'http'.
 String getServerName()
          Default value 'Test Double'.
 int getServerPort()
          Default value 8080.
 String getServletPath()
           
 HttpSession getSession()
           
 HttpSession getSession(boolean aCreateNew)
           
 Principal getUserPrincipal()
           
 boolean isRequestedSessionIdFromCookie()
          Hard-code to true.
 boolean isRequestedSessionIdFromUrl()
          Hard-code to false.
 boolean isRequestedSessionIdFromURL()
          Hard-code to false.
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(String aRole)
           
 void logInAuthenticatedUser(String aUserName, List<String> aRoles)
          Method added for testing.
 void removeAttribute(String aName)
           
 void setAttribute(String aName, Object aObject)
           
 void setCharacterEncoding(String aEncoding)
           
 void setContentLength(int aContentLength)
          Method added for testing.
 void setContentType(String aContentType)
          Method added for testing.
 void setIsSecure(boolean aIsSecure)
          Method added for testing.
 void setLocale(Locale aLocale)
          Method added for testing.
 void setProtocol(String aProtocol)
          Method added for testing.
 void setRemoteAddr(String aRemoteAddr)
          Method added for testing.
 void setRemoteHost(String aRemoteHost)
          Method added for testing.
 void setRemotePort(int aRemotePort)
          Method added for testing.
 void setRequestedSessionId(String aSessionId)
          Method added for testing.
 void setScheme(String aScheme)
          Method added for testing.
 void setServerName(String aServerName)
          Method added for testing.
 void setServerPort(int aServerPort)
          Method added for testing.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FakeRequest

public FakeRequest(String aScheme,
                   String aServerName,
                   Integer aServerPort,
                   String aContextPath,
                   String aServletMatchingPath,
                   String aExtraPath,
                   String aQueryString,
                   FakeRequest.HttpMethod aMethod)
Full constructor.

Method Detail

forGET

public static FakeRequest forGET(String aServletMatchingPath,
                                 String aQueryString)
Factory method for GET requests .


forPOST

public static FakeRequest forPOST(String aServletMatchingPath,
                                  String aQueryString)
Factory method for POST requests .


setContentType

public void setContentType(String aContentType)
Method added for testing.


setContentLength

public void setContentLength(int aContentLength)
Method added for testing.


setProtocol

public void setProtocol(String aProtocol)
Method added for testing.


setScheme

public void setScheme(String aScheme)
Method added for testing.


setServerName

public void setServerName(String aServerName)
Method added for testing.


setServerPort

public void setServerPort(int aServerPort)
Method added for testing.


setRemoteAddr

public void setRemoteAddr(String aRemoteAddr)
Method added for testing.


setRemoteHost

public void setRemoteHost(String aRemoteHost)
Method added for testing.


setIsSecure

public void setIsSecure(boolean aIsSecure)
Method added for testing.


setRemotePort

public void setRemotePort(int aRemotePort)
Method added for testing.


setLocale

public void setLocale(Locale aLocale)
Method added for testing.


addCookie

public void addCookie(String aName,
                      String aValue)
Method added for testing.


addParameter

public void addParameter(String aName,
                         String aValue)
Method added for testing.


addHeader

public void addHeader(String aName,
                      String aValue)
Date/time headers must use RFC 1123 format. Method added for testing.


logInAuthenticatedUser

public void logInAuthenticatedUser(String aUserName,
                                   List<String> aRoles)
Method added for testing.


setRequestedSessionId

public void setRequestedSessionId(String aSessionId)
Method added for testing.


getAttribute

public Object getAttribute(String aName)
Specified by:
getAttribute in interface ServletRequest

getAttributeNames

public Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface ServletRequest

setAttribute

public void setAttribute(String aName,
                         Object aObject)
Specified by:
setAttribute in interface ServletRequest

removeAttribute

public void removeAttribute(String aName)
Specified by:
removeAttribute in interface ServletRequest

getCharacterEncoding

public String getCharacterEncoding()
Default value 'UTF-8'.

Specified by:
getCharacterEncoding in interface ServletRequest

setCharacterEncoding

public void setCharacterEncoding(String aEncoding)
                          throws UnsupportedEncodingException
Specified by:
setCharacterEncoding in interface ServletRequest
Throws:
UnsupportedEncodingException

getContentLength

public int getContentLength()
Default value 0.

Specified by:
getContentLength in interface ServletRequest

getContentType

public String getContentType()
Default value 'text/html'.

Specified by:
getContentType in interface ServletRequest

getParameter

public String getParameter(String aName)
Specified by:
getParameter in interface ServletRequest

getParameterNames

public Enumeration getParameterNames()
Specified by:
getParameterNames in interface ServletRequest

getParameterValues

public String[] getParameterValues(String aName)
Specified by:
getParameterValues in interface ServletRequest

getParameterMap

public Map getParameterMap()
Specified by:
getParameterMap in interface ServletRequest

getProtocol

public String getProtocol()
Specified by:
getProtocol in interface ServletRequest

getScheme

public String getScheme()
Default value 'http'.

Specified by:
getScheme in interface ServletRequest

getServerName

public String getServerName()
Default value 'Test Double'.

Specified by:
getServerName in interface ServletRequest

getServerPort

public int getServerPort()
Default value 8080.

Specified by:
getServerPort in interface ServletRequest

getLocalAddr

public String getLocalAddr()
Default value '127.0.0.1'.

Specified by:
getLocalAddr in interface ServletRequest

getLocalName

public String getLocalName()
Default value '127.0.0.1'.

Specified by:
getLocalName in interface ServletRequest

getLocalPort

public int getLocalPort()
Default value 8080.

Specified by:
getLocalPort in interface ServletRequest

getRemoteAddr

public String getRemoteAddr()
Default value '127.0.0.1'.

Specified by:
getRemoteAddr in interface ServletRequest

getRemoteHost

public String getRemoteHost()
Default value '127.0.0.1'.

Specified by:
getRemoteHost in interface ServletRequest

getRemotePort

public int getRemotePort()
Default value '80'.

Specified by:
getRemotePort in interface ServletRequest

getLocale

public Locale getLocale()
Default value Locale.ENGLISH.

Specified by:
getLocale in interface ServletRequest

getLocales

public Enumeration getLocales()
Returns only one Locale.

Specified by:
getLocales in interface ServletRequest

isSecure

public boolean isSecure()
Specified by:
isSecure in interface ServletRequest

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String aPath)
Returns null - not implemented.

Specified by:
getRequestDispatcher in interface ServletRequest

getRealPath

public String getRealPath(String aPath)
Returns null - deprecated.

Specified by:
getRealPath in interface ServletRequest

getInputStream

public ServletInputStream getInputStream()
                                  throws IOException
Returns null - not implemented.

Specified by:
getInputStream in interface ServletRequest
Throws:
IOException

getReader

public BufferedReader getReader()
                         throws IOException
Returns null - not implemented.

Specified by:
getReader in interface ServletRequest
Throws:
IOException

getAuthType

public String getAuthType()
Returns null - not authenticated.

Specified by:
getAuthType in interface HttpServletRequest

getCookies

public Cookie[] getCookies()
Specified by:
getCookies in interface HttpServletRequest

getDateHeader

public long getDateHeader(String aName)
Specified by:
getDateHeader in interface HttpServletRequest

getHeader

public String getHeader(String aName)
Specified by:
getHeader in interface HttpServletRequest

getHeaders

public Enumeration getHeaders(String aName)
Specified by:
getHeaders in interface HttpServletRequest

getHeaderNames

public Enumeration getHeaderNames()
Specified by:
getHeaderNames in interface HttpServletRequest

getIntHeader

public int getIntHeader(String aName)
Specified by:
getIntHeader in interface HttpServletRequest

getMethod

public String getMethod()
Specified by:
getMethod in interface HttpServletRequest

getPathInfo

public String getPathInfo()
Specified by:
getPathInfo in interface HttpServletRequest

getPathTranslated

public String getPathTranslated()
Returns null - not implemented.

Specified by:
getPathTranslated in interface HttpServletRequest

getContextPath

public String getContextPath()
Specified by:
getContextPath in interface HttpServletRequest

getQueryString

public String getQueryString()
Created from the given request parameters. Includes the initial '?'. Returns null if no parameters present. This implementation is artificial but convenient, since it makes no distinction between GET and POST.

Specified by:
getQueryString in interface HttpServletRequest

getRemoteUser

public String getRemoteUser()
Specified by:
getRemoteUser in interface HttpServletRequest

isUserInRole

public boolean isUserInRole(String aRole)
Specified by:
isUserInRole in interface HttpServletRequest

getUserPrincipal

public Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface HttpServletRequest

getRequestURI

public String getRequestURI()
Specified by:
getRequestURI in interface HttpServletRequest

getRequestURL

public StringBuffer getRequestURL()
Specified by:
getRequestURL in interface HttpServletRequest

getServletPath

public String getServletPath()
Specified by:
getServletPath in interface HttpServletRequest

getRequestedSessionId

public String getRequestedSessionId()
Specified by:
getRequestedSessionId in interface HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Specified by:
isRequestedSessionIdValid in interface HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Hard-code to true.

Specified by:
isRequestedSessionIdFromCookie in interface HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Hard-code to false.

Specified by:
isRequestedSessionIdFromURL in interface HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Hard-code to false.

Specified by:
isRequestedSessionIdFromUrl in interface HttpServletRequest

getSession

public HttpSession getSession(boolean aCreateNew)
Specified by:
getSession in interface HttpServletRequest

getSession

public HttpSession getSession()
Specified by:
getSession in interface HttpServletRequest

Fish & Chips Club 4.10.0.0

Copyright Hirondelle Systems - Generated 2013Oct19.12.26