feat: Write Integration test for Create Project Route and ensure using Snake Case in JSON Format (SCRUM-7) #14
					 4 changed files with 25 additions and 32 deletions
				
			
		Ensure Snake Case in JSON
				commit
				
					
					
						ffb1a1586a
					
				
			
		|  | @ -8,8 +8,8 @@ Content-Type: application/json | ||||||
|   "leading_employee": 1, |   "leading_employee": 1, | ||||||
|   "employees": [2, 3], |   "employees": [2, 3], | ||||||
|   "contractor": 4, |   "contractor": 4, | ||||||
|   "contractorName": "Peter File", |   "contractor_name": "Peter File", | ||||||
|   "comment": "goal of project", |   "comment": "goal of project", | ||||||
|   "startDate": "01.01.2000", |   "start_date": "01.01.2000", | ||||||
|   "plannedEndDate": "01.01.2001" |   "planned_end_date": "01.01.2001" | ||||||
| } | } | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| package de.szut.lf8_starter.project.dto; | package de.szut.lf8_starter.project.dto; | ||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.annotation.JsonFormat; | import com.fasterxml.jackson.annotation.JsonFormat; | ||||||
|  | import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||||||
|  | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||||||
| import jakarta.validation.constraints.NotBlank; | import jakarta.validation.constraints.NotBlank; | ||||||
| import jakarta.validation.constraints.NotNull; | import jakarta.validation.constraints.NotNull; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
|  | @ -11,6 +13,7 @@ import java.util.List; | ||||||
| 
 | 
 | ||||||
