Remove var
Some checks failed
Quality Check / Tests (pull_request) Failing after 34s
Build PR / Build and analyze (pull_request) Failing after 39s
Quality Check / Checkstyle Main (pull_request) Successful in 24s

This commit is contained in:
Phan Huy Tran 2024-10-23 10:34:24 +02:00
parent 928920a359
commit cda04fa8a2
6 changed files with 30 additions and 32 deletions

@ -6,10 +6,7 @@ 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.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.*;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@ -37,7 +34,7 @@ class AddEmployeeToProjectActionIntegrationTest {
@Test
void addEmployeeToProjectTest() throws Exception {
var project = new ProjectEntity();
ProjectEntity project = new ProjectEntity();
project.setComment("comment");
project.setContractor(1);
project.setContractorName("contractorName");
@ -54,7 +51,7 @@ class AddEmployeeToProjectActionIntegrationTest {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent());
var updatedProject = projectRepository.findById(1L).get();
ProjectEntity updatedProject = projectRepository.findById(1L).get();
assert updatedProject.getEmployees().contains(312L);
}
@ -73,7 +70,7 @@ class AddEmployeeToProjectActionIntegrationTest {
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
var response = this.restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
ResponseEntity<Map> response = this.restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
return Objects.requireNonNull(response.getBody()).get("access_token").toString();
}

@ -1,5 +1,6 @@
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;
@ -12,10 +13,9 @@ import org.springframework.test.web.servlet.MockMvc;
import java.time.LocalDate;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@ -41,9 +41,9 @@ class CreateProjectActionTest {
}
""";
final var contentAsString = this.mockMvc.perform(
post("/projects").content(content).contentType(MediaType.APPLICATION_JSON)
)
final String contentAsString = this.mockMvc.perform(
post("/projects").content(content).contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isCreated())
.andExpect(jsonPath("name", is("name")))
.andExpect(jsonPath("leading_employee", is(1)))
@ -57,15 +57,15 @@ class CreateProjectActionTest {
.getResponse()
.getContentAsString();
final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final long id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final var project = this.projectRepository.findById(id);
assertThat(project.get().getName()).isEqualTo("name");
assertThat(project.get().getLeadingEmployee()).isEqualTo(1);
assertThat(project.get().getContractor()).isEqualTo(4);
assertThat(project.get().getContractorName()).isEqualTo("Peter File");
assertThat(project.get().getComment()).isEqualTo("goal of project");
assertThat(project.get().getStartDate()).isEqualTo(LocalDate.of(2000, 1, 1));
assertThat(project.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2001, 1, 1));
final ProjectEntity project = this.projectRepository.findById(id);
assertThat(project.get().getName()).isEqualTo("name");
assertThat(project.get().getLeadingEmployee()).isEqualTo(1);
assertThat(project.get().getContractor()).isEqualTo(4);
assertThat(project.get().getContractorName()).isEqualTo("Peter File");
assertThat(project.get().getComment()).isEqualTo("goal of project");
assertThat(project.get().getStartDate()).isEqualTo(LocalDate.of(2000, 1, 1));
assertThat(project.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2001, 1, 1));
}
}

@ -26,7 +26,7 @@ class GetProjectActionTest {
@Test
void getProjectTest() throws Exception {
var project = new ProjectEntity();
ProjectEntity project = new ProjectEntity();
project.setId(1);
project.setComment("comment");
project.setContractor(1);

@ -27,7 +27,7 @@ class ProjectFindAllSuccessTest {
@Test
void findAllProjectsTest() throws Exception {
var project = new ProjectEntity();
ProjectEntity project = new ProjectEntity();
project.setId(1);
project.setComment("comment");
project.setContractor(1);
@ -36,7 +36,7 @@ class ProjectFindAllSuccessTest {
project.setLeadingEmployee(1);
project.setName("name");
project.setStartDate(LocalDate.of(2021, 1, 1));
project.setEmployees(List.of(1L,2L,3L));
project.setEmployees(List.of(1L, 2L, 3L));
this.projectRepository.save(project);
this.mockMvc.perform(get("/projects"))

@ -25,7 +25,7 @@ class RemoveProjectActionTest {
@Test
void deleteProjectTest() throws Exception {
var project = new ProjectEntity();
ProjectEntity project = new ProjectEntity();
project.setComment("comment");
project.setContractor(1);
project.setContractorName("contractorName");

@ -13,6 +13,7 @@ import org.springframework.test.web.servlet.MockMvc;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
@ -55,7 +56,7 @@ class UpdateProjectActionTest {
}
""";
final var contentAsString = this.mockMvc.perform(
final String contentAsString = this.mockMvc.perform(
put("/projects/1").content(content).contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
@ -71,9 +72,9 @@ class UpdateProjectActionTest {
.getResponse()
.getContentAsString();
final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final long id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final var existingProject = this.projectRepository.findById(id);
final Optional<ProjectEntity> existingProject = this.projectRepository.findById(id);
assertThat(existingProject.get().getName()).isEqualTo("updatedName");
assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(2);
assertThat(existingProject.get().getContractor()).isEqualTo(6);
@ -103,13 +104,13 @@ class UpdateProjectActionTest {
{}
""";
final var contentAsString = this.mockMvc.perform(
final String contentAsString = this.mockMvc.perform(
put("/projects/1").content(content).contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
.andExpect(jsonPath("name", is("name")))
.andExpect(jsonPath("leading_employee", is(1)))
.andExpect(jsonPath("employees", is(List.of(1,2,3))))
.andExpect(jsonPath("employees", is(List.of(1, 2, 3))))
.andExpect(jsonPath("contractor", is(1)))
.andExpect(jsonPath("contractor_name", is("contractorName")))
.andExpect(jsonPath("comment", is("comment")))
@ -120,9 +121,9 @@ class UpdateProjectActionTest {
.getResponse()
.getContentAsString();
final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final long id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
final var existingProject = this.projectRepository.findById(id);
final Optional<ProjectEntity> existingProject = this.projectRepository.findById(id);
assertThat(existingProject.get().getName()).isEqualTo("name");
assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(1);
assertThat(existingProject.get().getContractor()).isEqualTo(1);