use of org.reactivestreams.Publisher in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method unknownReturnType.
@Test
public void unknownReturnType() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/unknown-return-type").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> {
assertThat(error, instanceOf(IllegalStateException.class));
assertThat(error.getMessage(), startsWith("No HandlerResultHandler"));
}).verify();
}
use of org.reactivestreams.Publisher in project spring-framework by spring-projects.
the class DefaultEntityResponseBuilderTests method bodyInserter.
@Test
public void bodyInserter() throws Exception {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
BiFunction<ServerHttpResponse, BodyInserter.Context, Mono<Void>> writer = (response, strategies) -> {
byte[] bodyBytes = body.getBytes(UTF_8);
ByteBuffer byteBuffer = ByteBuffer.wrap(bodyBytes);
DataBuffer buffer = new DefaultDataBufferFactory().wrap(byteBuffer);
return response.writeWith(Mono.just(buffer));
};
Mono<EntityResponse<Publisher<String>>> result = EntityResponse.fromPublisher(publisher, String.class).build();
MockServerWebExchange exchange = MockServerHttpRequest.get("http://localhost").toExchange();
HandlerStrategies strategies = HandlerStrategies.empty().messageWriter(new EncoderHttpMessageWriter<>(new CharSequenceEncoder())).build();
StepVerifier.create(result).consumeNextWith(response -> {
StepVerifier.create(response.entity()).expectNext(body).expectComplete().verify();
response.writeTo(exchange, strategies);
}).expectComplete().verify();
assertNotNull(exchange.getResponse().getBody());
}
use of org.reactivestreams.Publisher in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method responseBodyMessageConversionError.
@Test
public void responseBodyMessageConversionError() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> assertThat(error, instanceOf(NotAcceptableStatusException.class))).verify();
}
use of org.reactivestreams.Publisher in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method noHandler.
@Test
public void noHandler() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/does-not-exist").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> {
assertThat(error, instanceOf(ResponseStatusException.class));
assertThat(error.getMessage(), is("Request failure [status: 404, reason: \"No matching handler\"]"));
}).verify();
}
use of org.reactivestreams.Publisher in project spring-framework by spring-projects.
the class DispatcherHandlerErrorTests method controllerReturnsMonoError.
@Test
public void controllerReturnsMonoError() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/error-signal").toExchange();
Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
StepVerifier.create(publisher).consumeErrorWith(error -> assertSame(EXCEPTION, error)).verify();
}
Aggregations