Search in sources :

Example 36 with BindingContext

use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.

the class RequestAttributeMethodArgumentResolverTests method resolve.

@Test
public void resolve() throws Exception {
    MethodParameter param = initMethodParameter(0);
    Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
    StepVerifier.create(mono).expectNextCount(0).expectError(ServerWebInputException.class).verify();
    Foo foo = new Foo();
    this.exchange.getAttributes().put("foo", foo);
    mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange);
    assertSame(foo, mono.block());
}
Also used : ServerWebInputException(org.springframework.web.server.ServerWebInputException) MethodParameter(org.springframework.core.MethodParameter) SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Example 37 with BindingContext

use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.

the class RequestBodyArgumentResolverTests method resolveValueWithEmptyBody.

@SuppressWarnings("unchecked")
private <T> T resolveValueWithEmptyBody(MethodParameter param) {
    ServerWebExchange exchange = MockServerHttpRequest.post("/path").build().toExchange();
    Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
    Object value = result.block(Duration.ofSeconds(5));
    if (value != null) {
        assertTrue("Unexpected parameter type: " + value, param.getParameterType().isAssignableFrom(value.getClass()));
    }
    //no inspection unchecked
    return (T) value;
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext)

Example 38 with BindingContext

use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
    initializer.setValidator(new TestBeanValidator());
    this.bindingContext = new BindingContext(initializer);
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) BindingContext(org.springframework.web.reactive.BindingContext) Before(org.junit.Before)

Example 39 with BindingContext

use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.

the class InvocableHandlerMethodTests method invoke.

private Mono<HandlerResult> invoke(Object handler, Method method, HandlerMethodArgumentResolver... resolver) {
    InvocableHandlerMethod hm = new InvocableHandlerMethod(handler, method);
    hm.setArgumentResolvers(Arrays.asList(resolver));
    return hm.invoke(this.exchange, new BindingContext());
}
Also used : BindingContext(org.springframework.web.reactive.BindingContext)

Example 40 with BindingContext

use of org.springframework.web.reactive.BindingContext in project spring-framework by spring-projects.

the class ServerWebExchangeArgumentResolverTests method testResolveArgument.

private void testResolveArgument(MethodParameter parameter, Object expected) {
    Mono<Object> mono = this.resolver.resolveArgument(parameter, new BindingContext(), this.exchange);
    assertSame(expected, mono.block());
}
Also used : BindingContext(org.springframework.web.reactive.BindingContext)

Aggregations

BindingContext (org.springframework.web.reactive.BindingContext)43 Test (org.junit.Test)26 ServerWebExchange (org.springframework.web.server.ServerWebExchange)16 MethodParameter (org.springframework.core.MethodParameter)14 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)10 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)9 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)8 WebDataBinder (org.springframework.web.bind.WebDataBinder)7 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)6 Mono (reactor.core.publisher.Mono)6 Map (java.util.Map)5 Before (org.junit.Before)5 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 WebExchangeDataBinder (org.springframework.web.bind.support.WebExchangeDataBinder)4 ServerWebInputException (org.springframework.web.server.ServerWebInputException)4 Method (java.lang.reflect.Method)3 List (java.util.List)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 ReactiveAdapter (org.springframework.core.ReactiveAdapter)3