final class HtmlUnitRequestBuilder extends java.lang.Object implements RequestBuilder, Mergeable
WebRequest
into a
MockHttpServletRequest
using Spring MVC Test's RequestBuilder
.
By default the first path segment of the URL is used as the contextPath.
To override this default see setContextPath(String)
.
MockMvcWebConnection
Modifier and Type | Class and Description |
---|---|
private class |
HtmlUnitRequestBuilder.HtmlUnitMockHttpServletRequest
An extension to
MockHttpServletRequest that ensures that when a
new HttpSession is created, it is added to the managed sessions. |
private class |
HtmlUnitRequestBuilder.HtmlUnitMockHttpSession
An extension to
MockHttpSession that ensures when
HtmlUnitRequestBuilder.HtmlUnitMockHttpSession.invalidate() is called that the HttpSession
is removed from the managed sessions. |
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
contextPath |
private RequestPostProcessor |
forwardPostProcessor |
private static java.util.regex.Pattern |
LOCALE_PATTERN |
private RequestBuilder |
parentBuilder |
private SmartRequestBuilder |
parentPostProcessor |
private java.util.Map<java.lang.String,MockHttpSession> |
sessions |
private WebClient |
webClient |
private WebRequest |
webRequest |
Constructor and Description |
---|
HtmlUnitRequestBuilder(java.util.Map<java.lang.String,MockHttpSession> sessions,
WebClient webClient,
WebRequest webRequest)
Construct a new
HtmlUnitRequestBuilder . |
Modifier and Type | Method and Description |
---|---|
private void |
addSessionCookie(MockHttpServletRequest request,
java.lang.String sessionid) |
private void |
authType(MockHttpServletRequest request) |
MockHttpServletRequest |
buildRequest(ServletContext servletContext)
Build the request.
|
private void |
content(MockHttpServletRequest request,
java.lang.String charset) |
private void |
contentType(MockHttpServletRequest request) |
private void |
contextPath(MockHttpServletRequest request,
UriComponents uriComponents) |
private void |
cookies(MockHttpServletRequest request) |
private com.gargoylesoftware.htmlunit.util.Cookie |
createCookie(MockHttpServletRequest request,
java.lang.String sessionid) |
private java.lang.String |
getCharset() |
private CookieManager |
getCookieManager() |
private java.lang.String |
header(java.lang.String headerName) |
private void |
headers(MockHttpServletRequest request) |
private MockHttpSession |
httpSession(MockHttpServletRequest request,
java.lang.String sessionid) |
boolean |
isMergeEnabled()
Is merging enabled for this particular instance?
|
private void |
locales(MockHttpServletRequest request) |
java.lang.Object |
merge(java.lang.Object parent)
Merge the current value set with that of the supplied object.
|
private void |
params(MockHttpServletRequest request,
UriComponents uriComponents) |
private void |
parent(MockHttpServletRequest request,
RequestBuilder parent) |
private java.util.Locale |
parseLocale(java.lang.String locale) |
private void |
ports(UriComponents uriComponents,
MockHttpServletRequest request) |
private MockHttpServletRequest |
postProcess(MockHttpServletRequest request) |
private void |
processCookie(MockHttpServletRequest request,
java.util.List<Cookie> cookies,
Cookie cookie) |
private void |
removeSessionCookie(MockHttpServletRequest request,
java.lang.String sessionid) |
private void |
servletPath(MockHttpServletRequest request,
java.lang.String requestPath) |
private void |
servletPath(UriComponents uriComponents,
MockHttpServletRequest request) |
void |
setContextPath(java.lang.String contextPath)
Set the contextPath to be used.
|
void |
setForwardPostProcessor(RequestPostProcessor forwardPostProcessor) |
private UriComponents |
uriComponents() |
private java.lang.String |
urlDecode(java.lang.String value) |
private static final java.util.regex.Pattern LOCALE_PATTERN
private final java.util.Map<java.lang.String,MockHttpSession> sessions
private final WebClient webClient
private final WebRequest webRequest
private java.lang.String contextPath
private RequestBuilder parentBuilder
private SmartRequestBuilder parentPostProcessor
private RequestPostProcessor forwardPostProcessor
public HtmlUnitRequestBuilder(java.util.Map<java.lang.String,MockHttpSession> sessions, WebClient webClient, WebRequest webRequest)
HtmlUnitRequestBuilder
.sessions
- a Map
from session IDs
to currently managed HttpSession
objects; never null
webClient
- the WebClient for retrieving cookieswebRequest
- the WebRequest
to transform into a
MockHttpServletRequest
; never null
public MockHttpServletRequest buildRequest(ServletContext servletContext)
RequestBuilder
buildRequest
in interface RequestBuilder
servletContext
- the ServletContext
to use to create the requestprivate MockHttpServletRequest postProcess(MockHttpServletRequest request)
private void parent(MockHttpServletRequest request, RequestBuilder parent)
public void setContextPath(java.lang.String contextPath)
The value may be null in which case the first path segment of the
URL is turned into the contextPath. Otherwise it must conform to
HttpServletRequest#getContextPath()
which states it can be
an empty string, or it must start with a "/" and not end with a "/".
contextPath
- a valid contextPathjava.lang.IllegalArgumentException
- if the contextPath is not a valid
HttpServletRequest#getContextPath()
public void setForwardPostProcessor(RequestPostProcessor forwardPostProcessor)
private void authType(MockHttpServletRequest request)
private void content(MockHttpServletRequest request, java.lang.String charset)
private void contentType(MockHttpServletRequest request)
private void contextPath(MockHttpServletRequest request, UriComponents uriComponents)
private void cookies(MockHttpServletRequest request)
private void processCookie(MockHttpServletRequest request, java.util.List<Cookie> cookies, Cookie cookie)
private java.lang.String getCharset()
private java.lang.String header(java.lang.String headerName)
private void headers(MockHttpServletRequest request)
private MockHttpSession httpSession(MockHttpServletRequest request, java.lang.String sessionid)
private void addSessionCookie(MockHttpServletRequest request, java.lang.String sessionid)
private void removeSessionCookie(MockHttpServletRequest request, java.lang.String sessionid)
private com.gargoylesoftware.htmlunit.util.Cookie createCookie(MockHttpServletRequest request, java.lang.String sessionid)
private void locales(MockHttpServletRequest request)
private void params(MockHttpServletRequest request, UriComponents uriComponents)
private java.lang.String urlDecode(java.lang.String value)
private java.util.Locale parseLocale(java.lang.String locale)
private void servletPath(MockHttpServletRequest request, java.lang.String requestPath)
private void servletPath(UriComponents uriComponents, MockHttpServletRequest request)
private void ports(UriComponents uriComponents, MockHttpServletRequest request)
private UriComponents uriComponents()
public boolean isMergeEnabled()
Mergeable
isMergeEnabled
in interface Mergeable
public java.lang.Object merge(java.lang.Object parent)
Mergeable
The supplied object is considered the parent, and values in the callee's value set must override those of the supplied object.
private CookieManager getCookieManager()