use of reactor.core.publisher.Mono 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 reactor.core.publisher.Mono 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();
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo.
@Test
public void toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = // Mono.<ServerResponse> is required for compilation in Eclipse
request -> Mono.<ServerResponse>just(new ServerResponse() {
@Override
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@Override
public HttpHeaders headers() {
return new HttpHeaders();
}
@Override
public Mono<Void> writeTo(ServerWebExchange exchange, HandlerStrategies strategies) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found");
}
});
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertNotNull(result);
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("http://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertEquals(HttpStatus.NOT_FOUND, httpResponse.getStatusCode());
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class MessageReaderArgumentResolverTests method emptyBody.
// More extensive "empty body" tests in RequestBody- and HttpEntityArgumentResolverTests
// SPR-9942
@Test
// SPR-9942
@SuppressWarnings("unchecked")
public void emptyBody() throws Exception {
ServerWebExchange exchange = post("/path").contentType(MediaType.APPLICATION_JSON).toExchange();
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
MethodParameter param = this.testMethod.arg(type);
Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody(param, true, this.bindingContext, exchange).block();
StepVerifier.create(result).expectError(ServerWebInputException.class).verify();
}
use of reactor.core.publisher.Mono in project spring-framework by spring-projects.
the class ModelAttributeMethodArgumentResolverTests method testValidationError.
private void testValidationError(MethodParameter param, Function<Mono<?>, Mono<?>> valueMonoExtractor) throws URISyntaxException {
ServerWebExchange exchange = postForm("age=invalid");
Mono<?> mono = createResolver().resolveArgument(param, this.bindContext, exchange);
mono = valueMonoExtractor.apply(mono);
StepVerifier.create(mono).consumeErrorWith(ex -> {
assertTrue(ex instanceof WebExchangeBindException);
WebExchangeBindException bindException = (WebExchangeBindException) ex;
assertEquals(1, bindException.getErrorCount());
assertTrue(bindException.hasFieldErrors("age"));
}).verify();
}
Aggregations