Skip to content

Commit

Permalink
[feature/Inhabas#252] 내가 쓴 글,댓글, 예산신청 조회 DTO test 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
skytin1004 committed Mar 19, 2024
1 parent 4191092 commit e55b1f7
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,18 +20,21 @@ public class MyBoardsDto {
// 게시글 id
@NotNull @Positive private Long id;

@NotNull private Integer menuId;

@NotNull private String menuName;

@NotBlank private String title;

@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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FileDownloadDto> receipts;

@NotNull
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
@Schema(type = "string", example = "2024-11-01T00:00:00")
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ public ResponseEntity<Void> handleMyInfoRequest(
return ResponseEntity.noContent().build();
}

// [모임, 글, 댓글, 예산신청 조회] 추후 개발 예정

@Operation(summary = "내가 쓴 게시글 목록 조회")
@ApiResponses(
value = {
Expand Down Expand Up @@ -310,4 +308,6 @@ public ResponseEntity<PagedResponseDto<MyCommentsDto>> getCommentsList(

return ResponseEntity.ok(new PagedResponseDto<>(pageInfoDto, pagedDtoList));
}

// [모임, 강의 조회] 추후 개발 예정
}
Original file line number Diff line number Diff line change
@@ -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<ConstraintViolation<MyBoardsDto>> 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<ConstraintViolation<MyBoardsDto>> violations = validator.validate(myBoardsDto);

// then
assertThat(violations).hasSize(1);
}
}
Original file line number Diff line number Diff line change
@@ -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<ConstraintViolation<MyBudgetSupportApplicationDto>> 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<ConstraintViolation<MyBudgetSupportApplicationDto>> violations =
validator.validate(myBudgetSupportApplicationDto);

// then
assertThat(violations).hasSize(1);
}
}
Original file line number Diff line number Diff line change
@@ -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<ConstraintViolation<MyCommentsDto>> 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<ConstraintViolation<MyCommentsDto>> violations = validator.validate(myCommentsDto);

// then
assertThat(violations).hasSize(1);
}
}

0 comments on commit e55b1f7

Please sign in to comment.