use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method unresolvedViewName.
@Test
public void unresolvedViewName() throws Exception {
String returnValue = "account";
MethodParameter returnType = on(TestController.class).resolveReturnType(String.class);
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
MockServerWebExchange exchange = get("/path").toExchange();
Mono<Void> mono = resultHandler().handleResult(exchange, result);
StepVerifier.create(mono).expectNextCount(0).expectErrorMessage("Could not resolve view with name 'account'.").verify();
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method testDefaultViewName.
private void testDefaultViewName(Object returnValue, MethodParameter returnType) throws URISyntaxException {
this.bindingContext.getModel().addAttribute("id", "123");
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
ViewResolutionResultHandler handler = resultHandler(new TestViewResolver("account"));
MockServerWebExchange exchange = get("/account").toExchange();
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {id=123}");
exchange = get("/account/").toExchange();
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {id=123}");
exchange = get("/account.123").toExchange();
handler.handleResult(exchange, result).block(Duration.ofMillis(5000));
assertResponseBody(exchange, "account: {id=123}");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseBodyResultHandlerTests method testSupports.
private void testSupports(Object controller, Method method) {
HandlerResult handlerResult = getHandlerResult(controller, method);
assertTrue(this.resultHandler.supports(handlerResult));
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method handleMonoWithWildcardBodyType.
// SPR-14877
@Test
public void handleMonoWithWildcardBodyType() throws Exception {
MockServerWebExchange exchange = get("/path").toExchange();
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, ResponseEntity.class);
HandlerResult result = new HandlerResult(new TestController(), Mono.just(ok().body("body")), type);
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.OK, exchange.getResponse().getStatusCode());
assertResponseBody(exchange, "\"body\"");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method testHandle.
private void testHandle(Object returnValue, MethodParameter returnType) {
MockServerWebExchange exchange = get("/path").toExchange();
HandlerResult result = handlerResult(returnValue, returnType);
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.OK, exchange.getResponse().getStatusCode());
assertEquals("text/plain;charset=UTF-8", exchange.getResponse().getHeaders().getFirst("Content-Type"));
assertResponseBody(exchange, "abc");
}
Aggregations