use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingOptionalParamList.
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamList() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, List.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(Optional.empty());
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingRequestParamEmptyValueConvertedToNull.
// SPR-10578
@Test
public void missingRequestParamEmptyValueConvertedToNull() throws Exception {
WebDataBinder binder = new WebRequestDataBinder(null);
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);
request.addParameter("stringNotAnnot", "");
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(arg).isNull();
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveOptionalMultipartFile.
@Test
public void resolveOptionalMultipartFile() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
boolean condition = result instanceof Optional;
assertThat(condition).isTrue();
assertThat(((Optional<?>) result).get()).as("Invalid result").isEqualTo(expected);
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveOptionalParamValue.
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamValue() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(Optional.empty());
request.addParameter("name", "123");
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).get()).isEqualTo(123);
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingOptionalParamArray.
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamArray() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer[].class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(Optional.empty());
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
}
Aggregations