From 84793f340b103e9fd96c8867ca5a31a978d5e5fd Mon Sep 17 00:00:00 2001
From: Phan Huy Tran
Date: Wed, 2 Oct 2024 10:45:46 +0200
Subject: [PATCH] Increase Code Coverage
---
.../project/UpdateProjectActionTest.java | 49 +++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java
index 594745e..5d3cf40 100644
--- a/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java
+++ b/src/test/java/de/szut/lf8_starter/integration/project/UpdateProjectActionTest.java
@@ -84,6 +84,55 @@ class UpdateProjectActionTest {
}
+ @Test
+ void updateProjectShouldUpdateProjectPartially() throws Exception {
+ ProjectEntity project = new ProjectEntity();
+ project.setId(1);
+ project.setName("name");
+ project.setLeadingEmployee(1);
+ project.setContractor(1);
+ project.setComment("comment");
+ project.setEmployees(List.of(1L, 2L, 3L));
+ project.setContractorName("contractorName");
+ project.setStartDate(LocalDate.of(2021, 1, 1));
+ project.setPlannedEndDate(LocalDate.of(2023, 1, 1));
+ project.setEndDate(LocalDate.of(2024, 1, 1));
+ this.projectRepository.save(project);
+
+ String content = """
+ {}
+ """;
+
+ final var 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("contractor", is(1)))
+ .andExpect(jsonPath("contractor_name", is("contractorName")))
+ .andExpect(jsonPath("comment", is("comment")))
+ .andExpect(jsonPath("start_date", is("01.01.2021")))
+ .andExpect(jsonPath("planned_end_date", is("01.01.2023")))
+ .andExpect(jsonPath("end_date", is("01.01.2024")))
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ final var id = Long.parseLong(new JSONObject(contentAsString).get("id").toString());
+
+ final var existingProject = this.projectRepository.findById(id);
+ assertThat(existingProject.get().getName()).isEqualTo("name");
+ assertThat(existingProject.get().getLeadingEmployee()).isEqualTo(1);
+ assertThat(existingProject.get().getContractor()).isEqualTo(1);
+ assertThat(existingProject.get().getContractorName()).isEqualTo("contractorName");
+ assertThat(existingProject.get().getComment()).isEqualTo("comment");
+ assertThat(existingProject.get().getStartDate()).isEqualTo(LocalDate.of(2021, 1, 1));
+ assertThat(existingProject.get().getPlannedEndDate()).isEqualTo(LocalDate.of(2023, 1, 1));
+ assertThat(existingProject.get().getEndDate()).isEqualTo(LocalDate.of(2024, 1, 1));
+ }
+
@Test
void updateProjectShouldReturnNotFoundResponseWhenProjectIsNotFound() throws Exception {
this.mockMvc.perform(put("/projects/2").content("{}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound());