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
ConstructorDescriptionMockServerHttpResponse
(org.springframework.core.io.buffer.DataBufferFactory dataBufferFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
protected void
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.reactor.core.publisher.Mono<String>
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.<T> T
reactor.core.publisher.Mono<Void>
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.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, getRawStatusCode, getStatusCode, isCommitted, setRawStatusCode, setStatusCode, touchDataBuffer, writeAndFlushWith, writeWith
-
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:
getNativeResponse
in classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
applyStatusCode
protected void applyStatusCode()- Specified by:
applyStatusCode
in classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
applyHeaders
protected void applyHeaders()- Specified by:
applyHeaders
in classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
applyCookies
protected void applyCookies()- Specified by:
applyCookies
in 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:
writeWithInternal
in 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:
writeAndFlushWithInternal
in classorg.springframework.http.server.reactive.AbstractServerHttpResponse
-
setComplete
- Specified by:
setComplete
in interfaceorg.springframework.http.ReactiveHttpOutputMessage
- Overrides:
setComplete
in 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.
-