From e55b1f778c723800b42ed590c21beea33bb33b10 Mon Sep 17 00:00:00 2001 From: skytin1004 Date: Tue, 19 Mar 2024 22:55:50 +0900 Subject: [PATCH] =?UTF-8?q?[feature/Inhabas#252]=20=EB=82=B4=EA=B0=80=20?= =?UTF-8?q?=EC=93=B4=20=EA=B8=80,=EB=8C=93=EA=B8=80,=20=EC=98=88=EC=82=B0?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=A1=B0=ED=9A=8C=20DTO=20test=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/domain/myInfo/dto/MyBoardsDto.java | 9 ++- .../dto/MyBudgetSupportApplicationDto.java | 23 +++++- .../api/domain/myInfo/dto/MyCommentsDto.java | 13 ++- .../inhabas/api/web/MyProfileController.java | 4 +- .../domain/myInfo/dto/MyBoardsDtoTest.java | 73 +++++++++++++++++ .../dto/MyBudgetSupportApplicationsTest.java | 79 +++++++++++++++++++ .../domain/myInfo/dto/MyCommentsDtoTest.java | 73 +++++++++++++++++ 7 files changed, 263 insertions(+), 11 deletions(-) create mode 100644 resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDtoTest.java create mode 100644 resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationsTest.java create mode 100644 resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDtoTest.java diff --git a/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDto.java b/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDto.java index c03f0290..34f78d9e 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDto.java @@ -1,5 +1,7 @@ package com.inhabas.api.domain.myInfo.dto; +import java.time.LocalDateTime; + import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Positive; @@ -18,6 +20,8 @@ public class MyBoardsDto { // 게시글 id @NotNull @Positive private Long id; + @NotNull private Integer menuId; + @NotNull private String menuName; @NotBlank private String title; @@ -25,11 +29,12 @@ public class MyBoardsDto { @NotNull @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") @Schema(type = "string", example = "2024-11-01T00:00:00") - String dateCreated; + private LocalDateTime dateCreated; @Builder - MyBoardsDto(Long id, String menuName, String title, String dateCreated) { + MyBoardsDto(Long id, Integer menuId, String menuName, String title, LocalDateTime dateCreated) { this.id = id; + this.menuId = menuId; this.menuName = menuName; this.title = title; this.dateCreated = dateCreated; diff --git a/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationDto.java b/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationDto.java index 12323127..32a39e85 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationDto.java @@ -1,29 +1,28 @@ package com.inhabas.api.domain.myInfo.dto; import java.time.LocalDateTime; -import java.util.List; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import com.fasterxml.jackson.annotation.JsonFormat; import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.RequestStatus; -import com.inhabas.api.domain.file.dto.FileDownloadDto; import io.swagger.v3.oas.annotations.media.Schema; @Getter @NoArgsConstructor public class MyBudgetSupportApplicationDto { + @NotNull private Long id; + @NotNull private RequestStatus status; @NotBlank private String title; - @NotNull private List receipts; - @NotNull @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") @Schema(type = "string", example = "2024-11-01T00:00:00") @@ -36,4 +35,20 @@ public class MyBudgetSupportApplicationDto { @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") @Schema(type = "string", example = "2024-11-01T00:00:00") private LocalDateTime dateDeposited; + + @Builder + MyBudgetSupportApplicationDto( + Long id, + RequestStatus status, + String title, + LocalDateTime dateCreated, + LocalDateTime dateChecked, + LocalDateTime dateDeposited) { + this.id = id; + this.status = status; + this.title = title; + this.dateCreated = dateCreated; + this.dateChecked = dateChecked; + this.dateDeposited = dateDeposited; + } } diff --git a/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDto.java b/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDto.java index 306db39f..de24f536 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDto.java @@ -1,5 +1,7 @@ package com.inhabas.api.domain.myInfo.dto; +import java.time.LocalDateTime; + import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Positive; @@ -11,9 +13,12 @@ public class MyCommentsDto { - // ParentsBoard의 id + // ParentsBoard의 게시판 id @NotNull @Positive private Long id; + // ParentsBoard의 menuId + @NotNull private Integer menuId; + // ParentsBoard의 메뉴 이름 @NotNull private String menuName; @@ -23,11 +28,13 @@ public class MyCommentsDto { @NotNull @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss") @Schema(type = "string", example = "2024-11-01T00:00:00") - String dateCreated; + private LocalDateTime dateCreated; @Builder - MyCommentsDto(Long id, String menuName, String content, String dateCreated) { + MyCommentsDto( + Long id, Integer menuId, String menuName, String content, LocalDateTime dateCreated) { this.id = id; + this.menuId = menuId; this.menuName = menuName; this.content = content; this.dateCreated = dateCreated; diff --git a/resource-server/src/main/java/com/inhabas/api/web/MyProfileController.java b/resource-server/src/main/java/com/inhabas/api/web/MyProfileController.java index fb43d54c..34e70065 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/MyProfileController.java +++ b/resource-server/src/main/java/com/inhabas/api/web/MyProfileController.java @@ -230,8 +230,6 @@ public ResponseEntity handleMyInfoRequest( return ResponseEntity.noContent().build(); } - // [모임, 글, 댓글, 예산신청 조회] 추후 개발 예정 - @Operation(summary = "내가 쓴 게시글 목록 조회") @ApiResponses( value = { @@ -310,4 +308,6 @@ public ResponseEntity> getCommentsList( return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtoList)); } + + // [모임, 강의 조회] 추후 개발 예정 } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDtoTest.java new file mode 100644 index 00000000..dee7d90c --- /dev/null +++ b/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBoardsDtoTest.java @@ -0,0 +1,73 @@ +package com.inhabas.api.domain.myInfo.dto; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.LocalDateTime; +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class MyBoardsDtoTest { + + private static ValidatorFactory validatorFactory; + private static Validator validator; + + @BeforeAll + public static void init() { + validatorFactory = Validation.buildDefaultValidatorFactory(); + validator = validatorFactory.getValidator(); + } + + @AfterAll + public static void close() { + validatorFactory.close(); + } + + @DisplayName("MyBoardsDto 객체를 정상적으로 생성한다.") + @Test + public void MyBoardsDto_is_OK() { + // given + MyBoardsDto myBoardsDto = + MyBoardsDto.builder() + .id(1L) + .menuId(16) + .menuName("알파 테스터") + .title("title") + .dateCreated(LocalDateTime.now()) + .build(); + + // when + Set> violations = validator.validate(myBoardsDto); + + // then + assertThat(violations).isEmpty(); + } + + @DisplayName("MyBoardsDto menuName 필드가 null 이면 validation 실패") + @Test + public void MenuName_is_null() { + // given + MyBoardsDto myBoardsDto = + MyBoardsDto.builder() + .id(1L) + .menuId(16) + .menuName(null) + .title("title") + .dateCreated(LocalDateTime.now()) + .build(); + + // when + Set> violations = validator.validate(myBoardsDto); + + // then + assertThat(violations).hasSize(1); + } +} diff --git a/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationsTest.java b/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationsTest.java new file mode 100644 index 00000000..d55b6254 --- /dev/null +++ b/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyBudgetSupportApplicationsTest.java @@ -0,0 +1,79 @@ +package com.inhabas.api.domain.myInfo.dto; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.LocalDateTime; +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; + +import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.RequestStatus; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class MyBudgetSupportApplicationsTest { + + private static ValidatorFactory validatorFactory; + private static Validator validator; + + @BeforeAll + public static void init() { + validatorFactory = Validation.buildDefaultValidatorFactory(); + validator = validatorFactory.getValidator(); + } + + @AfterAll + public static void close() { + validatorFactory.close(); + } + + @DisplayName("MyBudgetSupportApplicationsDto 객체를 정상적으로 생성한다.") + @Test + public void MyBoardsDto_is_OK() { + // given + MyBudgetSupportApplicationDto myBudgetSupportApplicationDto = + MyBudgetSupportApplicationDto.builder() + .id(1L) + .status(RequestStatus.COMPLETED) + .title("예산신청 제목") + .dateCreated(LocalDateTime.now()) + .dateChecked(LocalDateTime.now()) + .dateDeposited(LocalDateTime.now()) + .build(); + + // when + Set> violations = + validator.validate(myBudgetSupportApplicationDto); + + // then + assertThat(violations).isEmpty(); + } + + @DisplayName("MyBudgetSupportApplicationsDto status 필드가 null 이면 validation 실패") + @Test + public void MenuName_is_null() { + // given + MyBudgetSupportApplicationDto myBudgetSupportApplicationDto = + MyBudgetSupportApplicationDto.builder() + .id(1L) + .status(null) + .title("예산신청 제목") + .dateCreated(LocalDateTime.now()) + .dateChecked(LocalDateTime.now()) + .dateDeposited(LocalDateTime.now()) + .build(); + + // when + Set> violations = + validator.validate(myBudgetSupportApplicationDto); + + // then + assertThat(violations).hasSize(1); + } +} diff --git a/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDtoTest.java new file mode 100644 index 00000000..c3e40c4f --- /dev/null +++ b/resource-server/src/test/java/com/inhabas/api/domain/myInfo/dto/MyCommentsDtoTest.java @@ -0,0 +1,73 @@ +package com.inhabas.api.domain.myInfo.dto; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.LocalDateTime; +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class MyCommentsDtoTest { + + private static ValidatorFactory validatorFactory; + private static Validator validator; + + @BeforeAll + public static void init() { + validatorFactory = Validation.buildDefaultValidatorFactory(); + validator = validatorFactory.getValidator(); + } + + @AfterAll + public static void close() { + validatorFactory.close(); + } + + @DisplayName("MyCommentsDto 객체를 정상적으로 생성한다.") + @Test + public void MyCommentsDto_is_OK() { + // given + MyCommentsDto myCommentsDto = + MyCommentsDto.builder() + .id(1L) + .menuId(16) + .menuName("알파 테스터") + .content("댓글 내용") + .dateCreated(LocalDateTime.now()) + .build(); + + // when + Set> violations = validator.validate(myCommentsDto); + + // then + assertThat(violations).isEmpty(); + } + + @DisplayName("MyCommentsDto content 필드가 blank 이면 validation 실패") + @Test + public void Content_is_blank() { + // given + MyCommentsDto myCommentsDto = + MyCommentsDto.builder() + .id(1L) + .menuId(16) + .menuName("알파 테스터") + .content("") + .dateCreated(LocalDateTime.now()) + .build(); + + // when + Set> violations = validator.validate(myCommentsDto); + + // then + assertThat(violations).hasSize(1); + } +}