use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testMultipartFileAsString.
@Test
public void testMultipartFileAsString() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("name", "Juergen".getBytes()));
binder.bind(new ServletWebRequest(request));
assertEquals("Juergen", target.getName());
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method isMultipartRequestHttpPut.
// SPR-9079
@Test
public void isMultipartRequestHttpPut() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes());
request.addFile(expected);
request.setMethod("PUT");
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(actual instanceof List);
assertEquals(expected, ((List<?>) actual).get(0));
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileArray.
@Test
public void resolveMultipartFileArray() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected1 = new MockMultipartFile("mfilearray", "Hello World 1".getBytes());
MultipartFile expected2 = new MockMultipartFile("mfilearray", "Hello World 2".getBytes());
request.addFile(expected1);
request.addFile(expected2);
request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
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[]);
MultipartFile[] parts = (MultipartFile[]) result;
assertEquals(2, parts.length);
assertEquals(parts[0], expected1);
assertEquals(parts[1], expected2);
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileListNotannot.
@Test
public void resolveMultipartFileListNotannot() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected1 = new MockMultipartFile("multipartFileList", "Hello World 1".getBytes());
MultipartFile expected2 = new MockMultipartFile("multipartFileList", "Hello World 2".getBytes());
request.addFile(expected1);
request.addFile(expected2);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof List);
assertEquals(Arrays.asList(expected1, expected2), result);
}
use of org.springframework.mock.web.test.MockMultipartFile in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveMultipartFileList.
@Test
public void resolveMultipartFileList() throws Exception {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes());
MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes());
request.addFile(expected1);
request.addFile(expected2);
request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, null);
assertTrue(result instanceof List);
assertEquals(Arrays.asList(expected1, expected2), result);
}
Aggregations