Search in sources :

Example 41 with WebDataBinder

use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.

the class InitBinderBindingContextTests method createBinderTypeConversion.

@Test
public void createBinderTypeConversion() throws Exception {
    MockServerHttpRequest request = MockServerHttpRequest.get("/path?requestParam=22").build();
    MockServerWebExchange exchange = MockServerWebExchange.from(request);
    ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
    this.argumentResolvers.add(new RequestParamMethodArgumentResolver(null, adapterRegistry, false));
    BindingContext context = createBindingContext("initBinderTypeConversion", WebDataBinder.class, int.class);
    WebDataBinder dataBinder = context.createDataBinder(exchange, null, "foo");
    assertThat(dataBinder.getDisallowedFields()).isNotNull();
    assertThat(dataBinder.getDisallowedFields()[0]).isEqualTo("requestParam-22");
}
Also used : WebDataBinder(org.springframework.web.bind.WebDataBinder) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) Test(org.junit.jupiter.api.Test)

Example 42 with WebDataBinder

use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.

the class InitBinderBindingContextTests method createBinderWithAttrNameNoMatch.

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

Example 43 with WebDataBinder

use of org.springframework.web.bind.WebDataBinder in project spring-framework by spring-projects.

the class InitBinderBindingContextTests method createBinderNullAttrName.

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

Aggregations

WebDataBinder (org.springframework.web.bind.WebDataBinder)43 Test (org.junit.jupiter.api.Test)23 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)16 MethodParameter (org.springframework.core.MethodParameter)7 WebRequestDataBinder (org.springframework.web.bind.support.WebRequestDataBinder)6 BindingContext (org.springframework.web.reactive.BindingContext)6 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)6 TestBean (org.springframework.beans.testfixture.beans.TestBean)4 ConversionService (org.springframework.core.convert.ConversionService)4 Nullable (org.springframework.lang.Nullable)4 ServletRequestDataBinder (org.springframework.web.bind.ServletRequestDataBinder)4 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)4 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)3 ArrayList (java.util.ArrayList)2 TypeMismatchException (org.springframework.beans.TypeMismatchException)2 StringTrimmerEditor (org.springframework.beans.propertyeditors.StringTrimmerEditor)2 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)2 BindException (org.springframework.validation.BindException)2