gpt4 book ai didi

spring - JsonPathRequestMatchers 到 ResultMatcher 使用 MockMVC

转载 作者:行者123 更新时间:2023-12-01 15:22:12 25 4
gpt4 key购买 nike

我正在使用 MockMVC 测试一个 todo Controller :

            mockMvc.perform(MockMvcRequestBuilders.get("/toDos/")
.with(user("user").password("password").roles("ADMIN"))
.content("{ \"saved_date\": \"2010-01-01\"}")
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect((ResultMatcher) jsonPath("$.id").doesNotExist())
.andExpect(status().isOk())
.andExpect( content().contentType("application/json"));
}

我不断收到此错误:
java.lang.ClassCastException: org.springframework.test.web.client.match.JsonPathRequestMatchers$5 cannot be cast to org.springframework.test.web.servlet.ResultMatcher

我想删除对 (ResultMatcher) 的转换,但不知道如何创建一个 ResultMatcher 来测试 Id 的存在。有任何想法吗 ?

最佳答案

我想你想使用:

org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath

... 代替:
org.springframework.test.web.client.match.MockMvcResultMatchers.jsonPath

关于spring - JsonPathRequestMatchers 到 ResultMatcher 使用 MockMVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44719251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com