PMT-26: Test Endpoint
All checks were successful
Quality Check / Validate OAS (push) Successful in 51s
Quality Check / Validate OAS (pull_request) Successful in 1m7s
Quality Check / Linting (push) Successful in 2m4s
Quality Check / Linting (pull_request) Successful in 2m15s
Quality Check / Testing (push) Successful in 2m27s
Quality Check / Static Analysis (push) Successful in 2m29s
Quality Check / Testing (pull_request) Successful in 2m20s
Quality Check / Static Analysis (pull_request) Successful in 2m24s

This commit is contained in:
Rajbir Singh 2024-10-23 13:17:23 +02:00 committed by Dominik Säume
parent b9d3170802
commit 108a31b2fa
2 changed files with 73 additions and 2 deletions

View file

@ -165,13 +165,18 @@ public abstract class IntegrationTest {
allocation1ToOverlapA.setRole(TEST_QUALIFICATION_A_ID); allocation1ToOverlapA.setRole(TEST_QUALIFICATION_A_ID);
allocations.put("1>overlap-a", allocation1ToOverlapA); allocations.put("1>overlap-a", allocation1ToOverlapA);
Allocation allocation1ToSpaceStation = new Allocation(); Allocation allocation1ToSpaceStation = new Allocation();
allocation1ToSpaceStation.setProject(allProjects.get("space-station")); allocation1ToSpaceStation.setProject(allProjects.get("space-station"));
allocation1ToSpaceStation.setEmployeeId(TEST_EMPLOYEE_A_ID); allocation1ToSpaceStation.setEmployeeId(TEST_EMPLOYEE_A_ID);
allocation1ToSpaceStation.setRole(TEST_QUALIFICATION_A_ID); allocation1ToSpaceStation.setRole(TEST_QUALIFICATION_A_ID);
allocations.put("1>space-station", allocation1ToSpaceStation); 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()); allocationRepository.saveAllAndFlush(allocations.values());
return allocations; return allocations;
} }

View file

@ -0,0 +1,66 @@
package de.hmmh.pmt.project;
import de.hmmh.pmt.IntegrationTest;
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<String, Project> allProjects = createTestProjectData();
this.mvc
.perform(getRequest(allProjects.get("research-lab").getId()))
.andExpect(status().isOk());
}
@Test
void shouldReturnListOfEmployeesWhenAllParametersAreValid() throws Exception {
Map<String, Project> allProjects = createTestProjectData();
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<String, Project> allProjects = createTestProjectData();
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);
}
}