public class MockRestRequest extends RestRequest
RestRequest
with additional features for mocked testing.
Instances of this class are instantiated through methods on MockRestClient
such as MockRestClient.post(Object,Object)
Modifier | Constructor and Description |
---|---|
protected |
MockRestRequest(RestClient client,
URI uri,
String method,
boolean hasBody)
Constructs a REST call with the specified method name.
|
Modifier and Type | Method and Description |
---|---|
MockRestRequest |
attribute(String name,
Object value)
Adds an attribute to the underlying
HttpServletRequest object. |
MockRestRequest |
attributes(Map<String,Object> value)
Replaces the attributes on the underlying
HttpServletRequest object. |
MockRestRequest |
authType(String value)
Overrides the authorization type value on the underlying
HttpServletRequest object. |
MockRestRequest |
characterEncoding(String value)
Overrides the character encoding value on the underlying
HttpServletRequest object. |
MockRestRequest |
contextPath(String value)
Overrides the context path on the underlying
HttpServletRequest object. |
MockRestRequest |
cookies(Cookie[] value)
Overrides the cookies on the underlying
HttpServletRequest object. |
MockRestRequest |
dispatcherType(DispatcherType value)
Overrides the dispatcher type value on the underlying
HttpServletRequest object. |
Map<String,Object> |
getAttributeMap()
Returns the attributes to add to the underlying
HttpServletRequest object. |
String |
getAuthType()
Returns the authorization type value to set on the underlying
HttpServletRequest object. |
String |
getCharacterEncoding()
Returns the value to set for the return value on the underlying
ServletRequest.getCharacterEncoding() method. |
String |
getContextPath()
Returns the context path to set on the underlying
HttpServletRequest object. |
Cookie[] |
getCookies()
Returns the cookies to set on the underlying
HttpServletRequest object. |
DispatcherType |
getDispatcherType()
Returns the dispatcher type value to set on the underlying
HttpServletRequest object. |
HttpSession |
getHttpSession()
Returns the HTTP session to set on the underlying
HttpServletRequest object. |
String |
getLocalAddr()
Returns the local address value to set on the underlying
HttpServletRequest object. |
Locale |
getLocale()
Returns the locale to set on the underlying
HttpServletRequest object. |
String |
getLocalName()
Returns the local name value to set on the underlying
HttpServletRequest object. |
Integer |
getLocalPort()
Returns the local port value to set on the underlying
HttpServletRequest object. |
String |
getPathInfo()
Returns the path-info value to set on the underlying
HttpServletRequest object. |
String |
getPathTranslated()
Returns the path-translated value to set on the underlying
HttpServletRequest object. |
String |
getProtocol()
Returns the HTTP protocol value to set on the underlying
HttpServletRequest object. |
String |
getQueryString()
Returns the query string to set on the underlying
HttpServletRequest object. |
String |
getRemoteAddr()
Returns the remote address value to set on the underlying
HttpServletRequest object. |
String |
getRemoteHost()
Returns the remote host value to set on the underlying
HttpServletRequest object. |
Integer |
getRemotePort()
Returns the remote port value to set on the underlying
HttpServletRequest object. |
String |
getRemoteUser()
Returns the remote user to set on the underlying
HttpServletRequest object. |
Map<String,RequestDispatcher> |
getRequestDispatcherMap()
Returns the request dispatcher to set on the underlying
HttpServletRequest obhject. |
String |
getRequestedSessionId()
Returns the requested session ID to set on the underlying
HttpServletRequest object. |
String |
getRequestURI()
Returns the request URI to set on the underlying
HttpServletRequest object. |
String[] |
getRoles()
Returns the user roles to set on the underlying
HttpServletRequest object. |
String |
getScheme()
Returns the HTTP schema value to set on the underlying
HttpServletRequest object. |
String |
getServerName()
Returns the server name value to set on the underlying
HttpServletRequest object. |
Integer |
getServerPort()
Returns the server port value to set on the underlying
HttpServletRequest object. |
ServletContext |
getServletContext()
Returns the servlet context to set on the underlying
HttpServletRequest object. |
String |
getServletPath()
Returns the servlet path to set on the underlying
HttpServletRequest object. |
Principal |
getUserPrincipal()
Returns the user principal to set on the underlying
HttpServletRequest object. |
MockRestRequest |
httpSession(HttpSession value)
Overrides the HTTP session on the underlying
HttpServletRequest object. |
MockRestRequest |
localAddr(String value)
Overrides the local address value on the underlying
HttpServletRequest object. |
MockRestRequest |
locale(Locale value)
Overrides the locale on the underlying
HttpServletRequest object. |
MockRestRequest |
localName(String value)
Overrides the local name value on the underlying
HttpServletRequest object. |
MockRestRequest |
localPort(int value)
Overrides the local port value on the underlying
HttpServletRequest object. |
MockRestRequest |
pathInfo(String value)
Overrides the path-info value on the underlying
HttpServletRequest object. |
MockRestRequest |
pathTranslated(String value)
Overrides the path-translated value on the underlying
HttpServletRequest object. |
MockRestRequest |
protocol(String value)
Overrides the HTTP protocol value on the underlying
HttpServletRequest object. |
MockRestRequest |
queryString(String value)
Overrides the query string on the underlying
HttpServletRequest object. |
MockRestRequest |
remoteAddr(String value)
Overrides the remote address value on the underlying
HttpServletRequest object. |
MockRestRequest |
remoteHost(String value)
Overrides the remote host value on the underlying
HttpServletRequest object. |
MockRestRequest |
remotePort(int value)
Overrides the remote port value on the underlying
HttpServletRequest object. |
MockRestRequest |
remoteUser(String value)
Overrides the remote user on the underlying
HttpServletRequest object. |
MockRestRequest |
requestDispatcher(String path,
RequestDispatcher value)
Overrides the request dispatcher on the underlying
HttpServletRequest object. |
MockRestRequest |
requestedSessionId(String value)
Overrides the requested session ID on the underlying
HttpServletRequest object. |
MockRestRequest |
requestURI(String value)
Overrides the request URI on the underlying
HttpServletRequest object. |
MockRestRequest |
role(String role)
Specifies the value for the security roles on the underlying
HttpServletRequest object. |
MockRestRequest |
roles(String... roles)
Specifies the user roles on the underlying
HttpServletRequest object. |
MockRestRequest |
scheme(String value)
Overrides the HTTP schema value on the underlying
HttpServletRequest object. |
MockRestRequest |
serverName(String value)
Overrides the server name value on the underlying
HttpServletRequest object. |
MockRestRequest |
serverPort(int value)
Overrides the server port value on the underlying
HttpServletRequest object. |
MockRestRequest |
servletContext(ServletContext value)
Overrides the servlet context on the underlying
HttpServletRequest object. |
MockRestRequest |
servletPath(String value)
Overrides the servlet path on the underlying
HttpServletRequest object. |
MockRestRequest |
userPrincipal(Principal value)
Overrides the user principal on the underlying
HttpServletRequest object. |
abort, accept, acceptCharset, acceptEncoding, acceptLanguage, addHeader, addHeader, authorization, body, body, bodyString, cacheControl, cancellable, clientVersion, complete, completed, completeFuture, config, connection, containsHeader, contentEncoding, contentLength, contentType, context, createInnerRequest, date, debug, errorCodes, expect, formData, formData, formData, formData, formData, formDataCustom, formDataPairs, formDatas, formDatas, forwarded, fragment, from, getAllHeaders, getConfig, getFirstHeader, getHeader, getHeader, getHeaders, getHttpEntity, getLastHeader, getMethod, getParams, getProperties, getProtocolVersion, getRequestLine, getUri, getURI, hasHttpEntity, header, header, header, header, header, headerIterator, headerIterator, headerPairs, headers, headers, host, hostHeader, html, htmlDoc, htmlStrippedDoc, ifMatch, ifModifiedSince, ifNoneMatch, ifRange, ifUnmodifiedSince, ignoreErrors, interceptors, isAborted, isDebug, json, log, log, maxForwards, msgPack, noTrace, openApi, origin, parser, parser, path, path, path, pathPairs, paths, plainText, port, pragma, protocolVersion, proxyAuthorization, queries, queries, query, query, query, query, query, queryCustom, queryPairs, range, referer, removeHeader, removeHeaders, run, runFuture, serializer, serializer, setHeader, setHeader, setHeaders, setParams, simpleJson, target, te, toMap, uon, upgrade, uri, urlEnc, userAgent, userInfo, userInfo, via, warning, xml
_class, addWarning, checkForWarnings, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionaryClasses, getBeanFieldVisibility, getBeanFilters, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getExamples, getImplClasses, getNamePropertyName, getNotBeanClasses, getNotBeanPackagesNames, getNotBeanPackagesPrefixes, getPropertyNamer, getSchema, getStringBuilder, getSwaps, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnorePropertiesWithoutSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isSortProperties, isUseEnumNames, isUseInterfaceProxies, isUseJavaBeanIntrospector, newBean, newBean, newBeanMap, newBeanMap, object, returnStringBuilder, string, toArray, toBeanMap, toBeanMap
addToCache, addToCache, getClassProperty, getFromCache, getInstanceArrayProperty, getInstanceProperty, getMediaType, getProperty, getProperty, getProperty, getPropertyKeys, getTimeZone, getTimeZoneId, getWarnings, hasProperty, hasWarnings, toString
protected MockRestRequest(RestClient client, URI uri, String method, boolean hasBody) throws RestCallException
client
- The client that created this request.uri
- The target URI.method
- The HTTP method name (uppercase).hasBody
- Whether this method has a body.RestCallException
- If an exception or non-200 response code occurred during the connection attempt.public MockRestRequest attribute(String name, Object value)
HttpServletRequest
object.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
name
- The servlet request attribute name.value
- The servlet request attribute value.public MockRestRequest attributes(Map<String,Object> value)
HttpServletRequest
object.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new servlet attribute values.public Map<String,Object> getAttributeMap()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest roles(String... roles)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.isUserInRole(String)
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
roles
- The roles to add to this request (e.g. public String[] getRoles()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest role(String role)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.isUserInRole(String)
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
role
- The role to add to this request (e.g. public MockRestRequest characterEncoding(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getCharacterEncoding()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getCharacterEncoding()
ServletRequest.getCharacterEncoding()
method.ServletRequest.getCharacterEncoding()
method.public MockRestRequest protocol(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getProtocol()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getProtocol()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest scheme(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getScheme()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
scheme
in class RestRequest
value
- The new value for this setting.public String getScheme()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest serverName(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getServerName()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getServerName()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest serverPort(int value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getServerPort()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public Integer getServerPort()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest remoteAddr(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getRemoteAddr()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getRemoteAddr()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest remoteHost(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getRemoteHost()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getRemoteHost()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest locale(Locale value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getLocale()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public Locale getLocale()
HttpServletRequest
object.getLocale
in class Session
HttpServletRequest
object.Context.CONTEXT_locale
public MockRestRequest remotePort(int value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getRemotePort()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public Integer getRemotePort()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest localName(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getLocalName()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getLocalName()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest localAddr(String value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getLocalAddr()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getLocalAddr()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest localPort(int value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getLocalPort()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public Integer getLocalPort()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest requestDispatcher(String path, RequestDispatcher value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getRequestDispatcher(String)
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
path
- The path to the resource being resolved.value
- The new value for this setting.public Map<String,RequestDispatcher> getRequestDispatcherMap()
HttpServletRequest
obhject.public MockRestRequest servletContext(ServletContext value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getServletContext()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public ServletContext getServletContext()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest dispatcherType(DispatcherType value)
HttpServletRequest
object.
Affects the results of calling ServletRequest.getDispatcherType()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public DispatcherType getDispatcherType()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest authType(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getAuthType()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getAuthType()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest cookies(Cookie[] value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getCookies()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public Cookie[] getCookies()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest pathInfo(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getPathInfo()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getPathInfo()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest pathTranslated(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getPathTranslated()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getPathTranslated()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest contextPath(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getContextPath()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getContextPath()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest queryString(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getQueryString()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getQueryString()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest remoteUser(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getRemoteUser()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getRemoteUser()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest userPrincipal(Principal value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getUserPrincipal()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public Principal getUserPrincipal()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest requestedSessionId(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getRequestedSessionId()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getRequestedSessionId()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest requestURI(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getRequestURI()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getRequestURI()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest servletPath(String value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getServletPath()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public String getServletPath()
HttpServletRequest
object.HttpServletRequest
object.public MockRestRequest httpSession(HttpSession value)
HttpServletRequest
object.
Affects the results of calling HttpServletRequest.getSession()
.
This value gets copied to the servlet request after the call to HttpClientConnection.sendRequestHeader(HttpRequest)
and right before HttpClientConnection.sendRequestEntity(HttpEntityEnclosingRequest)
.
value
- The new value for this setting.public HttpSession getHttpSession()
HttpServletRequest
object.HttpServletRequest
object.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.