From 730c144c22c66137c94953950b6bf78dcca6ebe7 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 2 Oct 2024 11:12:26 +0200 Subject: [PATCH] test(DeleteProjectAction): add integration tests for project deletion --- .../project/DeleteProjectActionTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java diff --git a/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java new file mode 100644 index 0000000..1e006d9 --- /dev/null +++ b/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java @@ -0,0 +1,50 @@ +package de.szut.lf8_starter.integration.project; + +import de.szut.lf8_starter.project.ProjectEntity; +import de.szut.lf8_starter.project.ProjectRepository; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +import java.time.LocalDate; +import java.util.List; + +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@AutoConfigureMockMvc(addFilters = false) +public class DeleteProjectActionTest { + @Autowired + private MockMvc mockMvc; + @Autowired + private ProjectRepository projectRepository; + + @Test + void deleteProjectTest() throws Exception { + var project = new ProjectEntity(); + project.setId(1); + project.setComment("comment"); + project.setContractor(1); + project.setContractorName("contractorName"); + project.setEndDate(LocalDate.of(2024, 1, 1)); + project.setLeadingEmployee(1); + project.setName("name"); + project.setStartDate(LocalDate.of(2021, 1, 1)); + project.setEmployees(List.of(1L, 2L, 3L)); + this.projectRepository.save(project); + + this.mockMvc.perform(delete("/projects/1")) + .andExpect(status().isNoContent()); + } + + @Test + void deleteProjectShouldReturnNotFoundResponseWhenProjectIsNotFound() throws Exception { + this.mockMvc.perform(get("/projects/2")).andExpect(status().isNotFound()); + } +}