Add integration test
This commit is contained in:
parent
e1bb48d7b1
commit
beff4aa971
@ -4,6 +4,11 @@ import de.szut.lf8_starter.project.ProjectEntity;
|
||||
import de.szut.lf8_starter.project.ProjectMapper;
|
||||
import de.szut.lf8_starter.project.ProjectService;
|
||||
import de.szut.lf8_starter.project.dto.GetProjectDto;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -19,6 +24,13 @@ public class GetProjectAction {
|
||||
this.projectMapper = projectMapper;
|
||||
}
|
||||
|
||||
@Operation(summary = "Find project by ID")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Project found", content = {
|
||||
@Content(mediaType = "application/json", schema = @Schema(implementation = GetProjectDto.class))
|
||||
}),
|
||||
@ApiResponse(responseCode = "404", description = "Project not found", content = @Content)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<GetProjectDto> findArticleById(@PathVariable Long id) {
|
||||
ProjectEntity project = this.projectService.findById(id);
|
||||
|
@ -0,0 +1,60 @@
|
||||
package de.szut.lf8_starter.integration.project;
|
||||
|
||||
import de.szut.lf8_starter.project.ProjectEntity;
|
||||
import de.szut.lf8_starter.project.ProjectRepository;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc(addFilters = false)
|
||||
public class FindProjectActionTest {
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired
|
||||
private ProjectRepository projectRepository;
|
||||
|
||||
@Test
|
||||
void createProjectTest() throws Exception {
|
||||
var project = new ProjectEntity();
|
||||
project.setId(1);
|
||||
project.setComment("comment");
|
||||
project.setContractor(1);
|
||||
project.setContractorName("contractorName");
|
||||
project.setEndDate(LocalDate.of(2024, 1, 1));
|
||||
project.setLeadingEmployee(1);
|
||||
project.setName("name");
|
||||
project.setStartDate(LocalDate.of(2021, 1, 1));
|
||||
project.setEmployees(List.of(1L,2L,3L));
|
||||
this.projectRepository.save(project);
|
||||
|
||||
this.mockMvc.perform(get("/projects/1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("id").value(1))
|
||||
.andExpect(jsonPath("comment").value("comment"))
|
||||
.andExpect(jsonPath("contractor").value(1))
|
||||
.andExpect(jsonPath("contractor_name").value("contractorName"))
|
||||
.andExpect(jsonPath("end_date").value("01.01.2024"))
|
||||
.andExpect(jsonPath("leading_employee").value(1))
|
||||
.andExpect(jsonPath("name").value("name"))
|
||||
.andExpect(jsonPath("start_date").value("01.01.2021"))
|
||||
.andExpect(jsonPath("employees").isArray())
|
||||
.andExpect(jsonPath("employees", hasSize(3)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user