Search in sources :

Example 16 with BindingContext

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

the class InitBinderBindingContextTests method returnValueNotExpected.

@Test(expected = IllegalStateException.class)
public void returnValueNotExpected() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinderReturnValue", WebDataBinder.class);
    context.createDataBinder(exchange, null, "invalidName");
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.Test)

Example 17 with BindingContext

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

the class InitBinderBindingContextTests method createBinder.

@Test
public void createBinder() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinder", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, null);
    assertNotNull(dataBinder.getDisallowedFields());
    assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
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 18 with BindingContext

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

the class InitBinderBindingContextTests method createBinderWithAttrName.

@Test
public void createBinderWithAttrName() throws Exception {
    ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    BindingContext context = createBindingContext("initBinderWithAttributeName", WebDataBinder.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
    assertNotNull(dataBinder.getDisallowedFields());
    assertEquals("id", dataBinder.getDisallowedFields()[0]);
}
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 19 with BindingContext

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

the class RequestBodyArgumentResolverTests method resolveValue.

@SuppressWarnings("unchecked")
private <T> T resolveValue(MethodParameter param, String body) {
    ServerWebExchange exchange = MockServerHttpRequest.post("/path").body(body).toExchange();
    Mono<Object> result = this.resolver.readBody(param, true, new BindingContext(), exchange);
    Object value = result.block(Duration.ofSeconds(5));
    assertNotNull(value);
    assertTrue("Unexpected return value 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 20 with BindingContext

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

the class RequestHeaderMethodArgumentResolverTests method setup.

@Before
public void setup() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.refresh();
    ReactiveAdapterRegistry adapterRegistry = new ReactiveAdapterRegistry();
    this.resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory(), adapterRegistry);
    ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
    initializer.setConversionService(new DefaultFormattingConversionService());
    this.bindingContext = new BindingContext(initializer);
    Method method = ReflectionUtils.findMethod(getClass(), "params", (Class<?>[]) null);
    this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
    this.paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
    this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
    this.paramResolvedNameWithExpression = new SynthesizingMethodParameter(method, 3);
    this.paramResolvedNameWithPlaceholder = new SynthesizingMethodParameter(method, 4);
    this.paramNamedValueMap = new SynthesizingMethodParameter(method, 5);
    this.paramDate = new SynthesizingMethodParameter(method, 6);
    this.paramInstant = new SynthesizingMethodParameter(method, 7);
    this.paramMono = new SynthesizingMethodParameter(method, 8);
}
Also used : SynthesizingMethodParameter(org.springframework.core.annotation.SynthesizingMethodParameter) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Method(java.lang.reflect.Method) BindingContext(org.springframework.web.reactive.BindingContext) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) Before(org.junit.Before)

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