diff --git a/src/test/java/de/hmmh/pmt/project/DeleteEmployeeTest.java b/src/test/java/de/hmmh/pmt/project/DeleteEmployeeTest.java new file mode 100644 index 0000000..294dd90 --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/DeleteEmployeeTest.java @@ -0,0 +1,59 @@ +package de.hmmh.pmt.project; + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.web.client.HttpClientErrorException; + +import de.hmmh.pmt.IntegrationTest; +import de.hmmh.pmt.db.Allocation; +import de.hmmh.pmt.db.Project; +import de.hmmh.pmt.dtos.AddEmployeeDTO; + +public class DeleteEmployeeTest extends IntegrationTest { + @Test + void shouldNotDeleteEmployeeWhenProjectIsNotFound() throws Exception { + mvc + .perform(delete(baseUri + "/project/1")) + .andExpect(status().isNotFound()) + ; + } + + @Test + void shouldNotDeleteEmployeeWhenEmployeeIsNotAllocated() throws Exception { + when(this.mockEmployeeApi.findById(Mockito.anyLong())) + .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); + + Map allProjects = createTestProjectData(); + + this.mvc + .perform(getRequest(allProjects.get("research-lab").getId(), 0L)) + .andExpect(status().isNotFound()); + } + + @Test + void employeeSuccessfullyDeletedFromProject() throws Exception { + Map allProjects = createTestProjectData(); + Map allAllocations = createTestAllocationData(allProjects); + Allocation allocation = allAllocations.get("1>space-station"); + + this.mvc + .perform(getRequest(allocation.getProjectId(),allocation.getEmployeeId())) + .andExpect(status().isNoContent()); + + } + + private RequestBuilder getRequest(Long projectId, Long employeeId) { + return MockMvcRequestBuilders + .delete(baseUri + "/project/" + projectId + "/employee/" + employeeId); + } +}