org.apache.sling.commons.testing.sling
Class MockSlingHttpServletRequest

java.lang.Object
  extended by org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest, Adaptable, SlingHttpServletRequest

public class MockSlingHttpServletRequest
extends Object
implements SlingHttpServletRequest

Mock request object. This does not do anything useful, it just returns the constructor parameter secure in the isSecure method.


Field Summary
static String RESOURCE_TYPE
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
MockSlingHttpServletRequest(String resourcePath, String selectors, String extension, String suffix, String queryString)
           
 
Method Summary
<AdapterType>
AdapterType
adaptTo(Class<AdapterType> type)
          Adapts the adaptable to another type.
 Object getAttribute(String name)
           
 Enumeration<?> getAttributeNames()
           
 String getAuthType()
           
 String getCharacterEncoding()
           
 int getContentLength()
           
 String getContentType()
           
 String getContextPath()
           
 javax.servlet.http.Cookie getCookie(String name)
          Returns the named cookie from the HTTP request or null if no such cookie exists in the request.
 javax.servlet.http.Cookie[] getCookies()
           
 long getDateHeader(String name)
           
 String getHeader(String name)
           
 Enumeration<?> getHeaderNames()
           
 Enumeration<?> getHeaders(String name)
           
 javax.servlet.ServletInputStream getInputStream()
           
 int getIntHeader(String name)
           
 String getLocalAddr()
           
 Locale getLocale()
           
 Enumeration<?> getLocales()
           
 String getLocalName()
           
 int getLocalPort()
           
 String getMethod()
           
 String getParameter(String name)
           
 Map<?,?> getParameterMap()
           
 Enumeration<?> getParameterNames()
           
 String[] getParameterValues(String name)
           
 String getPathInfo()
           
 String getPathTranslated()
           
 String getProtocol()
           
 String getQueryString()
           
 BufferedReader getReader()
           
 String getRealPath(String path)
           
 String getRemoteAddr()
           
 String getRemoteHost()
           
 int getRemotePort()
           
 String getRemoteUser()
           
 javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource)
          Same as SlingHttpServletRequest.getRequestDispatcher(Resource,RequestDispatcherOptions) but using empty options.
 javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions options)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given resource.
 javax.servlet.RequestDispatcher getRequestDispatcher(String path)
           
 javax.servlet.RequestDispatcher getRequestDispatcher(String path, RequestDispatcherOptions options)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
 String getRequestedSessionId()
           
 RequestParameter getRequestParameter(String name)
          Returns the value of a request parameter as a RequestParameter, or null if the parameter does not exist.
 RequestParameterMap getRequestParameterMap()
          Returns a Map of the parameters of this request.
 RequestParameter[] getRequestParameters(String name)
          Returns an array of RequestParameter objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 RequestPathInfo getRequestPathInfo()
          Returns the RequestPathInfo pertaining to this request.
 RequestProgressTracker getRequestProgressTracker()
          Returns the RequestProgressTracker of this request.
 String getRequestURI()
           
 StringBuffer getRequestURL()
           
 Resource getResource()
          Returns the Resource object on whose behalf the servlet acts.
 ResourceBundle getResourceBundle(Locale locale)
          Returns the resource bundle for the given locale.
 ResourceBundle getResourceBundle(String baseName, Locale locale)
          Returns the resource bundle of the given base name for the given locale.
 ResourceResolver getResourceResolver()
          Returns the ResourceResolver which resolved the resource of this request.
 String getResponseContentType()
          Returns the framework preferred content type for the response.
 Enumeration<String> getResponseContentTypes()
          Gets a list of content types which the framework accepts for the response.
 String getScheme()
           
 String getServerName()
           
 int getServerPort()
           
 String getServletPath()
           
 javax.servlet.http.HttpSession getSession()
           
 javax.servlet.http.HttpSession getSession(boolean create)
           
 Principal getUserPrincipal()
           
 boolean isRequestedSessionIdFromCookie()
           
 boolean isRequestedSessionIdFromUrl()
           
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(String role)
           
 void removeAttribute(String name)
           
 void setAttribute(String name, Object o)
           
 void setCharacterEncoding(String env)
           
 void setMethod(String method)
           
 void setResource(Resource resource)
           
 void setResourceResolver(MockResourceResolver resolver)
           
 void setSecure(boolean secure)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_TYPE

public static final String RESOURCE_TYPE
See Also:
Constant Field Values
Constructor Detail

MockSlingHttpServletRequest

public MockSlingHttpServletRequest(String resourcePath,
                                   String selectors,
                                   String extension,
                                   String suffix,
                                   String queryString)
Method Detail

setResourceResolver

public void setResourceResolver(MockResourceResolver resolver)

setResource

public void setResource(Resource resource)

setSecure

public void setSecure(boolean secure)

setMethod

public void setMethod(String method)

getCookie

public javax.servlet.http.Cookie getCookie(String name)
Description copied from interface: SlingHttpServletRequest
Returns the named cookie from the HTTP request or null if no such cookie exists in the request.

