diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index 26fc2b7..36761f9 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestClientException; +import java.time.ZoneOffset; import java.util.List; import java.util.Optional; @@ -121,8 +122,8 @@ public class ApiController implements DefaultApi { return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); } - long start = project.getStart().toEpochSecond(null); - long plannedEnd = project.getPlannedEnd().toEpochSecond(null); + long start = project.getStart().toEpochSecond(ZoneOffset.UTC); + long plannedEnd = project.getPlannedEnd().toEpochSecond(ZoneOffset.UTC); List allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId()); if (allocations.stream() .map(Allocation::getProject) diff --git a/src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java b/src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java new file mode 100644 index 0000000..8ca9623 --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java @@ -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 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; + } + + +}