Class MockServerHttpResponse
java.lang.Object
org.springframework.http.server.reactive.AbstractServerHttpResponse
org.springframework.mock.http.server.reactive.MockServerHttpResponse
- All Implemented Interfaces:
org.springframework.http.HttpMessage,org.springframework.http.ReactiveHttpOutputMessage,org.springframework.http.server.reactive.ServerHttpResponse
public class MockServerHttpResponse
extends org.springframework.http.server.reactive.AbstractServerHttpResponse
Mock extension of
AbstractServerHttpResponse for use in tests without
an actual server.
By default response content is consumed in full upon writing and cached
for subsequent access, however it is also possible to set a custom
writeHandler.
- Since:
- 5.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
ConstructorsConstructorDescriptionMockServerHttpResponse(org.springframework.core.io.buffer.DataBufferFactory dataBufferFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidprotected voidreactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>getBody()Return the response body or an error stream if the body was not set.reactor.core.publisher.Mono<String>Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.<T> Treactor.core.publisher.Mono<Void>voidsetWriteHandler(Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<Void>> writeHandler) Configure a custom handler to consume the response body.protected reactor.core.publisher.Mono<Void>writeAndFlushWithInternal(Publisher<? extends Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body) protected reactor.core.publisher.Mono<Void>writeWithInternal(Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body) Methods inherited from class org.springframework.http.server.reactive.AbstractServerHttpResponse
addCookie, beforeCommit, bufferFactory, doCommit, doCommit, getCookies, getHeaders, getStatusCode, isCommitted, setRawStatusCode, setStatusCode, touchDataBuffer, writeAndFlushWith, writeWithMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.http.server.reactive.ServerHttpResponse
getRawStatusCode
-
Constructor Details
-
MockServerHttpResponse
public MockServerHttpResponse() -
MockServerHttpResponse
public MockServerHttpResponse(org.springframework.core.io.buffer.DataBufferFactory dataBufferFactory)
-
-
Method Details
-
setWriteHandler
public void setWriteHandler(Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<Void>> writeHandler) Configure a custom handler to consume the response body.By default, response body content is consumed in full and cached for subsequent access in tests. Use this option to take control over how the response body is consumed.
- Parameters:
writeHandler- the write handler to use returningMono<Void>when the body has been "written" (i.e. consumed).
-
getNativeResponse
public <T> T getNativeResponse()- Specified by:
getNativeResponsein classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
applyStatusCode
protected void applyStatusCode()- Specified by:
applyStatusCodein classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
applyHeaders
protected void applyHeaders()- Specified by:
applyHeadersin classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
applyCookies
protected void applyCookies()- Specified by:
applyCookiesin classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
writeWithInternal
protected reactor.core.publisher.Mono<Void> writeWithInternal(Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body) - Specified by:
writeWithInternalin classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
writeAndFlushWithInternal
protected reactor.core.publisher.Mono<Void> writeAndFlushWithInternal(Publisher<? extends Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body) - Specified by:
writeAndFlushWithInternalin classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
setComplete
- Specified by:
setCompletein interfaceorg.springframework.http.ReactiveHttpOutputMessage- Overrides:
setCompletein classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
getBody
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> getBody()Return the response body or an error stream if the body was not set. -
getBodyAsString
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.
-