|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.uwyn.rife.test.MockRequest
public class MockRequest
Provides a Request implementation that is suitable for testing a
web application outside of a servlet container.
| Constructor Summary | |
|---|---|
MockRequest()
|
|
| Method Summary | |
|---|---|
MockRequest |
addDateHeader(String name,
long value)
Adds a request header with the given name and date-value. |
MockRequest |
addHeader(String name,
String value)
Adds a request header with the given name and value. |
MockRequest |
addIntHeader(String name,
int value)
Adds a request header with the given name and integer value. |
void |
addLocale(Locale locale)
Adds a Locale to this request. |
MockRequest |
characterEncoding(String encoding)
Set the character encoding of this request. |
boolean |
containsHeader(String name)
Checks whether a certain request header is present. |
MockRequest |
contentType(String type)
Set the content type of this request. |
MockRequest |
dateHeader(String name,
long value)
Sets a request header with the given name and date-value. |
MockRequest |
file(String name,
MockFileUpload file)
Sets a file in this request. |
MockRequest |
files(Map<String,MockFileUpload[]> files)
Sets a map of files in this request. |
MockRequest |
files(String name,
MockFileUpload[] files)
Sets files in this request. |
Object |
getAttribute(String name)
See ServletRequest.getAttribute(String). |
Enumeration |
getAttributeNames()
See ServletRequest.getAttributeNames(). |
String |
getCharacterEncoding()
See ServletRequest.getCharacterEncoding(). |
String |
getContentType()
See ServletRequest.getContentType(). |
String |
getContextPath()
See HttpServletRequest.getContextPath(). |
Cookie |
getCookie(String name)
Retrieves a cookie. |
Cookie[] |
getCookies()
See HttpServletRequest.getCookies(). |
long |
getDateHeader(String name)
See HttpServletRequest.getDateHeader(String). |
UploadedFile |
getFile(String name)
Retrieves an uploaded file. |
Map<String,UploadedFile[]> |
getFiles()
Retrieves the files that were uploaded in this request. |
UploadedFile[] |
getFiles(String name)
Retrieves all files that have been uploaded for a particular name. |
String |
getHeader(String name)
See HttpServletRequest.getHeader(String). |
Enumeration |
getHeaderNames()
See HttpServletRequest.getHeaderNames(). |
Enumeration |
getHeaders(String name)
See HttpServletRequest.getHeaders(String). |
HttpServletRequest |
getHttpServletRequest()
Retrieves the underlying HttpServletRequest. |
int |
getIntHeader(String name)
See HttpServletRequest.getIntHeader(String). |
Locale |
getLocale()
See ServletRequest.getLocale(). |
Enumeration |
getLocales()
See ServletRequest.getLocales(). |
RequestMethod |
getMethod()
See HttpServletRequest.getMethod(). |
Map<String,String[]> |
getParameters()
Retrieves all the parameters of this request. |
String |
getProtocol()
See ServletRequest.getProtocol(). |
String |
getRemoteAddr()
See ServletRequest.getRemoteAddr(). |
String |
getRemoteHost()
See ServletRequest.getRemoteHost(). |
String |
getRemoteUser()
See HttpServletRequest.getRemoteUser(). |
RequestDispatcher |
getRequestDispatcher(String url)
See ServletRequest.getRequestDispatcher(String). |
String |
getScheme()
See ServletRequest.getScheme(). |
String |
getServerName()
See ServletRequest.getServerName(). |
int |
getServerPort()
See ServletRequest.getServerPort(). |
String |
getServerRootUrl(int port)
Returns the root URL of the server that is running this web applications. |
HttpSession |
getSession()
See HttpServletRequest.getSession(). |
HttpSession |
getSession(boolean create)
See HttpServletRequest.getSession(boolean). |
boolean |
hasAttribute(String name)
Checks if a request attribute exists. |
boolean |
hasCookie(String name)
Checks whether a cookie is present. |
boolean |
hasFile(String name)
Checks if a particular file has been uploaded in this request. |
boolean |
hasParameter(String name)
Checks whether a named parameter is present in this request. |
MockRequest |
header(String name,
String value)
Sets a request header with the given name and value. |
void |
init(StateStore stateStore)
Initialize the state of this request from a StateStore. |
MockRequest |
intHeader(String name,
int value)
Sets a request header with the given name and integer value. |
boolean |
isSecure()
See ServletRequest.isSecure(). |
MockRequest |
locale(Locale locale)
Adds a Locale to this request. |
MockRequest |
method(RequestMethod method)
Sets the method of this request. |
MockRequest |
parameter(String name,
String value)
Sets a parameter in this request. |
MockRequest |
parameter(String name,
String[] values)
Sets a parameter in this request. |
MockRequest |
parameters(Map<String,String[]> parameters)
Sets a map of parameters in this request. |
MockRequest |
protocol(String protocol)
Set the protocol of this request. |
MockRequest |
remoteAddr(String remoteAddr)
Set the remote address of this request. |
MockRequest |
remoteHost(String remoteHost)
Set the remote host of this request. |
MockRequest |
remoteUser(String remoteUser)
Set the remote user of this request. |
void |
removeAttribute(String name)
See ServletRequest.removeAttribute(String). |
void |
removeHeader(String name)
Removes a request header with the given name. |
MockRequest |
secure(boolean secure)
Set whether this request is secure. |
void |
setAttribute(String name,
Object object)
See ServletRequest.setAttribute(String, Object). |
void |
setCharacterEncoding(String encoding)
Set the character encoding of this request. |
void |
setContentType(String type)
Set the content type of this request. |
void |
setDateHeader(String name,
long value)
Sets a request header with the given name and date-value. |
void |
setFile(String name,
MockFileUpload file)
Sets a file in this request. |
void |
setFiles(Map<String,MockFileUpload[]> files)
Sets a map of files in this request. |
void |
setFiles(String name,
MockFileUpload[] files)
Sets files in this request. |
void |
setHeader(String name,
String value)
Sets a request header with the given name and value. |
void |
setIntHeader(String name,
int value)
Sets a request header with the given name and integer value. |
void |
setMethod(RequestMethod method)
Sets the method of this request. |
void |
setParameter(String name,
String value)
Sets a parameter in this request. |
void |
setParameter(String name,
String[] values)
Sets a parameter in this request. |
void |
setParameters(Map<String,String[]> parameters)
Sets a map of parameters in this request. |
void |
setProtocol(String protocol)
Set the protocol of this request. |
void |
setRemoteAddr(String remoteAddr)
Set the remote address of this request. |
void |
setRemoteHost(String remoteHost)
Set the remote host of this request. |
void |
setRemoteUser(String remoteUser)
Set the remote user of this request. |
void |
setSecure(boolean secure)
Set whether this request is secure. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockRequest()
| Method Detail |
|---|
public void init(StateStore stateStore)
RequestStateStore.
This method is only there to be used by the web engine, it should never be called manually.
init in interface RequeststateStore - the StateStore that will be used to
initialize the requestpublic RequestMethod getMethod()
RequestHttpServletRequest.getMethod().
getMethod in interface Requestpublic void setMethod(RequestMethod method)
The method defaults to RequestMethod.GET.
method - the method that will be used by this requestgetMethod(),
method(com.uwyn.rife.engine.RequestMethod)public MockRequest method(RequestMethod method)
method - the method that will be used by this request
MockRequest instancegetMethod(),
setMethod(com.uwyn.rife.engine.RequestMethod)public boolean hasParameter(String name)
name - the name of the parameter to check
true if the parameter is present; or
false otherwise
getParameters(),
setParameters(java.util.Map) ,
setParameter(String, String[]),
setParameter(String, String)public Map<String,String[]> getParameters()
getParameters in interface RequestMap of the parameters with the names as the keys
and their value arrays as the valueshasParameter(java.lang.String),
setParameters(java.util.Map) ,
setParameter(String, String[]),
setParameter(String, String)public void setParameters(Map<String,String[]> parameters)
parameters - a Map of the parameters that will be set
with the names as the keys and their value arrays as the valueshasParameter(java.lang.String),
getParameters(),
setParameter(String, String[]),
setParameter(String, String)public MockRequest parameters(Map<String,String[]> parameters)
parameters - a Map of the parameters that will be set
with the names as the keys and their value arrays as the values
MockRequest instancehasParameter(java.lang.String),
getParameters(),
setParameters(java.util.Map) ,
setParameter(String, String[]),
setParameter(String, String)
public void setParameter(String name,
String[] values)
name - the name of the parametervalues - the value array of the parameterhasParameter(java.lang.String),
getParameters(),
setParameters(java.util.Map) ,
setParameter(String, String)
public MockRequest parameter(String name,
String[] values)
name - the name of the parametervalues - the value array of the parameter
MockRequest instancehasParameter(java.lang.String),
getParameters(),
setParameters(java.util.Map) ,
setParameter(String, String[]),
setParameter(String, String)
public void setParameter(String name,
String value)
name - the name of the parametervalue - the value of the parameterhasParameter(java.lang.String),
getParameters(),
setParameters(java.util.Map) ,
setParameter(String, String[])
public MockRequest parameter(String name,
String value)
name - the name of the parametervalue - the value of the parameter
MockRequest instancehasParameter(java.lang.String),
getParameters(),
setParameters(java.util.Map) ,
setParameter(String, String[]),
setParameter(String, String)public Map<String,UploadedFile[]> getFiles()
Request
getFiles in interface RequestMap with all the uploaded filesRequest.hasFile(String),
Request.getFile(String),
Request.getFiles(String)public boolean hasFile(String name)
Request
hasFile in interface Requestname - the name of the file, as declared in the submission
true if the file was uploaded; or
false otherwise
Request.getFiles(),
Request.getFile(String),
Request.getFiles(String)public UploadedFile getFile(String name)
Request
getFile in interface Requestname - the name of the file, as declared in the submission
null if no file was uploaded
Request.getFiles(),
Request.hasFile(String),
Request.getFiles(String)public UploadedFile[] getFiles(String name)
Request
getFiles in interface Requestname - the name of the file, as declared in the submission
null if no files were uploaded for that name
Request.getFiles(),
Request.hasFile(String),
Request.getFile(String)
public void setFile(String name,
MockFileUpload file)
name - the parameter name of the filefile - the file specification that will be uploadedhasFile(java.lang.String),
getFile(java.lang.String),
getFiles(),
setFiles(Map),
setFiles(String, MockFileUpload[])public void setFiles(Map<String,MockFileUpload[]> files)
files - a Map of the files that will be set with the
names as the keys and their file upload specifications as the valueshasFile(java.lang.String),
getFile(java.lang.String),
getFiles(),
setFile(String, MockFileUpload),
setFiles(String, MockFileUpload[])
public void setFiles(String name,
MockFileUpload[] files)
name - the parameter name of the filefiles - the file specifications that will be uploadedhasFile(java.lang.String),
getFile(java.lang.String),
getFiles(),
setFile(String, MockFileUpload),
setFiles(Map)
public MockRequest file(String name,
MockFileUpload file)
name - the parameter name of the filefile - the file specification that will be uploaded
MockRequest instancehasFile(java.lang.String),
getFile(java.lang.String),
getFiles(),
setFile(String, MockFileUpload),
setFiles(Map),
setFiles(String, MockFileUpload[])public MockRequest files(Map<String,MockFileUpload[]> files)
files - a Map of the files that will be set with the
names as the keys and their file upload specifications as the values
MockRequest instancehasFile(java.lang.String),
getFile(java.lang.String),
getFiles(),
setFile(String, MockFileUpload),
setFiles(Map),
setFiles(String, MockFileUpload[])
public MockRequest files(String name,
MockFileUpload[] files)
name - the parameter name of the filefiles - the file specifications that will be uploaded
MockRequest instancehasFile(java.lang.String),
getFile(java.lang.String),
getFiles(),
setFile(String, MockFileUpload),
setFiles(Map),
setFiles(String, MockFileUpload[])public String getServerRootUrl(int port)
RequestThis includes the protocol, the server name and the server port, for
example: http://www.somehost.com:8080.
getServerRootUrl in interface Requestpublic boolean hasCookie(String name)
Request
hasCookie in interface Requestname - the name of the cookie
true if the cookie was present; or
false otherwise
Request.getCookie(String),
Request.getCookies()public Cookie getCookie(String name)
Request
getCookie in interface Requestname - the name of the cookie.
null if no such cookie is present
Request.hasCookie(String),
Request.getCookies()public Cookie[] getCookies()
RequestHttpServletRequest.getCookies().
getCookies in interface Requestpublic Object getAttribute(String name)
RequestServletRequest.getAttribute(String).
getAttribute in interface Requestpublic boolean hasAttribute(String name)
Request
hasAttribute in interface Requestname - a String specifying the name of the attribute
false otherwise
public Enumeration getAttributeNames()
RequestServletRequest.getAttributeNames().
getAttributeNames in interface Requestpublic void removeAttribute(String name)
RequestServletRequest.removeAttribute(String).
removeAttribute in interface Request
public void setAttribute(String name,
Object object)
RequestServletRequest.setAttribute(String, Object).
setAttribute in interface Requestpublic String getCharacterEncoding()
RequestServletRequest.getCharacterEncoding().
getCharacterEncoding in interface Requestpublic void setCharacterEncoding(String encoding)
encoding - the name of the character encodingpublic MockRequest characterEncoding(String encoding)
encoding - the name of the character encoding
MockRequest instancepublic String getContentType()
RequestServletRequest.getContentType().
getContentType in interface Requestpublic void setContentType(String type)
type - the content typepublic MockRequest contentType(String type)
type - the content type
MockRequest instancepublic long getDateHeader(String name)
RequestHttpServletRequest.getDateHeader(String).
getDateHeader in interface Requestpublic String getHeader(String name)
RequestHttpServletRequest.getHeader(String).
getHeader in interface Requestpublic Enumeration getHeaderNames()
RequestHttpServletRequest.getHeaderNames().
getHeaderNames in interface Requestpublic Enumeration getHeaders(String name)
RequestHttpServletRequest.getHeaders(String).
getHeaders in interface Requestpublic int getIntHeader(String name)
RequestHttpServletRequest.getIntHeader(String).
getIntHeader in interface Request
public MockRequest addHeader(String name,
String value)
name - the name of the header to setvalue - the additional header value
MockRequest instance
public MockRequest addDateHeader(String name,
long value)
name - the name of the header to setvalue - the additional date value
MockRequest instance
public MockRequest addIntHeader(String name,
int value)
name - the name of the header to setvalue - the additional integer value
MockRequest instancepublic boolean containsHeader(String name)
name - the name of the header to check
true if the header was present; or
false otherwise
public void setDateHeader(String name,
long value)
containsHeader(java.lang.String) method can be used to test for the presence of a
header before setting its value.
name - the name of the header to setvalue - the assigned date value
public MockRequest dateHeader(String name,
long value)
name - the name of the header to setvalue - the assigned date valuesetDateHeader(java.lang.String, long)
public void setHeader(String name,
String value)
containsHeader(java.lang.String) method can be used to test for the presence of a
header before setting its value.
name - the name of the header to setvalue - the header value
public MockRequest header(String name,
String value)
name - the name of the header to setvalue - the header valuesetDateHeader(java.lang.String, long)
public void setIntHeader(String name,
int value)
name - the name of the header to setvalue - the assigned integer value
public MockRequest intHeader(String name,
int value)
name - the name of the header to setvalue - the assigned integer valuesetDateHeader(java.lang.String, long)public void removeHeader(String name)
name - the name of the header to removepublic Locale getLocale()
RequestServletRequest.getLocale().
getLocale in interface Requestpublic Enumeration getLocales()
RequestServletRequest.getLocales().
getLocales in interface Requestpublic void addLocale(Locale locale)
Locale to this request.
locale - the locale to addpublic MockRequest locale(Locale locale)
Locale to this request.
locale - the locale to add
MockRequest instancepublic String getProtocol()
RequestServletRequest.getProtocol().
getProtocol in interface Requestpublic void setProtocol(String protocol)
The default protocol is "HTTP/1.1".
protocol - the protocol to setpublic MockRequest protocol(String protocol)
protocol - the protocol to set
MockRequest instancepublic String getRemoteAddr()
RequestServletRequest.getRemoteAddr().
getRemoteAddr in interface Requestpublic void setRemoteAddr(String remoteAddr)