共用方式為


MockHttpResponse Class

public class MockHttpResponse
extends HttpResponse

An HTTP response that is created to simulate a HTTP request.

Constructor Summary

Constructor Description
MockHttpResponse(HttpRequest request, int statusCode)

Creates a HTTP response associated with a request, returns the statusCode, and has an empty response body.

MockHttpResponse(HttpRequest request, int statusCode, byte[] bodyBytes)

Creates an HTTP response associated with a request, returns the statusCode, and response body of bodyBytes.

MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers)

Creates an HTTP response associated with a request, returns the statusCode, and http headers.

MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers, byte[] bodyBytes)

Creates an HTTP response associated with a request, returns the statusCode, contains the headers, and response body of bodyBytes.

MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers, Object serializable)

Creates an HTTP response associated with a request, returns the statusCode, contains the given headers, and response body that is JSON serialized from serializable.

MockHttpResponse(HttpRequest request, int statusCode, Object serializable)

Creates an HTTP response associated with a request, returns the statusCode, and response body that is JSON serialized from serializable.

Method Summary

Modifier and Type Method and Description
MockHttpResponse addHeader(String name, String value)

Deprecated

Don't use this method.

Adds the header name and value to the existing set of HTTP headers.

HttpResponse buffer()
Flux<ByteBuffer> getBody()
Mono<byte[]> getBodyAsByteArray()
Mono<String> getBodyAsString()
Mono<String> getBodyAsString(Charset charset)
String getHeaderValue(HttpHeaderName headerName)
String getHeaderValue(String name)
HttpHeaders getHeaders()
int getStatusCode()

Methods inherited from HttpResponse

Methods inherited from java.lang.Object

Constructor Details

MockHttpResponse

public MockHttpResponse(HttpRequest request, int statusCode)

Creates a HTTP response associated with a request, returns the statusCode, and has an empty response body.

Parameters:

request - HttpRequest associated with the response.
statusCode - Status code of the response.

MockHttpResponse

public MockHttpResponse(HttpRequest request, int statusCode, byte[] bodyBytes)

Creates an HTTP response associated with a request, returns the statusCode, and response body of bodyBytes.

Parameters:

request - HttpRequest associated with the response.
statusCode - Status code of the response.
bodyBytes - Contents of the response.

MockHttpResponse

public MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers)

Creates an HTTP response associated with a request, returns the statusCode, and http headers.

Parameters:

request - HttpRequest associated with the response.
statusCode - Status code of the response.
headers - Headers of the response.

MockHttpResponse

public MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers, byte[] bodyBytes)

Creates an HTTP response associated with a request, returns the statusCode, contains the headers, and response body of bodyBytes.

Parameters:

request - HttpRequest associated with the response.
statusCode - Status code of the response.
headers - HttpHeaders of the response.
bodyBytes - Contents of the response.

MockHttpResponse

public MockHttpResponse(HttpRequest request, int statusCode, HttpHeaders headers, Object serializable)

Creates an HTTP response associated with a request, returns the statusCode, contains the given headers, and response body that is JSON serialized from serializable.

Parameters:

request - HttpRequest associated with the response.
statusCode - Status code of the response.
headers - HttpHeaders of the response.
serializable - Contents to be serialized into JSON for the response.

MockHttpResponse

public MockHttpResponse(HttpRequest request, int statusCode, Object serializable)

Creates an HTTP response associated with a request, returns the statusCode, and response body that is JSON serialized from serializable.

Parameters:

request - HttpRequest associated with the response.
statusCode - Status code of the response.
serializable - Contents to be serialized into JSON for the response.

Method Details

addHeader

@Deprecated
public MockHttpResponse addHeader(String name, String value)

Deprecated

Don't use this method.

Adds the header name and value to the existing set of HTTP headers.

Parameters:

name - The header to add
value - The header value.

Returns:

The updated response object.

buffer

public HttpResponse buffer()

Overrides:

MockHttpResponse.buffer()

getBody

public Flux getBody()

Overrides:

MockHttpResponse.getBody()

getBodyAsByteArray

public Mono getBodyAsByteArray()

Overrides:

MockHttpResponse.getBodyAsByteArray()

getBodyAsString

public Mono getBodyAsString()

Overrides:

MockHttpResponse.getBodyAsString()

getBodyAsString

public Mono getBodyAsString(Charset charset)

Overrides:

MockHttpResponse.getBodyAsString(Charset charset)

Parameters:

charset

getHeaderValue

public String getHeaderValue(HttpHeaderName headerName)

Overrides:

MockHttpResponse.getHeaderValue(HttpHeaderName headerName)

Parameters:

headerName

getHeaderValue

@Deprecated
public String getHeaderValue(String name)

Overrides:

MockHttpResponse.getHeaderValue(String name)

Parameters:

name

getHeaders

public HttpHeaders getHeaders()

Overrides:

MockHttpResponse.getHeaders()

getStatusCode

public int getStatusCode()

Overrides:

MockHttpResponse.getStatusCode()

Applies to