We have kinda stuck in one point of unit testing. We would like to test, what happens if the database server is not connected or not reachable. We have already written the testcode, but we are not able to imitate, if the server is not connected.
Here is our current test code:
@Test
public void databaseIsNotRunning() throws Exception {
mockMvc.perform(get("/heartbeat"))
.andExpect(status().is5xxServerError())
.andExpect(MockMvcResultMatchers.jsonPath("$.application-status").value("ok"))
.andExpect(MockMvcResultMatchers.jsonPath("$.database-status").value("error"))
.andExpect(content().contentType(contentType));
}
What is wrong with it, or missing? Can someone or anyone help?