PMT-40: alle Projekte eines Bestimmten Mitarbeiters abfragen #18
1 changed files with 74 additions and 0 deletions
|
@ -0,0 +1,74 @@
|
||||||
|
package de.hmmh.pmt.project;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.IntegrationTest;
|
||||||
|
import de.hmmh.pmt.db.Allocation;
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class GetAllProjectsByEmployeeTest extends IntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void successfullyGetAllProjectsByEmployee() throws Exception {
|
||||||
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
|
.thenReturn(new EmployeeResponseDTO());
|
||||||
|
|
||||||
|
Map<String, Project> allProjects = createTestProjectData();
|
||||||
|
Map<String, Allocation> allAllocations = createTestAllocationData(allProjects);
|
||||||
|
|
||||||
|
List<Allocation> allocations = allAllocations
|
||||||
|
.values()
|
||||||
|
.stream()
|
||||||
|
.filter(allocation -> allocation.getEmployeeId().equals(TEST_EMPLOYEE_A_ID))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/employye/" + TEST_EMPLOYEE_A_ID + "/projects"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.projects", hasSize(allocations.size())))
|
||||||
|
.andExpect(jsonPath("$.projects[*].id").exists())
|
||||||
|
.andExpect(jsonPath("$.projects[*].name").exists())
|
||||||
|
.andExpect(jsonPath("$.projects[*].goal").exists())
|
||||||
|
.andExpect(jsonPath("$.projects[*].customerId").exists())
|
||||||
|
.andExpect(jsonPath("$.projects[*].administratorId").exists())
|
||||||
|
.andExpect(jsonPath("$.projects[*].plannedEnd").exists())
|
||||||
|
.andExpect(jsonPath("$.projects[*].realEnd").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnEmptyListWhenNoAllocationsFound() throws Exception {
|
||||||
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
|
.thenReturn(new EmployeeResponseDTO());
|
||||||
|
|
||||||
|
createTestProjectData();
|
||||||
|
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/employye/" + TEST_EMPLOYEE_A_ID + "/projects"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.projects", empty()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnNotFoundWhenEmployeeDoesNotExist() throws Exception {
|
||||||
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
|
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
|
||||||
|
|
||||||
|
mvc
|
||||||
|
.perform(get(baseUri + "/employye/0/projects"))
|
||||||
|
.andExpect(status().isNotFound());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue