Problema 3: Deletar produto
@Test
public void deleteShouldDoNothingWhenLoggedAsAdminAndProductExists() throws Exception {
ResultActions result =
mockMvc.perform(delete("/products/{id}", existingId)
.header("Authorization", "Bearer " + adminToken)
.accept(MediaType.APPLICATION_JSON));
result.andExpect(status().isNoContent());
} @Test
public void deleteShouldReturnNotFoundWhenLoggedAsAdminAndProductDoesnotExists() throws Exception {
ResultActions result =
mockMvc.perform(delete("/products/{id}", nonExistingId)
.header("Authorization", "Bearer " + adminToken)
.accept(MediaType.APPLICATION_JSON));
result.andExpect(status().isNotFound());
}Anterior401 quando não logado como admin ou cliente (token inválido)PróximoProblema 4: Consultar pedido por id
Atualizado