I've been struggling trying to find out why my DELETED test method gets a 404 Https error, what i'm thinking is that the url provided to the test method is not being recogniced. I have used Postman to test the method, but Postman does the Delete Request successfully.
Can I get some help figuring this out?
Test
@Test
void remove() throws Exception {
Long id = 35L;
mockMvc.perform(MockMvcRequestBuilders.delete("/fch-fiscal/usuarios/delete/{id}", id)).
andExpect(MockMvcResultMatchers.status().isNoContent());
}
Controller
@DeleteMapping("/delete/{id}")
public ResponseEntity<Object> remove(@PathVariable("id") Long id) { // Elimina un usuario ingresado
Optional<Usuario> o = service.findById(id);
if (o.isPresent()) {
service.remove(id);
return ResponseEntity.noContent().build(); // 204
}
return ResponseEntity.notFound().build();
}
Stack trace
%TESTC 1 v2
%TSTTREE2,mx.com.ficachi.master.login.controllers.UsuarioControllerTest,true,1,false,1,UsuarioControllerTest,,[engine:junit-jupiter]/[class:mx.com.ficachi.master.login.controllers.UsuarioControllerTest]
%TSTTREE3,remove(mx.com.ficachi.master.login.controllers.UsuarioControllerTest),false,1,false,2,remove(),,[engine:junit-jupiter]/[class:mx.com.ficachi.master.login.controllers.UsuarioControllerTest]/[method:remove()]
%TESTS 3,remove(mx.com.ficachi.master.login.controllers.UsuarioControllerTest)
%FAILED 3,remove(mx.com.ficachi.master.login.controllers.UsuarioControllerTest)
%TRACES
java.lang.AssertionError: Status expected:<204> but was:<404>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:59)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:122)
at org.springframework.test.web.servlet.result.StatusResultMatchers.lambda$matcher$9(StatusResultMatchers.java:637)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
at mx.com.ficachi.master.login.controllers.UsuarioControllerTest.remove(UsuarioControllerTest.java:72)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
%TRACEE
%TESTE 3,remove(mx.com.ficachi.master.login.controllers.UsuarioControllerTest)
%RUNTIME6643
I've seen another questions and try to guide myself with this question, but it didn't work.