From 1b036ca6f0beda9d2e96720d87c7812870af65d2 Mon Sep 17 00:00:00 2001 From: Rajbir Singh Date: Mon, 21 Oct 2024 13:09:31 +0200 Subject: [PATCH] PMT-4: Write Happy Path Test --- .../de/hmmh/pmt/project/AddEmployeeTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java 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..d9d9011 --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java @@ -0,0 +1,52 @@ +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.springframework.http.MediaType; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; +import java.util.Map; + +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; + } + + +}