story/PMT-27-mitarbeiter-aus-einem-projekt #17
1 changed files with 59 additions and 0 deletions
59
src/test/java/de/hmmh/pmt/project/DeleteEmployeeTest.java
Normal file
59
src/test/java/de/hmmh/pmt/project/DeleteEmployeeTest.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package de.hmmh.pmt.project;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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 de.hmmh.pmt.IntegrationTest;
|
||||
import de.hmmh.pmt.db.Allocation;
|
||||
import de.hmmh.pmt.db.Project;
|
||||
import de.hmmh.pmt.dtos.AddEmployeeDTO;
|
||||
|
||||
public class DeleteEmployeeTest extends IntegrationTest {
|
||||
@Test
|
||||
void shouldNotDeleteEmployeeWhenProjectIsNotFound() throws Exception {
|
||||
mvc
|
||||
.perform(delete(baseUri + "/project/1"))
|
||||
.andExpect(status().isNotFound())
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotDeleteEmployeeWhenEmployeeIsNotAllocated() throws Exception {
|
||||
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
|
||||
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allProjects.get("research-lab").getId(), 0L))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
void employeeSuccessfullyDeletedFromProject() throws Exception {
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
Map<String, Allocation> allAllocations = createTestAllocationData(allProjects);
|
||||
Allocation allocation = allAllocations.get("1>space-station");
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allocation.getProjectId(),allocation.getEmployeeId()))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
}
|
||||
|
||||
private RequestBuilder getRequest(Long projectId, Long employeeId) {
|
||||
return MockMvcRequestBuilders
|
||||
.delete(baseUri + "/project/" + projectId + "/employee/" + employeeId);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue