I have controller, which handles multiple file upload:
@PostMapping("/import")
public void import(@RequestParam("files") MultipartFile[] files, HttpServletRequest request) {
assertUploadFilesNotEmpty(files);
...
}
And I want to test it
@Test
public void importTest() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "list.xlsx", MIME_TYPE_EXCEL, Files.readAllBytes(Paths.get(excelFile.getURI())));
mvc.perform(fileUpload("/import").file(file).contentType(MIME_TYPE_EXCEL)).andExpect(status().isOk());
}
Problem is that MockMvc, creates MockHttpRequest with multipartFiles as a name for param that holds uploaded files. And my controller expects those files will be in 'files' param.
Is it possible to tell spring that multiple files should be passed in request under given name?