我正在尝试使用mockMvc
以下是我的控制器方法:
@RequestMapping(method = PUT, value = "/update-grouping-keys")
public ResponseEntity updateClaimGroupingKeyForDealer(@RequestBody GroupingKeyResource groupingKeyResource, @RequestParam(value = "dealer-id") String dealerId, @RequestParam(value = "user-id") String userId) throws IOException {
claimService.updateClaimGroupingKeyForDealer(dealerId, groupingKeyResource, userId);
return noContent();
}
而且,以下是我的测试用例文件:
@Test
public void shouldupdateClaimGroupingKeyForDealer() throws Exception {
String uri = "/claims/update-grouping-keys?dealer-id=Y832&user-id=/users/1";
GroupingKeyResource grpKeyResrc = new GroupingKeyResource();
System.out.println("Printing from Controller--->"+toJson(grpKeyResrc));
mockMvc.perform(put(uri).contentType(APPLICATION_JSON).content(toJson(grpKeyResrc))).andExpect(status().isNoContent());
}
在运行测试时出现以下错误:
Status expected:<204> but was:<500>
对于mockMvc.perform(put(uri).contentType(APPLICATION_JSON).content(toJson(grpKeyResrc))).andExpect(status().isNoContent());
行下面的
以下是我对URL的ServiceImpl代码。
ClaimGroupingKeyMapping claimGroupingKeyMapping = null;
ClaimGroupingHistory claimGroupingHistory = null;
boolean isUpdate = claimGroupMappingRepository.getClaimGroupingMappingByDealerCode(dealerId).size()>0 ? true:false;
boolean isUpdateClaimGroupingHistory = claimGroupingHistoryRepository.getClaimGroupingHistory(dealerId).size()>0? true:false; // if i comment this line, then test completing successfully.
在此代码中,如果我在boolean isUpdateClaimGroupingHistory = claimGroupingHistoryRepository.getClaimGroupingHistory(dealerId).size()>0? true:false;
行中注释,则测试用例成功完成。