story/PMT-27-mitarbeiter-aus-einem-projekt #17

Merged
SZUT-Ole merged 7 commits from story/PMT-27-mitarbeiter-aus-einem-projekt into trunk 2024-10-23 10:48:09 +00:00
Showing only changes of commit 8dff301457 - Show all commits

View 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);
}
}