Class MockClientHttpRequest
- java.lang.Object
- org.springframework.http.client.reactive.AbstractClientHttpRequest
- org.springframework.mock.http.client.reactive.MockClientHttpRequest
- All Implemented Interfaces:
ClientHttpRequest
,HttpMessage
,ReactiveHttpOutputMessage
public class MockClientHttpRequest extends AbstractClientHttpRequest
Mock implementation ofClientHttpRequest
.- Since:
- 5.0
- Author:
- Brian Clozel, Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description MockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars)
MockClientHttpRequest(HttpMethod httpMethod, URI url)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
applyCookies()
Add cookies fromAbstractClientHttpRequest.getHeaders()
to the underlying request.protected void
applyHeaders()
Apply header changes fromAbstractClientHttpRequest.getHeaders()
to the underlying request.DataBufferFactory
bufferFactory()
Return aDataBufferFactory
that can be used to create the body.reactor.core.publisher.Flux<DataBuffer>
getBody()
Return the request body, or an error stream if the body was never set or whensetWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<java.lang.Void>>)
is configured.reactor.core.publisher.Mono<String>
getBodyAsString()
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.HttpMethod
getMethod()
Return the HTTP method of the request.URI
getURI()
Return the URI of the request.reactor.core.publisher.Mono<Void>
setComplete()
Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made viaHttpMessage.getHeaders()
to the underlying HTTP message (if not applied already).void
setWriteHandler(Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)
Configure a custom handler for writing the request body.reactor.core.publisher.Mono<Void>
writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Use the givenPublisher
ofPublishers
to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>
.reactor.core.publisher.Mono<Void>
writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
Use the givenPublisher
to write the body of the message to the underlying HTTP layer.Methods inherited from class org.springframework.http.client.reactive.AbstractClientHttpRequest
beforeCommit, doCommit, doCommit, getCookies, getHeaders, isCommitted
Constructor Detail
MockClientHttpRequest
public MockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars)
MockClientHttpRequest
public MockClientHttpRequest(HttpMethod httpMethod, URI url)
Method Detail
setWriteHandler
public void setWriteHandler(Function<reactor.core.publisher.Flux<DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)
Configure a custom handler for writing the request body.The default write handler consumes and caches the request body so it may be accessed subsequently, e.g. in test assertions. Use this property when the request body is an infinite stream.
- Parameters:
writeHandler
- the write handler to use returningMono<Void>
when the body has been "written" (i.e. consumed).
getMethod
public HttpMethod getMethod()
Description copied from interface:ClientHttpRequest
Return the HTTP method of the request.
getURI
public URI getURI()
Description copied from interface:ClientHttpRequest
Return the URI of the request.
bufferFactory
public DataBufferFactory bufferFactory()
Description copied from interface:ReactiveHttpOutputMessage
Return aDataBufferFactory
that can be used to create the body.- Returns:
- a buffer factory
- See Also:
ReactiveHttpOutputMessage.writeWith(Publisher)
applyHeaders
protected void applyHeaders()
Description copied from class:AbstractClientHttpRequest
Apply header changes fromAbstractClientHttpRequest.getHeaders()
to the underlying request. This method is called once only.- Specified by:
applyHeaders
in classAbstractClientHttpRequest
applyCookies
protected void applyCookies()
Description copied from class:AbstractClientHttpRequest
Add cookies fromAbstractClientHttpRequest.getHeaders()
to the underlying request. This method is called once only.- Specified by:
applyCookies
in classAbstractClientHttpRequest
writeWith
public reactor.core.publisher.Mono<Void> writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
Description copied from interface:ReactiveHttpOutputMessage
Use the givenPublisher
to write the body of the message to the underlying HTTP layer.- Parameters:
body
- the body content publisher- Returns:
- a
Mono
that indicates completion or error
writeAndFlushWith
public reactor.core.publisher.Mono<Void> writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Description copied from interface:ReactiveHttpOutputMessage
Use the givenPublisher
ofPublishers
to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>
.- Parameters:
body
- the body content publisher- Returns:
- a
Mono
that indicates completion or error
setComplete
public reactor.core.publisher.Mono<Void> setComplete()
Description copied from interface:ReactiveHttpOutputMessage
Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made viaHttpMessage.getHeaders()
to the underlying HTTP message (if not applied already).This method should be automatically invoked at the end of message processing so typically applications should not have to invoke it. If invoked multiple times it should have no side effects.
- Returns:
- a
Mono
that indicates completion or error
getBody
public reactor.core.publisher.Flux<DataBuffer> getBody()
Return the request body, or an error stream if the body was never set or whensetWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<java.lang.Void>>)
is configured.
getBodyAsString
public reactor.core.publisher.Mono<String> getBodyAsString()
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.