Compare commits

..

No commits in common. "49244526ef625ff6b4eecae913766535e66bca17" and "096c25e33be204176290d0fd95653c7f17da3ac0" have entirely different histories.

2 changed files with 8 additions and 85 deletions

View file

@ -241,19 +241,16 @@ public class ApiController implements DefaultApi {
@Override
public ResponseEntity<EmployeeProjectsDTO> getAListOfAllProjectsFromASpecificEmployee(Long id) {
ApiTools.CheckEmployeeRecord employeeRecord = apiTools.checkEmployeeExists(id);
if (employeeRecord.status() != HttpStatus.OK) {
return new ResponseEntity<>(employeeRecord.status());
}
List<Allocation> allocationsByEmployee = allocationRepository.findAllByEmployeeId(id);
EmployeeProjectsDTO response = new EmployeeProjectsDTO();
response.setProjects(new ArrayList<>());
for (Allocation allocation : allocationsByEmployee) {
response.addProjectsItem(mapper.mapProject(allocation.getProject()));
}
Set<Project> projects = allocationsByEmployee.stream()
.map(Allocation::getProject)
.collect(Collectors.toSet());
return ResponseEntity.ok(response);
EmployeeProjectsDTO response = new EmployeeProjectsDTO();
for (Project project : projects) {
response.addProjectsItem(mapper.mapProject(project));
}
return new ResponseEntity<>(HttpStatus.OK);
}
}

View file

@ -1,74 +0,0 @@
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());
}
}