PMT-16: Cleanup Test Cases
All checks were successful
Quality Check / Validate OAS (push) Successful in 50s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Successful in 2m2s
Quality Check / Linting (pull_request) Successful in 2m9s
Quality Check / Testing (push) Successful in 2m18s
Quality Check / Testing (pull_request) Successful in 2m14s
Quality Check / Static Analysis (push) Successful in 2m24s
Quality Check / Static Analysis (pull_request) Successful in 2m18s
All checks were successful
Quality Check / Validate OAS (push) Successful in 50s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Successful in 2m2s
Quality Check / Linting (pull_request) Successful in 2m9s
Quality Check / Testing (push) Successful in 2m18s
Quality Check / Testing (pull_request) Successful in 2m14s
Quality Check / Static Analysis (push) Successful in 2m24s
Quality Check / Static Analysis (pull_request) Successful in 2m18s
This commit is contained in:
parent
499d1279d1
commit
03e33d654e
1 changed files with 17 additions and 58 deletions
|
@ -1,5 +1,4 @@
|
||||||
package de.hmmh.pmt.project;
|
package de.hmmh.pmt.project;
|
||||||
|
|
||||||
import de.hmmh.pmt.IntegrationTest;
|
import de.hmmh.pmt.IntegrationTest;
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
|
@ -7,17 +6,13 @@ import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.HttpStatusCode;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.web.servlet.RequestBuilder;
|
import org.springframework.test.web.servlet.RequestBuilder;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
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.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
@ -29,33 +24,19 @@ public class CreateTest extends IntegrationTest {
|
||||||
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
.thenReturn(new EmployeeResponseDTO());
|
.thenReturn(new EmployeeResponseDTO());
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
this.mvc
|
this.mvc
|
||||||
.perform(getRequest(createDTO))
|
.perform(getRequest(getCreateProjectDTO()))
|
||||||
.andExpect(status().isCreated())
|
.andExpect(status().isCreated())
|
||||||
.andExpect(jsonPath("$.id").exists());
|
.andExpect(jsonPath("$.id").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldNotCreateProjectWithSameName() throws Exception {
|
void shouldNotCreateProjectWithSameName() throws Exception {
|
||||||
|
|
||||||
Map<String, Project> allProjects = createTestProjectData();
|
Map<String, Project> allProjects = createTestProjectData();
|
||||||
Project spaceStation = allProjects.get("space-station");
|
Project spaceStation = allProjects.get("space-station");
|
||||||
|
|
||||||
CreateProjectDTO createDTO = new CreateProjectDTO();
|
CreateProjectDTO createDTO = getCreateProjectDTO();
|
||||||
createDTO.setName(spaceStation.getName());
|
createDTO.setName(spaceStation.getName());
|
||||||
createDTO.setGoal(spaceStation.getGoal());
|
|
||||||
createDTO.setCustomerId(spaceStation.getCustomerId());
|
|
||||||
createDTO.setAdministratorId(spaceStation.getAdministratorId());
|
|
||||||
createDTO.setStart(spaceStation.getStart());
|
|
||||||
createDTO.setPlannedEnd(spaceStation.getPlannedEnd());
|
|
||||||
|
|
||||||
this.mvc
|
this.mvc
|
||||||
.perform(getRequest(createDTO))
|
.perform(getRequest(createDTO))
|
||||||
|
@ -64,69 +45,37 @@ public class CreateTest extends IntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldNotCreateProjectWhenAdministratorDoesNotExist() throws Exception {
|
void shouldNotCreateProjectWhenAdministratorDoesNotExist() throws Exception {
|
||||||
|
|
||||||
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
|
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
this.mvc
|
this.mvc
|
||||||
.perform(getRequest(createDTO))
|
.perform(getRequest(getCreateProjectDTO()))
|
||||||
.andExpect(status().isNotFound());
|
.andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldReturnUnavailableWhenEmployeeApiIsDown() throws Exception {
|
void shouldReturnUnavailableWhenEmployeeApiIsDown() throws Exception {
|
||||||
|
|
||||||
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
.thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR));
|
.thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR));
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
this.mvc
|
this.mvc
|
||||||
.perform(getRequest(createDTO))
|
.perform(getRequest(getCreateProjectDTO()))
|
||||||
.andExpect(status().isServiceUnavailable());
|
.andExpect(status().isServiceUnavailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldReturnInternalServerErrorOnApiClientCrash() throws Exception {
|
void shouldReturnInternalServerErrorOnApiClientCrash() throws Exception {
|
||||||
|
|
||||||
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||||
.thenThrow(new RestClientException("Api Client crash"));
|
.thenThrow(new RestClientException("Api Client crash"));
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
this.mvc
|
this.mvc
|
||||||
.perform(getRequest(createDTO))
|
.perform(getRequest(getCreateProjectDTO()))
|
||||||
.andExpect(status().isInternalServerError());
|
.andExpect(status().isInternalServerError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldReturnUnprocessableWhenDataIsInvalid() throws Exception {
|
void shouldReturnUnprocessableWhenDataIsInvalid() throws Exception {
|
||||||
|
CreateProjectDTO createDTO = getCreateProjectDTO();
|
||||||
CreateProjectDTO createDTO = new CreateProjectDTO();
|
|
||||||
createDTO.setName("Test");
|
|
||||||
createDTO.setGoal("A Test Goal");
|
|
||||||
createDTO.setCustomerId(10L);
|
|
||||||
createDTO.setAdministratorId(1L);
|
|
||||||
createDTO.setStart(LocalDateTime.of(2003, 1, 13, 12, 51));
|
createDTO.setStart(LocalDateTime.of(2003, 1, 13, 12, 51));
|
||||||
createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42));
|
createDTO.setPlannedEnd(LocalDateTime.of(2002, 3, 21, 11, 42));
|
||||||
|
|
||||||
|
@ -135,8 +84,18 @@ public class CreateTest extends IntegrationTest {
|
||||||
.andExpect(status().isUnprocessableEntity());
|
.andExpect(status().isUnprocessableEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
private RequestBuilder getRequest(CreateProjectDTO createDTO) throws Exception {
|
private CreateProjectDTO getCreateProjectDTO() {
|
||||||
|
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));
|
||||||
|
return createDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestBuilder getRequest(CreateProjectDTO createDTO) throws Exception {
|
||||||
return MockMvcRequestBuilders
|
return MockMvcRequestBuilders
|
||||||
.post(baseUri + "/project")
|
.post(baseUri + "/project")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
|
|
Loading…
Reference in a new issue