Class MockClientHttpRequest
java.lang.Object
org.springframework.http.client.reactive.AbstractClientHttpRequest
org.springframework.mock.http.client.reactive.MockClientHttpRequest
- All Implemented Interfaces:
- ClientHttpRequest,- HttpMessage,- ReactiveHttpOutputMessage
Mock implementation of 
ClientHttpRequest.- Since:
- 5.0
- Author:
- Brian Clozel, Rossen Stoyanchev
- 
Constructor SummaryConstructorsConstructorDescriptionMockClientHttpRequest(HttpMethod httpMethod, String urlTemplate, Object... vars) MockClientHttpRequest(HttpMethod httpMethod, URI url) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidAdd attributes fromAbstractClientHttpRequest.getAttributes()to the underlying request.protected voidAdd cookies fromAbstractClientHttpRequest.getHeaders()to the underlying request.protected voidApply header changes fromAbstractClientHttpRequest.getHeaders()to the underlying request.Return aDataBufferFactorythat 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>Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.Return the HTTP method of the request.<T> TReturn the request from the underlying HTTP library.getURI()Return the URI of the request.reactor.core.publisher.Mono<Void>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).voidsetWriteHandler(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(Publisher<? extends Publisher<? extends DataBuffer>> body) Use the givenPublisherofPublishersto write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>.reactor.core.publisher.Mono<Void>writeWith(Publisher<? extends DataBuffer> body) Use the givenPublisherto write the body of the message to the underlying HTTP layer.Methods inherited from class org.springframework.http.client.reactive.AbstractClientHttpRequestbeforeCommit, doCommit, doCommit, getAttributes, getCookies, getHeaders, initReadOnlyHeaders, isCommitted
- 
Constructor Details- 
MockClientHttpRequest
- 
MockClientHttpRequest
 
- 
- 
Method Details- 
setWriteHandlerpublic 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, for example, in test assertions. Use this property when the request body is an infinite stream. - Parameters:
- writeHandler- the write handler to use returning- Mono<Void>when the body has been "written" (i.e. consumed).
 
- 
getMethodDescription copied from interface:ClientHttpRequestReturn the HTTP method of the request.
- 
getURIDescription copied from interface:ClientHttpRequestReturn the URI of the request.
- 
bufferFactoryDescription copied from interface:ReactiveHttpOutputMessageReturn aDataBufferFactorythat can be used to create the body.- Returns:
- a buffer factory
- See Also:
 
- 
getNativeRequestpublic <T> T getNativeRequest()Description copied from interface:ClientHttpRequestReturn the request from the underlying HTTP library.- Type Parameters:
- T- the expected type of the request to cast to
 
- 
applyHeadersprotected void applyHeaders()Description copied from class:AbstractClientHttpRequestApply header changes fromAbstractClientHttpRequest.getHeaders()to the underlying request. This method is called once only.- Specified by:
- applyHeadersin class- AbstractClientHttpRequest
 
- 
applyCookiesprotected void applyCookies()Description copied from class:AbstractClientHttpRequestAdd cookies fromAbstractClientHttpRequest.getHeaders()to the underlying request. This method is called once only.- Specified by:
- applyCookiesin class- AbstractClientHttpRequest
 
- 
applyAttributesprotected void applyAttributes()Description copied from class:AbstractClientHttpRequestAdd attributes fromAbstractClientHttpRequest.getAttributes()to the underlying request. This method is called once only.- Overrides:
- applyAttributesin class- AbstractClientHttpRequest
 
- 
writeWithDescription copied from interface:ReactiveHttpOutputMessageUse the givenPublisherto write the body of the message to the underlying HTTP layer.- Parameters:
- body- the body content publisher
- Returns:
- a Monothat indicates completion or error
 
- 
writeAndFlushWithpublic reactor.core.publisher.Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) Description copied from interface:ReactiveHttpOutputMessageUse the givenPublisherofPublishersto write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>.- Parameters:
- body- the body content publisher
- Returns:
- a Monothat indicates completion or error
 
- 
setCompleteDescription copied from interface:ReactiveHttpOutputMessageIndicate 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 Monothat indicates completion or error
 
- 
getBodyReturn 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.
- 
getBodyAsStringAggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.
 
-