PMT-4 created AddEmployeeTest
All checks were successful
Quality Check / Validate OAS (push) Successful in 54s
Quality Check / Validate OAS (pull_request) Successful in 1m2s
Quality Check / Linting (push) Successful in 2m7s
Quality Check / Linting (pull_request) Successful in 2m11s
Quality Check / Testing (push) Successful in 2m18s
Quality Check / Static Analysis (push) Successful in 2m24s
Quality Check / Testing (pull_request) Successful in 2m16s
Quality Check / Static Analysis (pull_request) Successful in 2m20s

This commit is contained in:
Rajbir Singh 2024-10-21 12:52:13 +02:00
parent 3a4c3fc21c
commit 0c3784dd72
2 changed files with 62 additions and 2 deletions

View file

@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import java.time.ZoneOffset;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -121,8 +122,8 @@ public class ApiController implements DefaultApi {
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
} }
long start = project.getStart().toEpochSecond(null); long start = project.getStart().toEpochSecond(ZoneOffset.UTC);
long plannedEnd = project.getPlannedEnd().toEpochSecond(null); long plannedEnd = project.getPlannedEnd().toEpochSecond(ZoneOffset.UTC);
List<Allocation> allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId()); List<Allocation> allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId());
if (allocations.stream() if (allocations.stream()
.map(Allocation::getProject) .map(Allocation::getProject)

View file

@ -0,0 +1,59 @@
package de.hmmh.pmt.project;
import de.hmmh.pmt.IntegrationTest;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.dtos.AddEmployeeDTO;
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.client.HttpClientErrorException;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.io.support.ClassicRequestBuilder.post;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
public class AddEmployeeTest extends IntegrationTest {
@Test
void addValidEmployee() throws Exception {
EmployeeResponseDTO employee= new EmployeeResponseDTO();
employee.setId(2L);
employee.setSkillSet(List.of(newQualification(1L)));
when(mockEmployeeApi.findById(anyLong()))
.thenReturn(employee);
Map<String, Project> allProjects = createTestProjectData();
AddEmployeeDTO addEmployeeDTO = new AddEmployeeDTO();
addEmployeeDTO.setEmployeeId(1L);
addEmployeeDTO.setQualificationId(1L);
RequestBuilder request = MockMvcRequestBuilders
.post(baseUri + "/project/" + allProjects.get("research-lab").getId())
.contentType(MediaType.APPLICATION_JSON)
.content(this.objectMapper.writeValueAsString(addEmployeeDTO));
this.mvc
.perform(request)
.andExpect(status().isNoContent());
}
private static QualificationGetDTO newQualification(Long id){
QualificationGetDTO qualificationGetDTO = new QualificationGetDTO();
qualificationGetDTO.setId(id);
return qualificationGetDTO;
}
}