use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingOptionalMultipartFile.
@Test
public void missingOptionalMultipartFile() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
request.setMethod("POST");
request.setContentType("multipart/form-data");
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertEquals(Optional.empty(), actual);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveStringArray.
@Test
public void resolveStringArray() throws Exception {
String[] expected = new String[] { "foo", "bar" };
request.addParameter("name", expected);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof String[]);
assertArrayEquals("Invalid result", expected, (String[]) result);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolvePart.
@Test
public void resolvePart() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
MockPart expected = new MockPart("pfile", "Hello World".getBytes());
request.setMethod("POST");
request.setContentType("multipart/form-data");
request.addPart(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof Part);
assertEquals("Invalid result", expected, result);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveEmptyValueRequiredWithoutDefault.
@Test
public void resolveEmptyValueRequiredWithoutDefault() throws Exception {
this.request.addParameter("name", "");
MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertEquals("", result);
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method supportsParameter.
@Test
public void supportsParameter() {
resolver = new RequestParamMethodArgumentResolver(null, true);
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annot(requestParam().name("name")).arg(Map.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, Part.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annot(requestParam().noName()).arg(Map.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annot(requestPart()).arg(MultipartFile.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annot(requestParam()).arg(String.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class);
assertTrue(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
assertTrue(resolver.supportsParameter(param));
resolver = new RequestParamMethodArgumentResolver(null, false);
param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
assertFalse(resolver.supportsParameter(param));
param = this.testMethod.annotPresent(RequestPart.class).arg(MultipartFile.class);
assertFalse(resolver.supportsParameter(param));
}
Aggregations