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();
    }

回答"如何将响应写入变量?"的问题.

推荐答案

        byte[] response = MvcRequester.on(mockMvc)
                                  .to("/api/reports/complaints/full")
                                  .get()
                                  .doExpect(status().isOk())
                                  .returnResponse()
                                  .getContentAsByteArray();

将依赖项更改为(在我使用此依赖项之前,它是具有相同约会的自定义依赖项)

   <dependency>
        <groupId>com.jupiter-tools</groupId>
        <artifactId>mvc-requester</artifactId>
        <version>0.4</version>
        <scope>test</scope>
    </dependency>

然后我得到了字节数组的响应,我可以随心所欲地将它与预期的文件进行比较.

Java相关问答推荐

参数值[...]与预期类型java.util.Date不匹配

无法传递消费者<;>;实例

弹簧靴和龙目岛

使用联接和分页的SpringBoot Spring数据JPA

为什么我的ArrayList索引的索引总是返回-1?

使用GridBagLayout正确渲染

测试容器无法加载类路径初始化脚本

Spring Security不允许加载js

如何使用log4j2(Json)记录由";异常引起的所有";?

扩展视图高度,并将其拖动到较低的视图上,而不是将其向下推?

有没有可能在时间范围内得到多种解决方案?

将JSON字符串转换为Java类

舰队运行配置Maven版本

如何在Jooq中获取临时表列引用?

无法使用Freemarker从XML中读取重复的标记值

在Java中将对象&转换为&q;HashMap(&Q)

在Java Spring JPA中插入包含对其他实体的引用的列

在具有Quarkus Panache的PostgreSQL中将JSON数据存储为JSONB时,会将其存储为转义字符串

为什么我的登录终结点不能被任何请求访问?

如何用Micrometer&;斯普肯