PMT-40: Write Tests for Endpoint Implementation
All checks were successful
Quality Check / Validate OAS (push) Successful in 52s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Successful in 2m8s
Quality Check / Linting (pull_request) Successful in 2m14s
Quality Check / Testing (push) Successful in 2m30s
Quality Check / Static Analysis (push) Successful in 2m34s
Quality Check / Testing (pull_request) Successful in 2m26s
Quality Check / Static Analysis (pull_request) Successful in 2m29s
All checks were successful
Quality Check / Validate OAS (push) Successful in 52s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Successful in 2m8s
Quality Check / Linting (pull_request) Successful in 2m14s
Quality Check / Testing (push) Successful in 2m30s
Quality Check / Static Analysis (push) Successful in 2m34s
Quality Check / Testing (pull_request) Successful in 2m26s
Quality Check / Static Analysis (pull_request) Successful in 2m29s
This commit is contained in:
parent
6b430ae251
commit
49244526ef
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