PMT-27-added Tests for Responses

This commit is contained in:
Ole Kück 2024-10-23 11:10:40 +02:00
parent e6d3854fbd
commit 8dff301457
Signed by: SZUT-Ole
GPG key ID: 0A1DF1B37C4A1E4C

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