MockMvcController { @RequestMapping(value = "/upload", method = RequestMethod.POST) String upload(@RequestPart(value = "role") Role role, @RequestParam(value = "file", required = true) List<MultipartFile> files) { logger.info("role: {};", role.toString()); files.stream().forEach(file -> { try { logger.info("filename: {}; originalFilename: {}; content: {}" , file.getName() , file.getOriginalFilename() , IOUtils.toString(file.getInputStream())); } catch (IOException e) { e.printStackTrace(); } }); return SUCCESS; }    }
@Test public void testUpload() throws Exception{ MockMultipartFile jsonFile = new MockMultipartFile("role", "", "application/json","{\"id\":2,\"name\":\"ROLE_USER\"}".getBytes()); MockMultipartFile file1 = new MockMultipartFile("file", "filename.txt", "text/plain", "content in file1".getBytes()); MockMultipartFile file2 = new MockMultipartFile("file", "other-file.data", "text/plain", "content in file2".getBytes()); mockMvc.perform(fileUpload("/mock/upload") .file(jsonFile) .file(file1).file(file2)) .andExpect(status().is(200)) .andExpect(content().string("success")); }