use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method resolverThrowsException.
@Test
public void resolverThrowsException() throws Exception {
Mono<Object> resolvedValue = Mono.error(new UnsupportedMediaTypeStatusException("boo"));
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
try {
mono.block();
fail("Expected UnsupportedMediaTypeStatusException");
} catch (UnsupportedMediaTypeStatusException ex) {
assertThat(ex.getMessage(), is("Request failure [status: 415, reason: \"boo\"]"));
}
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method noMatchingResolver.
@Test
public void noMatchingResolver() throws Exception {
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method);
try {
mono.block();
fail("Expected IllegalStateException");
} catch (IllegalStateException ex) {
assertThat(ex.getMessage(), is("No suitable resolver for argument 0 of type 'java.lang.String' " + "on " + method.toGenericString()));
}
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method invokeMethodWithNoValue.
@Test
public void invokeMethodWithNoValue() throws Exception {
Mono<Object> resolvedValue = Mono.empty();
Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
assertHandlerResultValue(mono, "success:null");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method testHandle.
private ServerWebExchange testHandle(String path, MethodParameter returnType, Object returnValue, String responseBody, ViewResolver... resolvers) throws URISyntaxException {
Model model = this.bindingContext.getModel();
model.asMap().clear();
model.addAttribute("id", "123");
HandlerResult result = new HandlerResult(new Object(), returnValue, returnType, this.bindingContext);
MockServerWebExchange exchange = get(path).toExchange();
resultHandler(resolvers).handleResult(exchange, result).block(Duration.ofSeconds(5));
assertResponseBody(exchange, responseBody);
return exchange;
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method contentNegotiation.
@Test
public void contentNegotiation() throws Exception {
TestBean value = new TestBean("Joe");
MethodParameter returnType = on(TestController.class).resolveReturnType(TestBean.class);
HandlerResult handlerResult = new HandlerResult(new Object(), value, returnType, this.bindingContext);
MockServerWebExchange exchange = get("/account").accept(APPLICATION_JSON).toExchange();
TestView defaultView = new TestView("jsonView", APPLICATION_JSON);
resultHandler(Collections.singletonList(defaultView), new TestViewResolver("account")).handleResult(exchange, handlerResult).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON, exchange.getResponse().getHeaders().getContentType());
assertResponseBody(exchange, "jsonView: {" + "org.springframework.validation.BindingResult.testBean=" + "org.springframework.validation.BeanPropertyBindingResult: 0 errors, " + "testBean=TestBean[name=Joe]" + "}");
}
Aggregations