PMT-26: alle mitarbeiter eines #15
2 changed files with 73 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue