Compare commits

...

4 commits

Author SHA1 Message Date
Rajbir Singh
609cafcb71 added shouldNotCreateProjectWhenAdministratorDoesNotExist test
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m7s
Quality Check / Static Analysis (push) Successful in 1m15s
Quality Check / Testing (push) Successful in 1m14s
Quality Check / Validate OAS (pull_request) Successful in 32s
Quality Check / Linting (pull_request) Successful in 1m9s
Quality Check / Testing (pull_request) Successful in 1m14s
Quality Check / Static Analysis (pull_request) Successful in 1m16s
2024-10-10 17:57:25 +02:00
Rajbir Singh
3e92e2747c added shouldNotCreateProjectWithSameName test 2024-10-10 17:09:45 +02:00
Rajbir Singh
beb293753b Merge remote-tracking branch 'origin/story/PMT-16-projekt-anlegen' into story/PMT-16-projekt-anlegen
# Conflicts:
#	api/pmt.yml
#	src/main/java/de/hmmh/pmt/ApiController.java
2024-10-10 14:16:44 +02:00
Rajbir Singh
d84647f9e6 .
Some checks failed
Quality Check / Validate OAS (push) Successful in 34s
Quality Check / Linting (push) Failing after 52s
Quality Check / Static Analysis (push) Failing after 1m0s
Quality Check / Testing (push) Successful in 1m4s
2024-10-07 14:27:22 +02:00

View file

@ -5,12 +5,16 @@ 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.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.client.HttpClientErrorException;
import java.time.LocalDateTime;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -18,8 +22,7 @@ public class CreateTest extends IntegrationTest {
@Test
void successfullyCreate() throws Exception {
Mockito
.when(this.mockEmployeeApi.findById(Mockito.anyLong()))
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
.thenReturn(new EmployeeResponseDTO());
CreateProjectDTO createDTO = new CreateProjectDTO();
@ -41,4 +44,62 @@ 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(1L);
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());
}
@Test
void shouldNotCreateProjectWhenAdministratorDoesNotExist() throws Exception {
HttpClientErrorException httpClientErrorException = mock(HttpClientErrorException.class);
when(httpClientErrorException.getStatusCode()).thenReturn(HttpStatusCode.valueOf(404));
when(this.mockEmployeeApi.findById(1L))
.thenThrow(httpClientErrorException);
CreateProjectDTO createDTO = new CreateProjectDTO();
createDTO.setName("Test");
createDTO.setGoal("A Test Goal");
createDTO.setCustomerId(10L);
createDTO.setAdministratorId(1L);
createDTO.setStart(LocalDateTime.of(2000, 1, 13, 12, 51));
createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42));
RequestBuilder projectRequestBuilder = createProjectRequestBuilder(createDTO);
this.mvc
.perform(projectRequestBuilder)
.andExpect(status().isNotFound());
}
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);
}
}