PMT-4: Write Happy Path Test

This commit is contained in:
Rajbir Singh 2024-10-21 13:09:31 +02:00 committed by Dominik Säume
parent 954ad8237c
commit 1b036ca6f0
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C

View file

@ -0,0 +1,52 @@
package de.hmmh.pmt.project;
import de.hmmh.pmt.IntegrationTest;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.dtos.AddEmployeeDTO;
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.List;
import java.util.Map;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
public class AddEmployeeTest extends IntegrationTest {
@Test
void addValidEmployee() throws Exception {
EmployeeResponseDTO employee= new EmployeeResponseDTO();
employee.setId(2L);
employee.setSkillSet(List.of(newQualification(1L)));
when(mockEmployeeApi.findById(anyLong()))
.thenReturn(employee);
Map<String, Project> allProjects = createTestProjectData();
AddEmployeeDTO addEmployeeDTO = new AddEmployeeDTO();
addEmployeeDTO.setEmployeeId(1L);
addEmployeeDTO.setQualificationId(1L);
RequestBuilder request = MockMvcRequestBuilders
.post(baseUri + "/project/" + allProjects.get("research-lab").getId())
.contentType(MediaType.APPLICATION_JSON)
.content(this.objectMapper.writeValueAsString(addEmployeeDTO));
this.mvc
.perform(request)
.andExpect(status().isNoContent());
}
private static QualificationGetDTO newQualification(Long id){
QualificationGetDTO qualificationGetDTO = new QualificationGetDTO();
qualificationGetDTO.setId(id);
return qualificationGetDTO;
}
}