use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class ByteArrayMultipartFileEditorTests method setValueAsMultipartFileWithBadBytes.
@Test(expected = IllegalArgumentException.class)
public void setValueAsMultipartFileWithBadBytes() throws Exception {
MultipartFile file = mock(MultipartFile.class);
given(file.getBytes()).willThrow(new IOException());
editor.setValue(file);
}
use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileNotAnnot.
@Test
public void resolveMultipartFileNotAnnot() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof MultipartFile);
assertEquals("Invalid result", expected, result);
}
use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFile.
@Test
public void resolveMultipartFile() throws Exception {
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(MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof MultipartFile);
assertEquals("Invalid result", expected, result);
}
use of org.springframework.web.multipart.MultipartFile 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));
}
use of org.springframework.web.multipart.MultipartFile in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequestTests method getBodyWithWrappedRequest.
// SPR-13317
@Test
public void getBodyWithWrappedRequest() throws Exception {
byte[] bytes = "content".getBytes("UTF-8");
MultipartFile part = new MockMultipartFile("part", "", "application/json", bytes);
this.mockRequest.addFile(part);
HttpServletRequest wrapped = new HttpServletRequestWrapper(this.mockRequest);
ServerHttpRequest request = new RequestPartServletServerHttpRequest(wrapped, "part");
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
assertArrayEquals(bytes, result);
}
Aggregations