| @Getter | @Getter | ||||||
| @Setter | @Setter | ||||||
|  | @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||||||
| public class CreateProjectDto { | public class CreateProjectDto { | ||||||
|     @NotBlank |     @NotBlank | ||||||
|     private String name; |     private String name; | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| package de.szut.lf8_starter.project.dto; | package de.szut.lf8_starter.project.dto; | ||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.annotation.JsonFormat; | import com.fasterxml.jackson.annotation.JsonFormat; | ||||||
|  | import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||||||
|  | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||||||
| import jakarta.validation.constraints.NotBlank; | import jakarta.validation.constraints.NotBlank; | ||||||
| import jakarta.validation.constraints.NotNull; | import jakarta.validation.constraints.NotNull; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
|  | @ -11,35 +13,22 @@ import java.util.List; | ||||||
| 
 | 
 | ||||||
| @Getter | @Getter | ||||||
| @Setter | @Setter | ||||||
|  | @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||||||
| public class GetProjectDto { | public class GetProjectDto { | ||||||
|     private long id; |     private long id; | ||||||
| 
 |  | ||||||
|     @NotBlank |  | ||||||
|     private String name; |     private String name; | ||||||
| 
 |  | ||||||
|     @NotNull |  | ||||||
|     private long leadingEmployee; |     private long leadingEmployee; | ||||||
| 
 |  | ||||||
|     private List<Long> employees; |     private List<Long> employees; | ||||||
| 
 |  | ||||||
|     @NotNull |  | ||||||
|     private long contractor; |     private long contractor; | ||||||
| 
 |  | ||||||
|     @NotBlank |  | ||||||
|     private String contractorName; |     private String contractorName; | ||||||
| 
 |  | ||||||
|     @NotBlank |  | ||||||
|     private String comment; |     private String comment; | ||||||
| 
 | 
 | ||||||
|     @NotNull |  | ||||||
|     @JsonFormat(pattern = "dd.MM.yyyy") |     @JsonFormat(pattern = "dd.MM.yyyy") | ||||||
|     private LocalDate startDate; |     private LocalDate startDate; | ||||||
| 
 | 
 | ||||||
|     @NotNull |  | ||||||
|     @JsonFormat(pattern = "dd.MM.yyyy") |     @JsonFormat(pattern = "dd.MM.yyyy") | ||||||
|     private LocalDate plannedEndDate; |     private LocalDate plannedEndDate; | ||||||
| 
 | 
 | ||||||
|     @NotNull |  | ||||||
|     @JsonFormat(pattern = "dd.MM.yyyy") |     @JsonFormat(pattern = "dd.MM.yyyy") | ||||||
|     private LocalDate endDate; |     private LocalDate endDate; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| package de.szut.lf8_starter.project; | package de.szut.lf8_starter.integration.project; | ||||||
| 
 | 
 | ||||||
|  | import de.szut.lf8_starter.project.ProjectRepository; | ||||||
| import org.json.JSONObject; | import org.json.JSONObject; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | @ -33,10 +34,10 @@ public class CreateProjectActionTest { | ||||||
|                     "leading_employee": 1, |                     "leading_employee": 1, | ||||||
|                     "employees": [2, 3], |                     "employees": [2, 3], | ||||||
|                     "contractor": 4, |                     "contractor": 4, | ||||||
|                    "contractorName": "Peter File", |                     "contractor_name": "Peter File", | ||||||
|                     "comment": "goal of project", |                     "comment": "goal of project", | ||||||
|                    "startDate": "01.01.2000", |                     "start_date": "01.01.2000", | ||||||
|                    "plannedEndDate": "01.01.2001" |                     "planned_end_date": "01.01.2001" | ||||||
|                   } |                   } | ||||||
|                 """; |                 """; | ||||||
| 
 | 
 | ||||||
|  | @ -45,13 +46,13 @@ public class CreateProjectActionTest { | ||||||
|         ) |         ) | ||||||
|                 .andExpect(status().isCreated()) |                 .andExpect(status().isCreated()) | ||||||
|                 .andExpect(jsonPath("name", is("name"))) |                 .andExpect(jsonPath("name", is("name"))) | ||||||
|                 .andExpect(jsonPath("leadingEmployee", is(0))) |                 .andExpect(jsonPath("leading_employee", is(1))) | ||||||
|                 .andExpect(jsonPath("employees", is(Arrays.asList(2, 3)))) |                 .andExpect(jsonPath("employees", is(Arrays.asList(2, 3)))) | ||||||
|                 .andExpect(jsonPath("contractor", is(4))) |                 .andExpect(jsonPath("contractor", is(4))) | ||||||
|                 .andExpect(jsonPath("contractorName", is("Peter File"))) |                 .andExpect(jsonPath("contractor_name", is("Peter File"))) | ||||||
|                 .andExpect(jsonPath("comment", is("goal of project"))) |                 .andExpect(jsonPath("comment", is("goal of project"))) | ||||||
|                 .andExpect(jsonPath("startDate", is("01.01.2000"))) |                 .andExpect(jsonPath("start_date", is("01.01.2000"))) | ||||||
|                 .andExpect(jsonPath("plannedEndDate", is("01.01.2001"))) |                 .andExpect(jsonPath("planned_end_date", is("01.01.2001"))) | ||||||
|                 .andReturn() |                 .andReturn() | ||||||
|                 .getResponse() |                 .getResponse() | ||||||
|                 .getContentAsString(); |                 .getContentAsString(); | ||||||
|  | @ -60,7 +61,7 @@ public class CreateProjectActionTest { | ||||||
| 
 | 
 | ||||||
|             final var project = this.projectRepository.findById(id); |             final var project = this.projectRepository.findById(id); | ||||||
|             assertThat(project.get().getName()).isEqualTo("name"); |             assertThat(project.get().getName()).isEqualTo("name"); | ||||||
|             assertThat(project.get().getLeadingEmployee()).isEqualTo(0); |             assertThat(project.get().getLeadingEmployee()).isEqualTo(1); | ||||||
|             assertThat(project.get().getContractor()).isEqualTo(4); |             assertThat(project.get().getContractor()).isEqualTo(4); | ||||||
|             assertThat(project.get().getContractorName()).isEqualTo("Peter File"); |             assertThat(project.get().getContractorName()).isEqualTo("Peter File"); | ||||||
|             assertThat(project.get().getComment()).isEqualTo("goal of project"); |             assertThat(project.get().getComment()).isEqualTo("goal of project"); | ||||||
		Reference in a new issue