use of org.springframework.web.testfixture.servlet.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);
boolean condition = result instanceof MultipartFile[];
assertThat(condition).isTrue();
MultipartFile[] parts = (MultipartFile[]) result;
assertThat(parts.length).isEqualTo(2);
assertThat(expected1).isEqualTo(parts[0]);
assertThat(expected2).isEqualTo(parts[1]);
}
use of org.springframework.web.testfixture.servlet.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);
boolean condition = result instanceof List;
assertThat(condition).isTrue();
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
}
use of org.springframework.web.testfixture.servlet.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));
assertThat(target.getName()).isEqualTo("Juergen");
}
use of org.springframework.web.testfixture.servlet.MockMultipartFile in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testMultipartFilesAsStringArray.
@Test
public void testMultipartFilesAsStringArray() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
request.addFile(new MockMultipartFile("stringArray", "Eva".getBytes()));
binder.bind(new ServletWebRequest(request));
assertThat(target.getStringArray().length).isEqualTo(2);
assertThat(target.getStringArray()[0]).isEqualTo("Juergen");
assertThat(target.getStringArray()[1]).isEqualTo("Eva");
}
Aggregations