【发布时间】:2021-01-29 05:59:04
【问题描述】:
MockMvc 在请求构建器中传入param() 时在字符串末尾添加引号,如下所示
// initialization of mockMvc
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
ObjectNode tweets = ((ObjectNode) result.getRequest().getAttribute("tweets"));
String query = tweets.get("query").toString();
String nextToken = tweets.get("meta").get("next_token").toString();
mockMvc.perform(MockMvcRequestBuilders.post("/next")
.param("query", query)
.param("next_token", nextToken)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isError", is("N")))
.andReturn();
如果查询是 "#GoGreen" 并且 next_token 是 "wefw234234ewf234" 在控制器中接收到
查询 = "\"#GoGreen\"" 和 next_token = "\"wefw234234ewf234\""
@PostMapping("/next") @ResponseBody
public ResponseEntity<Object> nextPageTrendingTweets(@RequestParam("query") String query,
@RequestParam("next_token") String nextToken)
也许我在初始化mockMvc 时遗漏了一些东西。我搜索了这个问题,但找不到任何解决方案。
【问题讨论】:
标签: java spring junit5 mockmvc spring-test-mvc