From 279fec4d96991af8f3c00d7f01ef10d9fc418942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Wed, 9 Oct 2024 10:06:33 +0200 Subject: [PATCH] testing....... (Comit needs to be edited later) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rajbir Singh Signed-off-by: Dominik Säume --- .../java/de/hmmh/pmt/project/CreateTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/de/hmmh/pmt/project/CreateTest.java diff --git a/src/test/java/de/hmmh/pmt/project/CreateTest.java b/src/test/java/de/hmmh/pmt/project/CreateTest.java new file mode 100644 index 0000000..ef9a2b2 --- /dev/null +++ b/src/test/java/de/hmmh/pmt/project/CreateTest.java @@ -0,0 +1,45 @@ +package de.hmmh.pmt.project; + +import de.hmmh.pmt.IntegrationTest; +import de.hmmh.pmt.dtos.CreateProjectDTO; +import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import java.time.LocalDateTime; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +public class CreateTest extends IntegrationTest { + + @Test + void successfullyCreate() throws Exception { + CreateProjectDTO createDTO = new CreateProjectDTO(); + createDTO.setName("Test"); + createDTO.setGoal("A Test Goal"); + createDTO.setCustomerId(10L); + createDTO.setAdministratorId(10L); + createDTO.setStart(LocalDateTime.of(2000, 1, 13, 12, 51)); + createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42)); + + String body = objectMapper.writeValueAsString(createDTO); + + RequestBuilder requestBuilder = MockMvcRequestBuilders + .post(baseUri + "/project") + .accept(MediaType.APPLICATION_JSON) + .content(body) + .contentType(MediaType.APPLICATION_JSON); + + Mockito.when(mockEmployeeApi.findById(Mockito.anyLong())).thenReturn(new EmployeeResponseDTO()); + + mvc + .perform(requestBuilder) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.id").exists()) + ; + } +}