use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method handleResponseEntityWithNullBody.
@Test
public void handleResponseEntityWithNullBody() {
Object returnValue = Mono.just(notFound().build());
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, entity(String.class));
HandlerResult result = handlerResult(returnValue, type);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertResponseBodyIsEmpty(exchange);
}
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 = MockServerWebExchange.from(get("/path"));
HandlerResult result = handlerResult(returnValue, returnType);
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(exchange.getResponse().getHeaders().getFirst("Content-Type")).isEqualTo("text/plain;charset=UTF-8");
assertResponseBody(exchange, "abc");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method contentNegotiationWithRedirect.
// SPR-15291
@Test
public void contentNegotiationWithRedirect() {
HandlerResult handlerResult = new HandlerResult(new Object(), "redirect:/", on(Handler.class).annotNotPresent(ModelAttribute.class).resolveReturnType(String.class), this.bindingContext);
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setApplicationContext(new StaticApplicationContext());
ViewResolutionResultHandler resultHandler = resultHandler(viewResolver);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON));
resultHandler.handleResult(exchange, handlerResult).block(Duration.ZERO);
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getStatusCode().value()).isEqualTo(303);
assertThat(response.getHeaders().getLocation().toString()).isEqualTo("/");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method contentNegotiation.
@Test
public void contentNegotiation() {
TestBean value = new TestBean("Joe");
MethodParameter returnType = on(Handler.class).resolveReturnType(TestBean.class);
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/account").accept(APPLICATION_JSON));
TestView defaultView = new TestView("jsonView", APPLICATION_JSON);
resultHandler(Collections.singletonList(defaultView), new TestViewResolver("account")).handleResult(exchange, handlerResult).block(Duration.ofSeconds(5));
assertThat(exchange.getResponse().getHeaders().getContentType()).isEqualTo(APPLICATION_JSON);
assertResponseBody(exchange, "jsonView: {" + "org.springframework.validation.BindingResult.testBean=" + "org.springframework.validation.BeanPropertyBindingResult: 0 errors, " + "testBean=TestBean[name=Joe]" + "}");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method unresolvedViewName.
@Test
public void unresolvedViewName() {
String returnValue = "account";
MethodParameter returnType = on(Handler.class).annotPresent(ModelAttribute.class).resolveReturnType(String.class);
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
Mono<Void> mono = resultHandler().handleResult(exchange, result);
StepVerifier.create(mono).expectNextCount(0).expectErrorMessage("Could not resolve view with name 'path'.").verify();
}
Aggregations