public class MockServerHttpRequest extends AbstractServerHttpRequest
AbstractServerHttpRequest
for use in tests without
an actual server.
Use the static builder methods in this class to create an instance possibly
further creating a MockServerWebExchange
via toExchange()
.
Modifier and Type | Class and Description |
---|---|
static interface |
MockServerHttpRequest.BaseBuilder<B extends MockServerHttpRequest.BaseBuilder<B>>
Request builder exposing properties not related to the body.
|
static interface |
MockServerHttpRequest.BodyBuilder
A builder that adds a body to the request.
|
ServerHttpRequest.Builder
Modifier and Type | Method and Description |
---|---|
static MockServerHttpRequest.BaseBuilder<?> |
delete(String urlTemplate,
Object... uriVars)
Create an HTTP DELETE builder with the given url.
|
static MockServerHttpRequest.BaseBuilder<?> |
get(String urlTemplate,
Object... uriVars)
Create an HTTP GET builder with the given url.
|
reactor.core.publisher.Flux<DataBuffer> |
getBody()
Return the body of the message as a
Publisher . |
HttpMethod |
getMethod()
Return the HTTP method of the request.
|
String |
getMethodValue()
Return the HTTP method of the request as a String
|
InetSocketAddress |
getRemoteAddress()
Return the remote address where this request is connected to, if available.
|
static MockServerHttpRequest.BaseBuilder<?> |
head(String urlTemplate,
Object... uriVars)
Create an HTTP HEAD builder with the given url.
|
protected MultiValueMap<String,HttpCookie> |
initCookies()
Obtain the cookies from the underlying "native" request and adapt those to
an
HttpCookie map. |
static MockServerHttpRequest.BodyBuilder |
method(HttpMethod method,
String urlTemplate,
Object... vars)
Alternative to
method(HttpMethod, URI) that accepts a URI template. |
static MockServerHttpRequest.BodyBuilder |
method(HttpMethod method,
URI url)
Create a builder with the given HTTP method and a
URI . |
static MockServerHttpRequest.BaseBuilder<?> |
options(String urlTemplate,
Object... uriVars)
Creates an HTTP OPTIONS builder with the given url.
|
static MockServerHttpRequest.BodyBuilder |
patch(String urlTemplate,
Object... uriVars)
Create an HTTP PATCH builder with the given url.
|
static MockServerHttpRequest.BodyBuilder |
post(String urlTemplate,
Object... uriVars)
Create an HTTP POST builder with the given url.
|
static MockServerHttpRequest.BodyBuilder |
put(String urlTemplate,
Object... uriVars)
Create an HTTP PUT builder with the given url.
|
MockServerWebExchange |
toExchange()
Shortcut to wrap the request with a
MockServerWebExchange . |
getCookies, getHeaders, getPath, getQueryParams, getURI, initQueryParams
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
mutate
public HttpMethod getMethod()
HttpRequest
null
if not resolvable (e.g. in case of a non-standard HTTP method)public String getMethodValue()
HttpRequest
@Nullable public InetSocketAddress getRemoteAddress()
ServerHttpRequest
public reactor.core.publisher.Flux<DataBuffer> getBody()
ReactiveHttpInputMessage
Publisher
.protected MultiValueMap<String,HttpCookie> initCookies()
AbstractServerHttpRequest
HttpCookie
map. The return value is turned into an immutable
map and cached.
Note that this method is invoked lazily on access to
AbstractServerHttpRequest.getCookies()
. Sub-classes should synchronize cookie
initialization if the underlying "native" request does not provide
thread-safe access to cookie data.
initCookies
in class AbstractServerHttpRequest
public MockServerWebExchange toExchange()
MockServerWebExchange
.public static MockServerHttpRequest.BodyBuilder method(HttpMethod method, URI url)
URI
.method
- the HTTP method (GET, POST, etc)url
- the URLpublic static MockServerHttpRequest.BodyBuilder method(HttpMethod method, String urlTemplate, Object... vars)
method(HttpMethod, URI)
that accepts a URI template.method
- the HTTP method (GET, POST, etc)urlTemplate
- the URL templatevars
- variables to expand into the templatepublic static MockServerHttpRequest.BaseBuilder<?> get(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BaseBuilder<?> head(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BodyBuilder post(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BodyBuilder put(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BodyBuilder patch(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BaseBuilder<?> delete(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variablespublic static MockServerHttpRequest.BaseBuilder<?> options(String urlTemplate, Object... uriVars)
urlTemplate
- a URL template; the resulting URL will be encodeduriVars
- zero or more URI variables