Class MockServerHttpRequest
java.lang.Object
org.springframework.http.server.reactive.AbstractServerHttpRequest
org.springframework.mock.http.server.reactive.MockServerHttpRequest
- All Implemented Interfaces:
- HttpMessage, HttpRequest, ReactiveHttpInputMessage, ServerHttpRequest
Mock extension of 
AbstractServerHttpRequest for use in tests without
an actual server. Use the static methods to obtain a builder.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceRequest builder exposing properties not related to the body.static interfaceA builder that adds a body to the request.Nested classes/interfaces inherited from interface ServerHttpRequestServerHttpRequest.Builder
- 
Method SummaryModifier and TypeMethodDescriptionstatic MockServerHttpRequest.BaseBuilder<?> HTTP DELETE variant.static MockServerHttpRequest.BaseBuilder<?> Create an HTTP GET builder with the given URI template.reactor.core.publisher.Flux<DataBuffer> getBody()Return the body of the message as aPublisher.Return the local address the request was accepted on, if available.<T> TReturn the underlying server response.Return the remote address where this request is connected to, if available.static MockServerHttpRequest.BaseBuilder<?> HTTP HEAD variant.protected MultiValueMap<String, HttpCookie> Obtain the cookies from the underlying "native" request and adapt those to anHttpCookiemap.Obtain SSL session information from the underlying "native" request.method(HttpMethod method, String uri, @Nullable Object... vars) Alternative tomethod(HttpMethod, URI)that accepts a URI template.method(HttpMethod method, URI url) Create a builder with the given HTTP method and aURI.static MockServerHttpRequest.BaseBuilder<?> HTTP OPTIONS variant.HTTP PATCH variant.HTTP POST variant.HTTP PUT variant.Methods inherited from class AbstractServerHttpRequestgetAttributes, getCookies, getHeaders, getId, getMethod, getPath, getQueryParams, getSslInfo, getURI, initId, initLogPrefix, initQueryParams, setAttributesSupplierMethods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ServerHttpRequestmutate
- 
Method Details- 
getLocalAddressDescription copied from interface:ServerHttpRequestReturn the local address the request was accepted on, if available.
- 
getRemoteAddressDescription copied from interface:ServerHttpRequestReturn the remote address where this request is connected to, if available.
- 
initSslInfoDescription copied from class:AbstractServerHttpRequestObtain SSL session information from the underlying "native" request.- Specified by:
- initSslInfoin class- AbstractServerHttpRequest
- Returns:
- the session information, or nullif none available
 
- 
getBodyDescription copied from interface:ReactiveHttpInputMessageReturn the body of the message as aPublisher.- Returns:
- the body content publisher
 
- 
initCookiesDescription copied from class:AbstractServerHttpRequestObtain the cookies from the underlying "native" request and adapt those to anHttpCookiemap. The return value is turned into an immutable map and cached.Note that this method is invoked lazily on access to AbstractServerHttpRequest.getCookies(). Subclasses should synchronize cookie initialization if the underlying "native" request does not provide thread-safe access to cookie data.- Specified by:
- initCookiesin class- AbstractServerHttpRequest
 
- 
getNativeRequestpublic <T> T getNativeRequest()Description copied from class:AbstractServerHttpRequestReturn the underlying server response.Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module. - Specified by:
- getNativeRequestin class- AbstractServerHttpRequest
 
- 
getpublic static MockServerHttpRequest.BaseBuilder<?> get(String urlTemplate, @Nullable Object... uriVars) Create an HTTP GET builder with the given URI template. The given URI may contain query parameters, or those may be added later viaqueryParambuilder methods.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
headpublic static MockServerHttpRequest.BaseBuilder<?> head(String urlTemplate, @Nullable Object... uriVars) HTTP HEAD variant. Seeget(String, Object...)for general info.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
postpublic static MockServerHttpRequest.BodyBuilder post(String urlTemplate, @Nullable Object... uriVars) HTTP POST variant. Seeget(String, Object...)for general info.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
putpublic static MockServerHttpRequest.BodyBuilder put(String urlTemplate, @Nullable Object... uriVars) HTTP PUT variant. Seeget(String, Object...)for general info.queryParambuilder methods.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
patchpublic static MockServerHttpRequest.BodyBuilder patch(String urlTemplate, @Nullable Object... uriVars) HTTP PATCH variant. Seeget(String, Object...)for general info.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
deletepublic static MockServerHttpRequest.BaseBuilder<?> delete(String urlTemplate, @Nullable Object... uriVars) HTTP DELETE variant. Seeget(String, Object...)for general info.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
optionspublic static MockServerHttpRequest.BaseBuilder<?> options(String urlTemplate, @Nullable Object... uriVars) HTTP OPTIONS variant. Seeget(String, Object...)for general info.- Parameters:
- urlTemplate- a URL template; the resulting URL will be encoded
- uriVars- zero or more URI variables
- Returns:
- the created builder
 
- 
methodCreate a builder with the given HTTP method and aURI.- Parameters:
- method- the HTTP method (GET, POST, etc)
- url- the URL
- Returns:
- the created builder
 
- 
methodpublic static MockServerHttpRequest.BodyBuilder method(HttpMethod method, String uri, @Nullable Object... vars) Alternative tomethod(HttpMethod, URI)that accepts a URI template. The given URI may contain query parameters, or those may be added later viaqueryParambuilder methods.- Parameters:
- method- the HTTP method (GET, POST, etc)
- uri- the URI template for the target URL
- vars- variables to expand into the template
- Returns:
- the created builder
 
 
-