我有一个返回DeferredResult的控制器,它是一个POST。
控制器:
@RequestMapping(value = "/{customerId}/cards", method = RequestMethod.POST)
@ResponseBody
public DeferredResult<CardSummaryQuery> createCard(
@PathVariable String customerId,
@RequestBody CustomerDto payload) {
DeferredResult<CardSummaryQuery> deferred = new DeferredResult<>();
Observable<CardSummaryQuery> observable =
cardService.registerCardObservable(customerId, payload);
observable.subscribe(deferred::setResult, deferred::setErrorResult);
return deferred;
}
我正在尝试测试它,但收到以下错误:“java.lang.AssertionError:Content type not set”
MvcResult result = mockMvc
.perform(post("/customers/55e5d-4df4r-v4fgt/cards").content(payload)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(request().asyncStarted())
.andExpect(request().asyncResult("Deferred result")).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(jsonPath("$.success").value(true));
我该怎么做才能解决?
答案 0 :(得分:0)