MvcRequester.on(mockMvc)
.to("/api/reports/complaints/full")
.get()
.doExpect(status().isOk())
.returnAs(MultipartFile.class); //drop here, tried to use File, InputStream, FileInputStream
I this is the part of the test that makes sending the request to the endpoint. An excel file comes from this endpoint. Please tell me how to write the response into a variable.
here is response body and exception.
I use custom library for inject file into response. It's work correct 100%.
下面是将文件添加到响应中的控制器方法的结尾
@GetMapping("/complaints/full")
@ResponseBody
public void getComplaintsFullReport(SearchComplaintDto dto,
HttpServletResponse servletResponse) {
SearchComplaintArgument argument = complaintMapper.toSearchArgument(dto);
File file = buildComplaintsReportAction.execute(argument);
FileResponse.builder()
.file(file)
.filename("Report_"
.concat(LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy_HH.mm")))
.concat(".xlsx"))
.mimeType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
.response(servletResponse)
.build();
}
回答"如何将响应写入变量?"的问题.