Specified by:
getCookie in interface SlingHttpServletRequest
Parameters:
name - The name of the cookie to return.
Returns:
The named cookie or null if no such cookie exists.

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(String path,
                                                            RequestDispatcherOptions options)
Description copied from interface: SlingHttpServletRequest
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to include the resource in a response.

Returns null if a RequestDispatcher cannot be returned for any reason.

Specified by:
getRequestDispatcher in interface SlingHttpServletRequest
Parameters:
path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
options - influence the rendering of the included Resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource or null if an error occurs preparing the dispatcher.

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource,
                                                            RequestDispatcherOptions options)
Description copied from interface: SlingHttpServletRequest
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given resource. A RequestDispatcher object can be used to include the resource in a response.

Returns null if a RequestDispatcher cannot be returned for any reason.

Specified by:
getRequestDispatcher in interface SlingHttpServletRequest
Parameters:
resource - The Resource instance whose response content may be included by the returned dispatcher.
options - influence the rendering of the included Resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource or null if an error occurs preparing the dispatcher.

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource)
Description copied from interface: SlingHttpServletRequest
Same as SlingHttpServletRequest.getRequestDispatcher(Resource,RequestDispatcherOptions) but using empty options.

Specified by:
getRequestDispatcher in interface SlingHttpServletRequest

getRequestParameter

public RequestParameter getRequestParameter(String name)
Description copied from interface: SlingHttpServletRequest
Returns the value of a request parameter as a RequestParameter, or null if the parameter does not exist.

This method should only be used if the parameter has only one value. If the parameter might have more than one value, use SlingHttpServletRequest.getRequestParameters(String).

If this method is used with a multivalued parameter, the value returned is equal to the first value in the array returned by getRequestParameters.

This method is a shortcut for getRequestParameterMap().getValue(String).

Specified by:
getRequestParameter in interface SlingHttpServletRequest
Parameters:
name - a String specifying the name of the parameter
Returns:
a RequestParameter representing the single value of the parameter
See Also:
SlingHttpServletRequest.getRequestParameters(String), RequestParameterMap.getValue(String)

getRequestParameterMap

public RequestParameterMap getRequestParameterMap()
Description copied from interface: SlingHttpServletRequest
Returns a Map of the parameters of this request.

The values in the returned Map are from type RequestParameter array (RequestParameter[]).

If no parameters exist this method returns an empty Map.

Specified by:
getRequestParameterMap in interface SlingHttpServletRequest
Returns:
an immutable Map containing parameter names as keys and parameter values as map values, or an empty Map if no parameters exist. The keys in the parameter map are of type String. The values in the parameter map are of type RequestParameter array (RequestParameter[]).

getRequestParameters

public RequestParameter[] getRequestParameters(String name)
Description copied from interface: SlingHttpServletRequest
Returns an array of RequestParameter objects containing all of the values the given request parameter has, or null if the parameter does not exist.

If the parameter has a single value, the array has a length of 1.

This method is a shortcut for getRequestParameterMap().getValues(String).

Specified by:
getRequestParameters in interface SlingHttpServletRequest
Parameters:
name - a String containing the name of the parameter the value of which is requested
Returns:
an array of RequestParameter objects containing the parameter values.
See Also:
SlingHttpServletRequest.getRequestParameter(String), RequestParameterMap.getValues(String)

getRequestPathInfo

public RequestPathInfo getRequestPathInfo()
Description copied from interface: SlingHttpServletRequest
Returns the RequestPathInfo pertaining to this request.

Specified by:
getRequestPathInfo in interface SlingHttpServletRequest
Returns:
the request path info.

getRequestProgressTracker

public RequestProgressTracker getRequestProgressTracker()
Description copied from interface: SlingHttpServletRequest
Returns the RequestProgressTracker of this request.

Specified by:
getRequestProgressTracker in interface SlingHttpServletRequest

getResource

public Resource getResource()
Description copied from interface: SlingHttpServletRequest
Returns the Resource object on whose behalf the servlet acts.

Specified by:
getResource in interface SlingHttpServletRequest
Returns:
The Resource object of this request.

getResourceBundle

public ResourceBundle getResourceBundle(Locale locale)
Description copied from interface: SlingHttpServletRequest
Returns the resource bundle for the given locale.

Specified by:
getResourceBundle in interface SlingHttpServletRequest
Parameters:
locale - the locale for which to retrieve the resource bundle. If this is null, the locale returned by ServletRequest.getLocale() is used to select the resource bundle.
Returns:
the resource bundle for the given locale

getResourceBundle

public ResourceBundle getResourceBundle(String baseName,
                                        Locale locale)
Description copied from interface: SlingHttpServletRequest
Returns the resource bundle of the given base name for the given locale.

Specified by:
getResourceBundle in interface SlingHttpServletRequest
Parameters:
baseName - The base name of the resource bundle to returned. If this parameter is null, the same resource bundle must be returned as if the SlingHttpServletRequest.getResourceBundle(Locale) method is called.
locale - the locale for which to retrieve the resource bundle. If this is null, the locale returned by ServletRequest.getLocale() is used to select the resource bundle.
Returns:
the resource bundle for the given locale

