added shouldNotCreateProjectWithSameName test

This commit is contained in:
Rajbir Singh 2024-10-10 17:09:45 +02:00 committed by Dominik Säume
parent 9ad0ef60ed
commit 7c9b8e919d
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C

View file

@ -41,4 +41,38 @@ public class CreateTest extends IntegrationTest {
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andExpect(jsonPath("$.id").exists()); .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);
}
} }