From ffefb5a72ed9d53f98f6b001c3a2146b4304bd16 Mon Sep 17 00:00:00 2001 From: Phan Huy Tran Date: Wed, 23 Oct 2024 14:46:44 +0200 Subject: [PATCH] Fix tests --- requests/employee/createEmployee.http | 2 +- .../integration/project/AddEmployeeToProjectTest.java | 9 +++------ .../integration/project/CreateProjectActionTest.java | 8 ++------ .../integration/project/GetEmployeesFromProjectTest.java | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/requests/employee/createEmployee.http b/requests/employee/createEmployee.http index b3f4591..becd37a 100644 --- a/requests/employee/createEmployee.http +++ b/requests/employee/createEmployee.http @@ -3,7 +3,7 @@ Authorization: Bearer {{auth_token}} Content-Type: application/json { - "firstName": "Jan1", + "firstName": "Jan12", "lastName": "Klattenhoff1", "street": "Pirolweg 171", "postcode": "27777", diff --git a/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java b/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java index 35144fc..8dc494b 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/AddEmployeeToProjectTest.java @@ -2,7 +2,6 @@ package de.szut.lf8_starter.integration.project; import de.szut.lf8_starter.project.ProjectEntity; import de.szut.lf8_starter.project.ProjectRepository; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -32,13 +31,10 @@ class AddEmployeeToProjectTest { @Autowired private ProjectRepository projectRepository; - @BeforeEach - public void clear() { - this.projectRepository.deleteAll(); - } - @Test void addEmployeeToProjectTest() throws Exception { + this.projectRepository.deleteAll(); + ProjectEntity project = new ProjectEntity(); project.setComment("comment"); project.setContractor(1); @@ -60,6 +56,7 @@ class AddEmployeeToProjectTest { assert updatedProject.getEmployees().contains(312L); } + private String getBearerToken() { String url = "https://keycloak.szut.dev/auth/realms/szut/protocol/openid-connect/token"; diff --git a/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java index c5f87cc..bea6042 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/CreateProjectActionTest.java @@ -3,7 +3,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.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -36,13 +35,10 @@ class CreateProjectActionTest { @Autowired private RestTemplate restTemplate; - @BeforeEach - public void clear() { - this.projectRepository.deleteAll(); - } - @Test void createProjectTest() throws Exception { + this.projectRepository.deleteAll(); + String content = """ { "name": "name", diff --git a/src/test/java/de/szut/lf8_starter/integration/project/GetEmployeesFromProjectTest.java b/src/test/java/de/szut/lf8_starter/integration/project/GetEmployeesFromProjectTest.java index 985fd2f..b585179 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/GetEmployeesFromProjectTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/GetEmployeesFromProjectTest.java @@ -42,7 +42,7 @@ class GetEmployeesFromProjectTest { project.setLeadingEmployee(1); project.setName("name"); project.setStartDate(LocalDate.of(2021, 1, 1)); - project.setEmployees(List.of(315L)); + project.setEmployees(List.of(316L)); this.projectRepository.save(project); this.mockMvc.perform(get("/projects/1/employees") @@ -50,7 +50,7 @@ class GetEmployeesFromProjectTest { ).andExpect(status().isOk()) .andExpect(jsonPath("project_id").value(1)) .andExpect(jsonPath("project_description").value("comment")) - .andExpect(jsonPath("employees[0].id").value(315)) + .andExpect(jsonPath("employees[0].id").value(316)) .andExpect(jsonPath("employees[0].skillSet[0].skill").value("Product Owner")); }