From 7c9b8e919d26bf2610e0a6cc3c7eb538c6a8f814 Mon Sep 17 00:00:00 2001 From: Rajbir Singh Date: Thu, 10 Oct 2024 17:09:45 +0200 Subject: [PATCH] added shouldNotCreateProjectWithSameName test --- .../java/de/hmmh/pmt/project/CreateTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/de/hmmh/pmt/project/CreateTest.java b/src/test/java/de/hmmh/pmt/project/CreateTest.java index 2f62f0b..3fbd7b2 100644 --- a/src/test/java/de/hmmh/pmt/project/CreateTest.java +++ b/src/test/java/de/hmmh/pmt/project/CreateTest.java @@ -41,4 +41,38 @@ public class CreateTest extends IntegrationTest { .andExpect(status().isCreated()) .andExpect(jsonPath("$.id").exists()); } + + @Test + void shouldNotCreateProjectWithSameName() 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)); + + RequestBuilder firstProjectRequestBuilder = createProjectRequestBuilder(createDTO); + + this.mvc + .perform(firstProjectRequestBuilder) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.id").exists()); + + RequestBuilder secondProjectRequestBuilder = createProjectRequestBuilder(createDTO); + + this.mvc + .perform(secondProjectRequestBuilder) + .andExpect(status().isConflict()); + } + + private RequestBuilder createProjectRequestBuilder(CreateProjectDTO createDTO) throws Exception { + + return MockMvcRequestBuilders + .post(baseUri + "/project") + .accept(MediaType.APPLICATION_JSON) + .content(this.objectMapper.writeValueAsString(createDTO)) + .contentType(MediaType.APPLICATION_JSON); + } }