Search in sources :

Example 26 with BindingContext

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

the class HttpEntityArgumentResolverTests method resolveValue.

@SuppressWarnings("unchecked")
private <T> T resolveValue(ServerWebExchange exchange, ResolvableType type) {
    MethodParameter param = this.testMethod.arg(type);
    Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange);
    Object value = result.block(Duration.ofSeconds(5));
    assertNotNull(value);
    assertTrue("Unexpected return value type: " + value.getClass(), param.getParameterType().isAssignableFrom(value.getClass()));
    return (T) value;
}
Also used : MethodParameter(org.springframework.core.MethodParameter) BindingContext(org.springframework.web.reactive.BindingContext)

Example 27 with BindingContext

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

the class InitBinderBindingContextTests method createBinderWithGlobalInitialization.

@Test
public void createBinderWithGlobalInitialization() throws Exception {
    ConversionService conversionService = new DefaultFormattingConversionService();
    bindingInitializer.setConversionService(conversionService);
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
    assertSame(conversionService, dataBinder.getConversionService());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebDataBinder(org.springframework.web.bind.WebDataBinder) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) ConversionService(org.springframework.core.convert.ConversionService) BindingContext(org.springframework.web.reactive.BindingContext) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Test(org.junit.Test)

Example 28 with BindingContext

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

the class InitBinderBindingContextTests method createBinderTypeConversion.

@Test
public void createBinderTypeConversion() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/path?requestParam=22").toExchange();
    ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
    this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false));
    BindingContext context = createBindingContext("initBinderTypeConversion", WebDataBinder.class, int.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
    assertNotNull(dataBinder.getDisallowedFields());
    assertEquals("requestParam-22", dataBinder.getDisallowedFields()[0]);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebDataBinder(org.springframework.web.bind.WebDataBinder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Example 29 with BindingContext

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

the class InitBinderBindingContextTests method createBinderNullAttrName.

@Test
public void createBinderNullAttrName() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
    assertNull(dataBinder.getDisallowedFields());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebDataBinder(org.springframework.web.bind.WebDataBinder) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Example 30 with BindingContext

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

the class InitBinderBindingContextTests method createBinderWithAttrNameNoMatch.

@Test
public void createBinderWithAttrNameNoMatch() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, "invalidName");
    assertNull(dataBinder.getDisallowedFields());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) WebDataBinder(org.springframework.web.bind.WebDataBinder) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

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