Package org.springframework.mock.http.server.reactive

# Class MockServerHttpRequest

java.lang.Object
org.springframework.http.server.reactive.AbstractServerHttpRequest
org.springframework.mock.http.server.reactive.MockServerHttpRequest

All Implemented Interfaces:
  `org.springframework.http.HttpMessage`, `org.springframework.http.HttpRequest`, `org.springframework.http.ReactiveHttpInputMessage`, `org.springframework.http.server.reactive.ServerHttpRequest`

public final class MockServerHttpRequest extends org.springframework.http.server.reactive.AbstractServerHttpRequest
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 Summary

Nested Classes
Modifier and Type
Class
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.

## Nested classes/interfaces inherited from interface org.springframework.http.server.reactive.ServerHttpRequest

`org.springframework.http.server.reactive.ServerHttpRequest.Builder`

## Method Summary

Modifier and Type
Method
Description
`static MockServerHttpRequest.BaseBuilder<?>`
`delete(String urlTemplate, Object... uriVars)`
HTTP DELETE variant.
`static MockServerHttpRequest.BaseBuilder<?>`
`get(String urlTemplate, Object... uriVars)`
Create an HTTP GET builder with the given URI template.
`reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>`
`getBody()`
`InetSocketAddress`
`getLocalAddress()`
`<T> T`
`getNativeRequest()`
`InetSocketAddress`
`getRemoteAddress()`
`static MockServerHttpRequest.BaseBuilder<?>`
`head(String urlTemplate, Object... uriVars)`
HTTP HEAD variant.
`protected org.springframework.util.MultiValueMap<String,org.springframework.http.HttpCookie>`
`initCookies()`
`protected org.springframework.http.server.reactive.SslInfo`
`initSslInfo()`
`static MockServerHttpRequest.BodyBuilder`
`method(String httpMethod, String uri, Object... vars)`
Deprecated.
as of Spring Framework 6.0 in favor of `method(HttpMethod, String, Object...)`
`static MockServerHttpRequest.BodyBuilder`
`method(org.springframework.http.HttpMethod method, String uri, Object... vars)`
Alternative to `method(HttpMethod, URI)` that accepts a URI template.
`static MockServerHttpRequest.BodyBuilder`
`method(org.springframework.http.HttpMethod method, URI url)`
Create a builder with the given HTTP method and a `URI`.
`static MockServerHttpRequest.BaseBuilder<?>`
`options(String urlTemplate, Object... uriVars)`
HTTP OPTIONS variant.
`static MockServerHttpRequest.BodyBuilder`
`patch(String urlTemplate, Object... uriVars)`
HTTP PATCH variant.
`static MockServerHttpRequest.BodyBuilder`
`post(String urlTemplate, Object... uriVars)`
HTTP POST variant.
`static MockServerHttpRequest.BodyBuilder`
`put(String urlTemplate, Object... uriVars)`
HTTP PUT variant.

### Methods inherited from class org.springframework.http.server.reactive.AbstractServerHttpRequest

`getAttributes, getCookies, getHeaders, getId, getMethod, getPath, getQueryParams, getSslInfo, getURI, initId, initLogPrefix, initQueryParams, setAttributesSupplier`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.http.server.reactive.ServerHttpRequest

`mutate`

## Method Details

### getLocalAddress

@Nullable public InetSocketAddress getLocalAddress()

### getRemoteAddress

@Nullable public InetSocketAddress getRemoteAddress()

### initSslInfo

@Nullable protected org.springframework.http.server.reactive.SslInfo initSslInfo()

Specified by:
  `initSslInfo` in class `org.springframework.http.server.reactive.AbstractServerHttpRequest`

### getBody

public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> getBody()

### initCookies

protected org.springframework.util.MultiValueMap<String,org.springframework.http.HttpCookie> initCookies()

Specified by:
  `initCookies` in class `org.springframework.http.server.reactive.AbstractServerHttpRequest`

### getNativeRequest

public <T> T getNativeRequest()

Specified by:
  `getNativeRequest` in class `org.springframework.http.server.reactive.AbstractServerHttpRequest`

### get

public static MockServerHttpRequest.BaseBuilder<?> get(String urlTemplate, 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 via `queryParam` builder methods.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `uriVars` - zero or more URI variables
Returns:
  the created builder

### head

public static MockServerHttpRequest.BaseBuilder<?> head(String urlTemplate, Object... uriVars)
HTTP HEAD variant. See `get(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

### post

public static MockServerHttpRequest.BodyBuilder post(String urlTemplate, Object... uriVars)
HTTP POST variant. See `get(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

### put

public static MockServerHttpRequest.BodyBuilder put(String urlTemplate, Object... uriVars)
HTTP PUT variant. See `get(String, Object...)` for general info. `queryParam` builder methods.

Parameters:
  `urlTemplate` - a URL template; the resulting URL will be encoded
  `uriVars` - zero or more URI variables
Returns:
  the created builder

### patch

public static MockServerHttpRequest.BodyBuilder patch(String urlTemplate, Object... uriVars)
HTTP PATCH variant. See `get(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

### delete

public static MockServerHttpRequest.BaseBuilder<?> delete(String urlTemplate, Object... uriVars)
HTTP DELETE variant. See `get(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

### options

public static MockServerHttpRequest.BaseBuilder<?> options(String urlTemplate, Object... uriVars)
HTTP OPTIONS variant. See `get(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

### method

public static MockServerHttpRequest.BodyBuilder method(org.springframework.http.HttpMethod method, URI url)
Create a builder with the given HTTP method and a `URI`.

Parameters:
  `method` - the HTTP method (GET, POST, etc)
  `url` - the URL
Returns:
  the created builder

### method

public static MockServerHttpRequest.BodyBuilder method(org.springframework.http.HttpMethod method, String uri, Object... vars)
Alternative to `method(HttpMethod, URI)` that accepts a URI template. The given URI may contain query parameters, or those may be added later via `queryParam` builder 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

### method

@Deprecated(since="6.0") public static MockServerHttpRequest.BodyBuilder method(String httpMethod, String uri, Object... vars)
Deprecated.
as of Spring Framework 6.0 in favor of `method(HttpMethod, String, Object...)`
Create a builder with a raw HTTP method value that is outside the range of `HttpMethod` enum values.

Parameters:
  `httpMethod` - the HTTP methodValue value
  `uri` - the URI template for target the URL
  `vars` - variables to expand into the template
Returns:
  the created builder
Since:
  5.2.7