使用带有MockMvc的delete方法rest api从存储库测试deleteAll()

时间:2018-03-21 11:38:49

标签: java spring-boot mockito integration-testing

我正在对REST api进行集成测试,其中所有测试都可以正常运行。

@Test
public void deleteAllUsers_should_return_noContent() throws Exception {
    //Given
    //When
    ResultActions resultActions = mockMvc
            .perform(delete("/pair?delAll"));
    //Then
    resultActions
            .andDo(print())
            .andExpect(status().isNoContent());
}

我期待204状态,但它获得400.以下是该方法的代码:

@RequestMapping(value = "/pair", method = RequestMethod.DELETE, params = "delAll")
public ResponseEntity<Void> deleteAllUsers() {
    userRepository.deleteAll();
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

对于我做错了什么的任何想法?

编辑:找到解决方案只需添加&#34; = true&#34;这些行

@RequestMapping(value = "/pair", method = RequestMethod.DELETE, params = "delAll=true")

ResultActions resultActions = mockMvc
            .perform(delete("/pair?delAll=true"));

0 个答案:

没有答案