use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method invokeMethodWithNoArguments.
@Test
public void invokeMethodWithNoArguments() throws Exception {
Method method = on(TestController.class).mockCall(TestController::noArgs).method();
Mono<HandlerResult> mono = invoke(new TestController(), method);
assertHandlerResultValue(mono, "success");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class InvocableHandlerMethodTests method invokeMethodWithResponseStatus.
@Test
public void invokeMethodWithResponseStatus() throws Exception {
Method method = on(TestController.class).annotPresent(ResponseStatus.class).resolveMethod();
Mono<HandlerResult> mono = invoke(new TestController(), method);
assertHandlerResultValue(mono, "created");
assertThat(this.exchange.getResponse().getStatusCode(), is(HttpStatus.CREATED));
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class RequestMappingInfoHandlerMappingTests method testHttpOptions.
private void testHttpOptions(String requestURI, String allowHeader) throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.options(requestURI).toExchange();
HandlerMethod handlerMethod = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
BindingContext bindingContext = new BindingContext();
InvocableHandlerMethod invocable = new InvocableHandlerMethod(handlerMethod);
Mono<HandlerResult> mono = invocable.invoke(exchange, bindingContext);
HandlerResult result = mono.block();
assertNotNull(result);
Optional<Object> value = result.getReturnValue();
assertTrue(value.isPresent());
assertEquals(HttpHeaders.class, value.get().getClass());
assertEquals(allowHeader, ((HttpHeaders) value.get()).getFirst("Allow"));
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method modelWithAsyncAttributes.
@Test
public void modelWithAsyncAttributes() throws Exception {
this.bindingContext.getModel().addAttribute("attr1", Mono.just(new TestBean("Bean1"))).addAttribute("attr2", Flux.just(new TestBean("Bean1"), new TestBean("Bean2"))).addAttribute("attr3", Single.just(new TestBean("Bean2"))).addAttribute("attr4", Observable.just(new TestBean("Bean1"), new TestBean("Bean2"))).addAttribute("attr5", Mono.empty());
MethodParameter returnType = on(TestController.class).resolveReturnType(void.class);
HandlerResult result = new HandlerResult(new Object(), null, 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: {" + "attr1=TestBean[name=Bean1], " + "attr2=[TestBean[name=Bean1], TestBean[name=Bean2]], " + "attr3=TestBean[name=Bean2], " + "attr4=[TestBean[name=Bean1], TestBean[name=Bean2]], " + "org.springframework.validation.BindingResult.attr1=" + "org.springframework.validation.BeanPropertyBindingResult: 0 errors, " + "org.springframework.validation.BindingResult.attr3=" + "org.springframework.validation.BeanPropertyBindingResult: 0 errors" + "}");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ViewResolutionResultHandlerTests method contentNegotiationWith406.
@Test
public void contentNegotiationWith406() 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();
ViewResolutionResultHandler resultHandler = resultHandler(new TestViewResolver("account"));
Mono<Void> mono = resultHandler.handleResult(exchange, handlerResult);
StepVerifier.create(mono).expectNextCount(0).expectError(NotAcceptableStatusException.class).verify();
}
Aggregations