getResourceResolver

public ResourceResolver getResourceResolver()
Description copied from interface: SlingHttpServletRequest
Returns the ResourceResolver which resolved the resource of this request.

Specified by:
getResourceResolver in interface SlingHttpServletRequest
Returns:
The resource resolver

getResponseContentType

public String getResponseContentType()
Description copied from interface: SlingHttpServletRequest
Returns the framework preferred content type for the response. The content type only includes the MIME type, not the character set.

For included resources this method will returned the same string as returned by the ServletResponse.getContentType() without the character set.

Specified by:
getResponseContentType in interface SlingHttpServletRequest
Returns:
preferred MIME type of the response

getResponseContentTypes

public Enumeration<String> getResponseContentTypes()
Description copied from interface: SlingHttpServletRequest
Gets a list of content types which the framework accepts for the response. This list is ordered with the most preferable types listed first. The content type only includes the MIME type, not the character set.

For included resources this method will returned an enumeration containing a single entry which is the same string as returned by the ServletResponse.getContentType() without the character set.

Specified by:
getResponseContentTypes in interface SlingHttpServletRequest
Returns:
ordered list of MIME types for the response

getAuthType

public String getAuthType()
Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getContextPath

public String getContextPath()
Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getCookies

public javax.servlet.http.Cookie[] getCookies()
Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(String name)
Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest

getHeader

public String getHeader(String name)
Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest

getHeaderNames

public Enumeration<?> getHeaderNames()
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getHeaders

public Enumeration<?> getHeaders(String name)
Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(String name)
Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest

getMethod

public String getMethod()
Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getPathInfo

public String getPathInfo()
Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public String getPathTranslated()
Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

getQueryString

public String getQueryString()
Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public String getRemoteUser()
Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getRequestURI

public String getRequestURI()
Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getRequestURL

public StringBuffer getRequestURL()
Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest

getRequestedSessionId

public String getRequestedSessionId()
Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

getServletPath

public String getServletPath()
Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession()
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getUserPrincipal

public Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isUserInRole

public boolean isUserInRole(String role)
Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

getAttribute

public Object getAttribute(String name)
Specified by:
getAttribute in interface javax.servlet.ServletRequest

getAttributeNames

public Enumeration<?> getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

getCharacterEncoding

public String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest

getContentLength

public int getContentLength()
Specified by:
getContentLength in interface javax.servlet.ServletRequest

getContentType

public String getContentType()
Specified by:
getContentType in interface javax.servlet.ServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
Specified by:
getInputStream in interface javax.servlet.ServletRequest

getLocalAddr

public String getLocalAddr()
Specified by:
getLocalAddr in interface javax.servlet.ServletRequest

getLocalName

public String getLocalName()
Specified by:
getLocalName in interface javax.servlet.ServletRequest

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface javax.servlet.ServletRequest

getLocale

public Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletRequest

getLocales

public Enumeration<?> getLocales()
Specified by:
getLocales in interface javax.servlet.ServletRequest

getParameter

public String getParameter(String name)
Specified by:
getParameter in interface javax.servlet.ServletRequest

getParameterMap

public Map<?,?> getParameterMap()
Specified by:
getParameterMap in interface javax.servlet.ServletRequest

getParameterNames

public Enumeration<?> getParameterNames()
Specified by:
getParameterNames in interface javax.servlet.ServletRequest

getParameterValues

public String[] getParameterValues(String name)
Specified by:
getParameterValues in interface javax.servlet.ServletRequest

getProtocol

public String getProtocol()
Specified by:
getProtocol in interface javax.servlet.ServletRequest

getReader

public BufferedReader getReader()
Specified by:
getReader in interface javax.servlet.ServletRequest

getRealPath

public String getRealPath(String path)
Specified by:
getRealPath in interface javax.servlet.ServletRequest

getRemoteAddr

public String getRemoteAddr()
Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

getRemoteHost

public String getRemoteHost()
Specified by:
getRemoteHost in interface javax.servlet.ServletRequest

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface javax.servlet.ServletRequest

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest

getScheme

public String getScheme()
Specified by:
getScheme in interface javax.servlet.ServletRequest

getServerName

public String getServerName()
Specified by:
getServerName in interface javax.servlet.ServletRequest

getServerPort

public int getServerPort()
Specified by:
getServerPort in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Specified by:
isSecure in interface javax.servlet.ServletRequest

removeAttribute

public void removeAttribute(String name)
Specified by:
removeAttribute in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(String name,
                         Object o)
Specified by:
setAttribute in interface javax.servlet.ServletRequest

setCharacterEncoding

public void setCharacterEncoding(String env)
Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest

adaptTo

public <AdapterType> AdapterType adaptTo(Class<AdapterType> type)
Description copied from interface: Adaptable
Adapts the adaptable to another type.

Specified by:
adaptTo in interface Adaptable
Type Parameters:
AdapterType - The generic type to which this resource is adapted to
Parameters:
type - The Class object of the target type, such as Node.class
Returns:
The adapter target or null if the resource cannot adapt to the requested type


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.