diff --git a/src/test/java/de/hmmh/pmt/IntegrationTest.java b/src/test/java/de/hmmh/pmt/IntegrationTest.java index 65e98f0..26ccee2 100644 --- a/src/test/java/de/hmmh/pmt/IntegrationTest.java +++ b/src/test/java/de/hmmh/pmt/IntegrationTest.java @@ -165,13 +165,18 @@ public abstract class IntegrationTest { allocation1ToOverlapA.setRole(TEST_QUALIFICATION_A_ID); allocations.put("1>overlap-a", allocation1ToOverlapA); - Allocation allocation1ToSpaceStation = new Allocation(); allocation1ToSpaceStation.setProject(allProjects.get("space-station")); allocation1ToSpaceStation.setEmployeeId(TEST_EMPLOYEE_A_ID); allocation1ToSpaceStation.setRole(TEST_QUALIFICATION_A_ID); allocations.put("1>space-station", allocation1ToSpaceStation); - + + Allocation allocation1ToAiResearch = new Allocation(); + allocation1ToAiResearch.setProject(allProjects.get("ai-research")); + allocation1ToAiResearch.setEmployeeId(TEST_EMPLOYEE_A_ID); + allocation1ToAiResearch.setRole(TEST_QUALIFICATION_A_ID); + allocations.put("1>ai-research", allocation1ToAiResearch); + allocationRepository.saveAllAndFlush(allocations.values()); return allocations; } diff --git a/src/test/java/de/hmmh/pmt/project/GetAllEmployeesByProjectTest.java b/src/test/java/de/hmmh/pmt/project/GetAllEmployeesByProjectTest.java new file mode 100644 index 0000000..7083385 --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/GetAllEmployeesByProjectTest.java @@ -0,0 +1,67 @@ +package de.hmmh.pmt.project; + +import de.hmmh.pmt.IntegrationTest; +import de.hmmh.pmt.db.Allocation; +import de.hmmh.pmt.db.Project; +import org.junit.jupiter.api.Test; +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.RestClientException; + + +import java.util.Map; + + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public class GetAllEmployeesByProjectTest extends IntegrationTest { + + @Test + void shouldReturnNotFoundWhenProjectDoesNotExist() throws Exception { + createTestProjectData(); + + this.mvc + .perform(getRequest(50L)) + .andExpect(status().isNotFound()); + } + + @Test + void shouldReturnOkWhenProjectHasNoEmployees() throws Exception { + Map allProjects = createTestProjectData(); + + this.mvc + .perform(getRequest(allProjects.get("research-lab").getId())) + .andExpect(status().isOk()); + } + + @Test + void shouldReturnListOfEmployeesWhenAllParametersAreValid() throws Exception { + Map allProjects = createTestProjectData(); + Map allocations = createTestAllocationData(allProjects); + + this.mvc + .perform(getRequest(allProjects.get("ai-research").getId())) + .andExpect(status().isOk()); + } + + @Test + void shouldReturnInternalServer() throws Exception { + when(this.mockEmployeeApi.findAll1()) + .thenThrow(new RestClientException("Internal Server Error")); + + Map allProjects = createTestProjectData(); + Map allocations = createTestAllocationData(allProjects); + + this.mvc + .perform(getRequest(allProjects.get("ai-research").getId())) + .andExpect(status().isInternalServerError()); + } + + private RequestBuilder getRequest(Long projectId) { + return MockMvcRequestBuilders + .get(baseUri + "/project/" + projectId + "/employees") + .contentType(MediaType.APPLICATION_JSON); + } +}