From a14b33bb9fe0d6f23a15f4dca3a97ee766415a7c Mon Sep 17 00:00:00 2001 From: Jangan Lee Date: Wed, 13 Nov 2024 06:12:46 +0900 Subject: [PATCH] =?UTF-8?q?[Weekly/11/Refactor/Test-TeatData]=20testdata?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81=20(#120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Image/api/dto/ImageRequest.java | 6 +- .../AdvertisementImageService.java | 2 +- .../application/CurationImageService.java | 2 +- .../Image/application/EventImageService.java | 2 +- .../Image/application/MemberImageService.java | 2 +- .../_common/error/GlobalExceptionHandler.java | 1 + .../cokaen/wouldyouin/_global/TestData.java | 140 ------- .../_global/mockMember/WithMockCurator.java | 4 +- .../_global/mockMember/WithMockHost.java | 4 +- .../_global/mockMember/WithMockMember.java | 4 +- .../mockMember/WithMockWelcomeMember.java | 4 +- .../_global/testdata/CommonData.java | 17 + .../_global/testdata/CurationData.java | 266 ++++++++---- .../_global/testdata/EventData.java | 130 ++++++ .../_global/testdata/ImageData.java | 395 +++++++++++++----- .../_global/testdata/MemberData.java | 274 ++++++++---- .../_global/testdata/ReservationData.java | 77 ++++ .../curation/CurationControllerUnitTest.java | 73 ++-- .../curation/CurationServiceTest.java | 26 +- .../event/EventControllerUnitTest.java | 19 +- .../event/EventServiceUnitTest.java | 26 +- .../wouldyouin/image/ImageControllerTest.java | 19 +- .../BaseMemberServiceUnitTest.java | 31 +- .../application/CuratorServiceUnitTest.java | 7 +- .../application/HostServiceUnitTest.java | 8 +- .../application/MemberServiceUnitTest.java | 11 +- .../ReservationControllerUnitTest.java | 38 +- 27 files changed, 1050 insertions(+), 538 deletions(-) delete mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java create mode 100644 src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java index 2825c2dd..15dda0cd 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/api/dto/ImageRequest.java @@ -7,13 +7,13 @@ @Builder public class ImageRequest { - private String url; + private String name; private Long size; private String extension; - public static ImageRequest of(String url, Long size, String extension) { + public static ImageRequest of(String name, Long size, String extension) { return ImageRequest.builder() - .url(url) + .name(name) .size(size) .extension(extension) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java index a1fa43ef..40403f31 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/AdvertisementImageService.java @@ -42,7 +42,7 @@ protected String getChildPath() { @Override protected AdvertisementImage toEntity(ImageRequest imageRequest) { return AdvertisementImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java index ab1d9a81..f9051050 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/CurationImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { @Override protected CurationImage toEntity(ImageRequest imageRequest) { return CurationImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java index db64e62a..72b982b8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/EventImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { @Override protected EventImage toEntity(ImageRequest imageRequest) { return EventImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index 7ada23a5..2e8ed906 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -40,7 +40,7 @@ protected String getChildPath() { @Override protected MemberImage toEntity(ImageRequest imageRequest) { return MemberImage.builder() - .name(imageRequest.getUrl()) + .name(imageRequest.getName()) .size(imageRequest.getSize()) .extension(imageRequest.getExtension()) .build(); diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java index 185ba406..ebe4de5e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/GlobalExceptionHandler.java @@ -33,6 +33,7 @@ public ResponseEntity> handleMethodArgumentTypeMismatchExc public ResponseEntity> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { return ApiResponse.error(ErrorCode.INVALID_INPUT_VALUE, e.getBindingResult().getFieldErrors().stream() .map(DefaultMessageSourceResolvable::getDefaultMessage) +// .map((reslover) -> "필드명: " + reslover.getField() + reslover.getDefaultMessage()) .collect(Collectors.joining(", "))); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java deleted file mode 100644 index 38f06c9f..00000000 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.ktc2.cokaen.wouldyouin._global; - -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidReservationMemberResponse; - -import java.time.LocalDateTime; -import java.util.List; -import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; -import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._common.vo.Location; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; -import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; -import org.ktc2.cokaen.wouldyouin.event.persist.Event; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; -import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; -import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; -import org.springframework.test.util.ReflectionTestUtils; - -public class TestData { - - public static SliceInfo createSliceInfo() { - return SliceInfo.builder() - .sliceSize(10) - .lastId(100L) - .build(); - } - - public static class EventDomain { - - public static Event createValidEvent() { - Event validEvent = Event.builder() - .title("title") - .content("content") - .area(Area.전체) - .location(new Location(132.0, 43.0, "광주 북구 용봉로77")) - .startTime(LocalDateTime.now()) - .endTime(LocalDateTime.now()) - .price(10000) - .totalSeat(100) - .category(Category.밴드) - .build(); - validEvent.setHost(createValidHost()); - ReflectionTestUtils.setField(validEvent, "id", 201L); - return validEvent; - } - - public static EventCreateRequest createValidEventCreateRequest() { - return EventCreateRequest.builder() - .title("title") - .content("content 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요.") - .area(Area.전체) - .location(new Location(55.0, 43.0, "광주 북구 용봉로 77")) - .startTime(LocalDateTime.of(2025, 10, 1, 9, 0)) - .endTime(LocalDateTime.of(2025, 10, 1, 10, 0)) - .price(10000) - .totalSeat(100) - .category(Category.밴드) - .imageIds(List.of()) - .build(); - } - - public static EventEditRequest createValidEventEditRequest() { - return EventEditRequest.builder() - .title("modifiedTitle") - .content("modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. ") - .area(Area.광주) - .location(new Location(232.0, 143.0, "광주 북구 용봉로 77")) - .startTime(LocalDateTime.of(2024, 10, 2, 17, 0)) - .endTime(LocalDateTime.of(2024, 10, 2, 18, 0)) - .price(20000) - .totalSeat(200) - .category(Category.뮤지컬) - .imageIds(List.of()) - .build(); - } - - public static CurationEventResponse createValidCurationEventResponse() { - return CurationEventResponse.builder() - .id(1L) - .title("title") - .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) - .thumbnailImageUrl("thumbnailImageUrl") - .hostProfileImageUrl("hostProfileImageUrl") - .hostNickname("nick_curator_12") - .build(); - } - - public static ReservationEventResponse createValidReservationEventResponse() { - return ReservationEventResponse.builder() - .id(1L) - .title("title") - .price(15000) - .build(); - } - } - - public static class ReservationDomain { - - public static ReservationRequest createValidReservationRequest() { - return ReservationRequest.builder() - .eventId(1L) - .quantity(2) - .build(); - } - - public static Reservation createValidReservation() { - Reservation reservation = Reservation.builder() - .member(createValidMember()) - .event(EventDomain.createValidEvent()) - .price(15000) - .quantity(2) - .build(); - ReflectionTestUtils.setField(reservation, "id", 1L); - return reservation; - } - - public static ReservationResponse createValidReservationResponse() { - return ReservationResponse.builder() - .id(1L) - .member(createValidReservationMemberResponse()) - .event(EventDomain.createValidReservationEventResponse()) - .price(15000) - .quantity(2) - .reservationDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); - } - - public static ReservationSliceResponse createValidReservationSliceResponse() { - return ReservationSliceResponse.builder() - .reservations(List.of(createValidReservationResponse())) - .sliceInfo(TestData.createSliceInfo()) - .build(); - } - } -} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java index e07aa771..a44df782 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockCurator.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validCuratorId, memberType = MemberType.curator) +@WithMockCustomUser(memberId = curator.id, memberType = MemberType.curator) public @interface WithMockCurator { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java index 2a84fd47..a92d6950 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockHost.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validHostId, memberType = MemberType.host) +@WithMockCustomUser(memberId = host.id, memberType = MemberType.host) public @interface WithMockHost { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java index 6b71ff00..4e5cbe8d 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockMember.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validMemberId, memberType = MemberType.normal) +@WithMockCustomUser(memberId = normal.id, memberType = MemberType.normal) public @interface WithMockMember { } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java index 4dc60ff8..951a6cf2 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/mockMember/WithMockWelcomeMember.java @@ -2,11 +2,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome; import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; @Retention(RetentionPolicy.RUNTIME) -@WithMockCustomUser(memberId = MemberData.validWelcomeMemberId, memberType = MemberType.welcome) +@WithMockCustomUser(memberId = welcome.id, memberType = MemberType.welcome) public @interface WithMockWelcomeMember { } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java new file mode 100644 index 00000000..8fa8fcc7 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CommonData.java @@ -0,0 +1,17 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import org.ktc2.cokaen.wouldyouin._common.api.SliceInfo; + +public class CommonData { + + public static class sliceInfo { + + public static SliceInfo get() { + return SliceInfo.builder() + .sliceSize(10) + .lastId(100L) + .build(); + } + } + +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java index a32b9cb7..dfcd2107 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/CurationData.java @@ -1,12 +1,11 @@ package org.ktc2.cokaen.wouldyouin._global.testdata; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; - import java.time.LocalDateTime; import java.util.List; +import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; -import org.ktc2.cokaen.wouldyouin._global.TestData; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationCard1; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.R.curationEditRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardRequest; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCardResponse; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -15,94 +14,195 @@ import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationSliceResponse; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; import org.ktc2.cokaen.wouldyouin.curation.persist.CurationCard; -import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.springframework.test.util.ReflectionTestUtils; public class CurationData { - public static CurationCardRequest createValidCurationCardRequest1() { - return CurationCardRequest.builder() - .subtitle("큐레이션 카드 부제목1") - .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageIds(List.of(1301L)) - .build(); - } - - public static CurationCardRequest createValidCurationCardRequest2() { - return CurationCardRequest.builder() - .subtitle("큐레이션 카드 부제목2") - .content("큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") - .imageIds(List.of(1302L)) - .build(); - } - - public static CurationCard createValidCurationCard1() { - CurationCard validCurationCard1 = - createValidCurationCardRequest1().toEntity(List.of(ImageData.createValidCurationImage1())); - ReflectionTestUtils.setField(validCurationCard1, "id", 351L); -// ReflectionTestUtils.setField(validCurationCard1, "curation", createValidCuration()); - return validCurationCard1; - } - - public static CurationCard createValidCurationCard2() { - CurationCard validCurationCard2 = - createValidCurationCardRequest2().toEntity(List.of(ImageData.createValidCurationImage2())); - ReflectionTestUtils.setField(validCurationCard2, "id", 352L); -// ReflectionTestUtils.setField(validCurationCard1, "curation", createValidCuration()); - return validCurationCard2; - } - - public static CurationCardResponse createValidCurationCardResponse1() { - return CurationCardResponse.from(createValidCurationCard1()); - } - - public static CurationCardResponse createValidCurationCardResponse2() { - return CurationCardResponse.from(createValidCurationCard2()); - } - - public static CurationCreateRequest createValidCurationCreateRequest() { - return CurationCreateRequest.builder() - .title("큐레이션 제목") - .content("큐레이션 본문") - .curationCards(List.of(createValidCurationCardRequest1())) - .area(Area.전체) - .hashtags(List.of("#큐레이션", "#해시태그")) - .eventIds(List.of(201L)) - .build(); - } - - public static CurationEditRequest createValidCurationEditRequest() { - return CurationEditRequest.builder() - .title("큐레이션 제목 수정") - .content("큐레이션 본문 수정") - .curationCards(List.of(createValidCurationCardRequest2())) - .area(Area.광주) - .hashtags(List.of("수정 해시태그")) - .eventIds(List.of(202L)) - .build(); - } - - public static Curation createValidCuration() { - Curation validCuration = createValidCurationCreateRequest().toEntity( - createValidCurator(), List.of(createValidCurationCard1()), List.of(EventDomain.createValidEvent())); - ReflectionTestUtils.setField(validCuration, "id", 301L); - ReflectionTestUtils.setField(validCuration, "createdDate", LocalDateTime.of(2023, 3, 23, 0, 0)); - ReflectionTestUtils.setField(validCuration, "modifiedDate", LocalDateTime.of(2024, 3, 23, 0, 0)); - return validCuration; + public static class R { + public static class curationCard1 { + public static final Long id = 351L; + public static final String subtitle = "큐레이션 카드 부제목1"; + public static final String content = "큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; + public static final List images = List.of(ImageData.curation1.entity.get()); + public static final List imageIds = List.of(1301L); + public static final List imageUrls = List.of("wouldyouin.com/curationImage1.jpg"); + } + public static class curationCard2 { + public static final Long id = 352L; + public static final String subtitle = "큐레이션 카드 부제목2"; + public static final String content = "큐레이션 카드 내용2 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다."; + public static final List imageIds = List.of(1302L); + public static final List imageUrls = List.of("wouldyouin.com/curationImage2.jpg"); + } + public static class curation { + public static final Long id = 301L; + public static final String title = "큐레이션 제목"; + public static final String content = "큐레이션 본문 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; + public static final List curationCards = List.of( + CurationData.curationCard1.entity.get(), + CurationData.curationCard2.entity.get() + ); + public static final List curationCardRequests = List.of( + CurationData.curationCard1.request.get(), + CurationData.curationCard2.request.get() + ); + public static final List curationCardResponses = List.of( + CurationData.curationCard1.response.get(), + CurationData.curationCard2.response.get() + ); + public static final Area area = Area.전체; + public static final List hashtags = List.of("#큐레이션", "#해시태그"); + public static final List eventIds = List.of(201L); + public static final List events = List.of(EventData.event.entity.get()); + public static final LocalDateTime createdDate = LocalDateTime.of(2023, 3, 23, 0, 0); + public static final LocalDateTime modifiedDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curationEditRequest { + public static final String title = "큐레이션 제목 수정"; + public static final String content = "수정된 큐레이션 본문 입니다. 큐레이션의 본문은 최소 20자 최대 1000자 입니다."; + public static final List curationCardRequests = List.of( + CurationData.curationCard2.request.get() + ); + public static final Area area = Area.광주; + public static final List hashtags = List.of("수정 해시태그"); + public static final List eventIds = List.of(202L); + } } - public static CurationCuratorResponse createValidCurationCuratorResponse() { - return CurationCuratorResponse.from(createValidCurator()); + public static class curationCard1 { + public static class entity { + public static CurationCard get() { + CurationCard validCurationCard1 = CurationCard.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard2.content) + // .curation(createValidCuration()) + .images(R.curationCard1.images) + .build(); + ReflectionTestUtils.setField(validCurationCard1, "id", R.curationCard1.id); + return validCurationCard1; + } + } + public static class request { + public static CurationCardRequest get() { + return CurationCardRequest.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard1.content) + .imageIds(R.curationCard1.imageIds) + .build(); + } + } + public static class response { + public static CurationCardResponse get() { + return CurationCardResponse.builder() + .subtitle(R.curationCard1.subtitle) + .content(R.curationCard1.content) + .imageUrls(R.curationCard1.imageUrls) + .build(); + } + } } - public static CurationResponse createValidCurationResponse() { - return CurationResponse.from(createValidCuration()); + public static class curationCard2 { + public static class entity { + public static CurationCard get() { + CurationCard validCurationCard2 = CurationCard.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + // .curation(createValidCuration()) + .images(List.of(ImageData.curation2.entity.get())) + .build(); + ReflectionTestUtils.setField(validCurationCard2, "id", R.curationCard2.id); + return validCurationCard2; + } + } + public static class request { + public static CurationCardRequest get() { + return CurationCardRequest.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + .imageIds(R.curationCard2.imageIds) + .build(); + } + } + public static class response { + public static CurationCardResponse get() { + return CurationCardResponse.builder() + .subtitle(R.curationCard2.subtitle) + .content(R.curationCard2.content) + .imageUrls(R.curationCard2.imageUrls) + .build(); + } + } } - public static CurationSliceResponse createValidCurationSliceResponse() { - return CurationSliceResponse.builder() - .curations(List.of(createValidCurationResponse())) - .sliceInfo(TestData.createSliceInfo()) - .build(); + public static class curation { + public static class entity { + public static Curation get() { + Curation validCuration = Curation.builder() + .curator(MemberData.curator.entity.get()) + .title(R.curation.title) + .content(R.curation.content) + .curationCards(R.curation.curationCards) + .area(R.curation.area) + .hashtags(R.curation.hashtags) + .events(R.curation.events) + .build(); + ReflectionTestUtils.setField(validCuration, "id", R.curation.id); + ReflectionTestUtils.setField(validCuration, "createdDate", R.curation.createdDate); + ReflectionTestUtils.setField(validCuration, "modifiedDate", R.curation.modifiedDate); + return validCuration; + } + } + public static class request { + public static class create { + public static CurationCreateRequest get() { + return CurationCreateRequest.builder() + .title(R.curation.title) + .content(R.curation.content) + .curationCards(R.curation.curationCardRequests) + .area(R.curation.area) + .hashtags(R.curation.hashtags) + .eventIds(R.curation.eventIds) + .build(); + } + } + public static class edit { + public static CurationEditRequest get() { + return CurationEditRequest.builder() + .title(curationEditRequest.title) + .content(curationEditRequest.content) + .curationCards(curationEditRequest.curationCardRequests) + .area(curationEditRequest.area) + .hashtags(curationEditRequest.hashtags) + .eventIds(curationEditRequest.eventIds) + .build(); + } + } + } + public static class response { + public static CurationResponse get() { + return CurationResponse.builder() + .id(R.curation.id) + //.curator(MemberData.dto.response.curationCurator.get()) + .title(R.curation.title) + .content(R.curation.content) + .curationCards(R.curation.curationCardResponses) + .area(R.curation.area) + .hashtags(R.curation.hashtags) + //.eventsInfo(List.of(EventDomain.createValidCurationEventResponse())) + .createdTime(R.curation.createdDate) + .modifiedDate(R.curation.modifiedDate) + .build(); + } + public static class slice { + public static CurationSliceResponse get() { + return CurationSliceResponse.builder() + .curations(List.of(response.get())) + .sliceInfo(CommonData.sliceInfo.get()) + .build(); + } + } + } } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java new file mode 100644 index 00000000..5babf5d3 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/EventData.java @@ -0,0 +1,130 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.time.LocalDateTime; +import java.util.List; +import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin._common.vo.Category; +import org.ktc2.cokaen.wouldyouin._common.vo.Location; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.CurationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.springframework.test.util.ReflectionTestUtils; + +public class EventData { + + public static class R { + + public static class event { + public static final long id = 201L; + public static final String title = "행사 제목"; + public static final String content = "행사 내용입니다. 행사의 내용은 최소 20자 최대 1000자 입니다."; + public static final Area area = Area.전체; + public static final Location location = new Location(55.0, 43.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = LocalDateTime.now().plusDays(3).plusHours(11).plusMinutes(47); + public static final LocalDateTime endTime = startTime.plusWeeks(2); + public static final int price = 15000; + public static final int totalSeat = 100; + public static final Category category = Category.밴드; + + public static final String hostNickname = MemberData.R.host.nickname; + public static final String hostProfileImageUrl = ImageData.R.member.host.url; + public static final String thumbnailImageUrl = "ImageData.R.event.thumbnail.url"; + } + public static class eventEditRequest { + public static final String title = "modifiedTitle"; + public static final String content = "modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. "; + public static final Area area = Area.광주; + public static final Location location = new Location(45.0, 143.0, "광주 북구 용봉로 77"); + public static final LocalDateTime startTime = event.startTime.plusDays(2); + public static final LocalDateTime endTime = startTime.plusWeeks(3); + public static final int price = 20000; + public static final int totalSeat = 200; + public static final Category category = Category.뮤지컬; + } + } + + public static class event { + public static class entity { + public static Event get() { + Event ret = Event.builder() + .title(R.event.title) + .content(R.event.content) + .area(R.event.area) + .location(R.event.location) + .startTime(R.event.startTime) + .endTime(R.event.endTime) + .price(R.event.price) + .totalSeat(R.event.totalSeat) + .category(R.event.category) + .build(); + ret.setHost(MemberData.host.entity.get()); + ReflectionTestUtils.setField(ret, "id", R.event.id); + return ret; + } + } + public static class request { + public static class create { + public static EventCreateRequest get() { + return EventCreateRequest.builder() + .title(R.event.title) + .content(R.event.content) + .area(R.event.area) + .location(R.event.location) + .startTime(R.event.startTime) + .endTime(R.event.endTime) + .price(R.event.price) + .totalSeat(R.event.totalSeat) + .category(R.event.category) + .imageIds(List.of()) + .build(); + } + } + public static class edit { + public static EventEditRequest get() { + return EventEditRequest.builder() + .title(R.eventEditRequest.title) + .content(R.eventEditRequest.content) + .area(R.eventEditRequest.area) + .location(R.eventEditRequest.location) + .startTime(R.eventEditRequest.startTime) + .endTime(R.eventEditRequest.endTime) + .price(R.eventEditRequest.price) + .totalSeat(R.eventEditRequest.totalSeat) + .category(R.eventEditRequest.category) + .imageIds(List.of()) + .build(); + } + } + } + public static class response { + + } + } + + public static class response { + public static class reservationEvent { + public static ReservationEventResponse createValidReservationEventResponse() { + return ReservationEventResponse.builder() + .eventId(R.event.id) + .title(R.event.title) + .price(R.event.price) + .build(); + } + } + public static class curationEvent { + public static CurationEventResponse createValidCurationEventResponse() { + return CurationEventResponse.builder() + .eventId(R.event.id) + .title(R.event.title) + .location(R.event.location) + .thumbnailImageUrl(R.event.thumbnailImageUrl) + .hostProfileImageUrl(R.event.hostProfileImageUrl) + .hostNickname(R.event.hostNickname) + .build(); + } + } + } + +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java index 11e047d6..a35eaff2 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ImageData.java @@ -6,6 +6,7 @@ import org.ktc2.cokaen.wouldyouin.Image.persist.AdvertisementImage; import org.ktc2.cokaen.wouldyouin.Image.persist.CurationImage; import org.ktc2.cokaen.wouldyouin.Image.persist.EventImage; +import org.ktc2.cokaen.wouldyouin.Image.persist.Image; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; @@ -13,123 +14,319 @@ public class ImageData { - public static final long validMemberImageId = 1101L; - public static final long validEventImageId = 1201L; - public static final long validCurationImageId = 1301L; - public static final long validAdImageId = 1401L; - - public static MemberImage createValidMemberImage() { - MemberImage validMemberImage = MemberImage.builder() - .url("member/memberImage.jpg") - .size(10L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validMemberImage, "id", 1101L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validMemberImage; - } + // name: 파일 이름만 있어야 함 => entity, request + // 예: memberImage1.png + // url: 도메인 그거 => response + // 예: https://localhost:8080/images/member/Image1.png - public static EventImage createValidEventImage() { - EventImage validEventImage = EventImage.builder() - .url("event/eventImage.jpg") - .size(20L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validEventImage, "id", 1201L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validEventImage; + public static class R { + public static class member { + public static class normal { + public static final Long id = 1101L; + public static final String name = "memberImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 11000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curator { + public static final Long id = 1102L; + public static final String name = "curatorImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 12000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class host { + public static final Long id = 1103L; + public static final String name = "hostImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 13000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class welcome { + public static final Long id = 1104L; + public static final String name = "welcomeImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 14000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + } + public static class event { + public static final Long id = 1201L; + public static final String name = "eventImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 22000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation1 { + public static final Long id = 1301L; + public static final String name = "curationImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 31000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class curation2 { + public static final Long id = 1302L; + public static final String name = "curationImage2.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 32000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class advertisement { + public static final Long id = 1401L; + public static final String name = "adImage1.jpg"; + public static final String url = "https://wouldyouin.store/api/images/" + name; + public static final Long size = 40000L; + public static final String extension = ".jpg"; + public static final LocalDateTime createdDate = LocalDateTime.of(2024, 3, 23, 0, 0); + } + public static class mockMultipartFile1 { + public static final String name = "images"; + public static final String originalFileName = "image1.jpg"; + public static final String contentType = MediaType.IMAGE_JPEG_VALUE; + public static final byte[] content = "imageData1".getBytes(); + } + public static class mockMultipartFile2 { + public static final String name = "images"; + public static final String originalFileName = "image2.png"; + public static final String contentType = MediaType.IMAGE_JPEG_VALUE; + public static final byte[] content = "imageData2".getBytes(); + } } - public static CurationImage createValidCurationImage1() { - CurationImage validCurationImage = CurationImage.builder() - .url("curation/curationImage1.jpg") - .size(30L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validCurationImage, "id", 1301L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validCurationImage; + private static void setImageFields(Image image, Long id, LocalDateTime createdDate) { + ReflectionTestUtils.setField(image, "id", id); + ReflectionTestUtils.setField(image, "createdDate", createdDate); } - public static CurationImage createValidCurationImage2() { - CurationImage validCurationImage = CurationImage.builder() - .url("curation/curationImage2.jpg") - .size(30L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validCurationImage, "id", 1302L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validCurationImage; - } + public static class member { + public static class normal { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.normal.name) + .size(R.member.normal.size) + .extension(R.member.normal.extension) + .build(); + setImageFields(ret, R.member.normal.id, R.member.normal.createdDate); + // ReflectionTestUtils.setField(ret, "baseMember", createValidMember()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.member.normal.url) + .size(R.member.normal.size) + .extension(R.member.normal.extension) + .build(); + } + } + public static class response { - public static AdvertisementImage createValidAdImage() { - AdvertisementImage validAdImage = AdvertisementImage.builder() - .url("curation/curationImage.jpg") - .size(40L) - .extension(".jpg") - .build(); - ReflectionTestUtils.setField(validAdImage, "id", 1401L); -// ReflectionTestUtils.setField(validMemberImage, "baseMember", MemberDomain.createValidMember()); - return validAdImage; - } + } + } + public static class curator { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.curator.name) + .size(R.member.curator.size) + .extension(R.member.curator.extension) + .build(); + setImageFields(ret, R.member.curator.id, R.member.curator.createdDate); + // ReflectionTestUtils.setField(ret, "baseMember", createValidCurator()); + return ret; + } + } + public static class request { - public static ImageRequest createValidMemberImageRequest() { - return ImageRequest.builder() - .url("member/memberImage.jpg") - .size(10L) - .extension(".jpg") - .build(); - } + } + public static class response { + + } + } + public static class host { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.host.name) + .size(R.member.host.size) + .extension(R.member.host.extension) + .build(); + setImageFields(ret, R.member.host.id, R.member.host.createdDate); + // ReflectionTestUtils.setField(ret, "baseMember", createValidHost()); + return ret; + } + } + public static class request { + + } + public static class response { - public static ImageRequest createValidEventImageRequest() { - return ImageRequest.builder() - .url("event/eventImage.jpg") - .size(20L) - .extension(".jpg") - .build(); + } + } + public static class welcome { + public static class entity { + public static MemberImage get() { + MemberImage ret = MemberImage.builder() + .name(R.member.welcome.name) + .size(R.member.welcome.size) + .extension(R.member.welcome.extension) + .build(); + setImageFields(ret, R.member.welcome.id, R.member.welcome.createdDate); + // ReflectionTestUtils.setField(validMemberImage, "baseMember", createValidWelcome()); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } } - public static ImageRequest createValidCurationImageRequest() { - return ImageRequest.builder() - .url("curation/curationImage.jpg") - .size(30L) - .extension(".jpg") - .build(); + public static class event { + public static class entity { + public static EventImage get() { + EventImage ret = EventImage.builder() + .name(R.event.name) + .size(R.event.size) + .extension(R.event.extension) + .build(); + setImageFields(ret, R.event.id, R.event.createdDate); +// ReflectionTestUtils.setField(ret, "event", createValidEvent()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.event.name) + .size(R.event.size) + .extension(R.event.extension) + .build(); + } + } + public static class response { + + } } - public static ImageRequest createValidAdImageRequest() { - return ImageRequest.builder() - .url("ad/adImage.jpg") - .size(40L) - .extension(".jpg") - .build(); + public static class curation1 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation1.name) + .size(R.curation1.size) + .extension(R.curation1.extension) + .build(); + setImageFields(ret, R.curation1.id, R.curation1.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.curation1.name) + .size(R.curation1.size) + .extension(R.curation1.extension) + .build(); + } + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation1.id) + .url(R.curation1.url) + .size(R.curation1.size) + .extension(R.curation1.extension) + .createdDate(R.curation1.createdDate) + .build(); + } + } } - public static ImageResponse createValidImageResponse1() { - return ImageResponse.builder() - .id(1L) - .url("curationImageUrl.jpg") - .size(10L) - .extension(".jpg") - .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); + public static class curation2 { + public static class entity { + public static CurationImage get() { + CurationImage ret = CurationImage.builder() + .name(R.curation2.name) + .size(R.curation2.size) + .extension(R.curation2.extension) + .build(); + setImageFields(ret, R.curation2.id, R.curation2.createdDate); + // ReflectionTestUtils.setField(ret, "curationCard", createValidCurator()); + return ret; + } + } + public static class request { + + } + public static class response { + public static ImageResponse get() { + return ImageResponse.builder() + .id(R.curation2.id) + .url(R.curation2.url) + .size(R.curation2.size) + .extension(R.curation2.extension) + .createdDate(R.curation2.createdDate) + .build(); + } + } } - public static ImageResponse createValidImageResponse2() { - return ImageResponse.builder() - .id(2L) - .url("memberImage.png") - .size(20L) - .extension(".png") - .createdDate(LocalDateTime.of(2024, 3, 23, 0, 0)) - .build(); + public static class advertisement { + public static class entity { + public static AdvertisementImage get() { + AdvertisementImage ret = AdvertisementImage.builder() + .name(R.advertisement.name) + .size(R.advertisement.size) + .extension(R.advertisement.extension) + .build(); + setImageFields(ret, R.advertisement.id, R.advertisement.createdDate); + // ReflectionTestUtils.setField(ret, "advertisement", createValidMember()); + return ret; + } + } + public static class request { + public static ImageRequest get() { + return ImageRequest.builder() + .name(R.advertisement.name) + .size(R.advertisement.size) + .extension(R.advertisement.extension) + .build(); + } + } } - public static MockMultipartFile createValidMultipartFile1() { - return new MockMultipartFile("images", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); + public static class mockMultipartFile1 { + public static MockMultipartFile get() { + return new MockMultipartFile( + R.mockMultipartFile1.name, + R.mockMultipartFile1.originalFileName, + R.mockMultipartFile1.contentType, + R.mockMultipartFile1.content); + } } - public static MockMultipartFile createValidMultipartFile2() { - return new MockMultipartFile("images", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); + public static class mockMultipartFile2 { + public static MockMultipartFile get() { + return new MockMultipartFile( + R.mockMultipartFile2.name, + R.mockMultipartFile2.originalFileName, + R.mockMultipartFile2.contentType, + R.mockMultipartFile2.content); + } } -} + +} \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java index d4581c38..22c94d7e 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/MemberData.java @@ -3,7 +3,9 @@ import java.util.List; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.vo.Area; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.CurationCuratorResponse; import org.ktc2.cokaen.wouldyouin.member.persist.AccountType; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.Host; @@ -13,89 +15,209 @@ public class MemberData { - public static final long validMemberId = 101L; - public static final long validCuratorId = 102L; - public static final long validHostId = 103L; - public static final long validWelcomeMemberId = 104L; - public static final long validAdminId = 105L; - - public static Member createValidMember() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Member ret = Member.builder() - .accountType(AccountType.kakao) - .email("member1@example.com") - .nickname("nick_normal_123") - .phone("010-1112-2233") - .profileImage(memberImage) - .area(Area.광주) - .gender("Men") - .socialId("100100100100100") - .build(); - ReflectionTestUtils.setField(ret, "Id", validMemberId); - ReflectionTestUtils.setField(ret, "memberType", MemberType.normal); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class R { + public static class normal { + public static final long id = 101L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.normal); + public static final AccountType accountType = AccountType.kakao; + public static final String email = "member1@example.com"; + public static final String nickname = "nick_normal_123"; + public static final String phone = "010-1112-2233"; + public static final MemberImage profileImage = ImageData.member.normal.entity.get(); + public static final Area area = Area.광주; + public static final String gender = "Men"; + public static final String socialId = "100100100100100"; + public static final MemberType memberType = MemberType.normal; + } + public static class curator { + public static final long id = 102L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.curator); + public static final AccountType accountType = AccountType.google; + public static final String email = "curator1@example.com"; + public static final String nickname = "nick_curator_12"; + public static final String phone = "010-4545-6767"; + public static final MemberImage profileImage = ImageData.member.curator.entity.get(); + public static final String profileImageUrl = "https://wouldyouin.store/api/images/member/" + profileImage.getName(); + public static final Area area = Area.광주; + public static final String gender = "Women"; + public static final String socialId = "200200200200200"; + public static final String intro = "큐레이터 자기소개입니다."; + public static final List hashtags = List.of("#큐레이터", "#해시태그", "#입니다"); + } + public static class host { + public static final long id = 103L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.host); + public static final String email = "host1@example.com"; + public static final String nickname = "nick_host_12"; + public static final String phone = "010-4545-6767"; + public static final String hashedPassword = "hashed_password"; + public static final MemberImage profileImage = ImageData.member.host.entity.get(); + public static final String intro = "주최자 자기소개입니다."; + public static final List hashtags = List.of("#주최자", "#해시태그", "#입니다"); + + } + public static class welcome { + public static final long id = 104L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.welcome); + public static final AccountType accountType = AccountType.kakao; + public static final String email = "welcome2@example.com"; + public static final String nickname = "nick_normal_333"; + public static final String phone = "010-4414-1144"; + public static final MemberImage profileImage = ImageData.member.welcome.entity.get(); + public static final Area area = Area.서울; + public static final String gender = "Men"; + public static final String socialId = "456456456456"; + + } + public static class admin { + public static final long id = 105L; + public static final MemberIdentifier memberIdentifier = new MemberIdentifier(id, MemberType.admin); + } } - public static Curator createValidCurator() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Curator ret = Curator.curatorBuilder() - .accountType(AccountType.google) - .email("curator1@example.com") - .nickname("nick_curator_12") - .phone("010-4545-6767") - .profileImage(memberImage) - .area(Area.광주) - .gender("Women") - .socialId("200200200200200") - .build(); - ReflectionTestUtils.setField(ret, "Id", validCuratorId); - ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtags", List.of("#큐레이터", "#해시태그", "#입니다")); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class normal { + public static class entity { + public static Member get() { + Member ret = Member.builder() + .accountType(R.normal.accountType) + .email(R.normal.email) + .nickname(R.normal.nickname) + .phone(R.normal.phone) + .profileImage(R.normal.profileImage) + .area(R.normal.area) + .gender(R.normal.gender) + .socialId(R.normal.socialId) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.normal.id); + ReflectionTestUtils.setField(ret, "memberType", R.normal.memberType); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } } - public static Host createValidHost() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Host ret = Host.builder() - .email("curator1@example.com") - .nickname("nick_curator_12") - .phone("010-4545-6767") - .hashedPassword("hashed_password") - .profileImage(memberImage) - .build(); - ReflectionTestUtils.setField(ret, "Id", validHostId); - ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtags", List.of("#주최자", "#해시태그", "#입니다")); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class curator { + public static class entity { + public static Curator get() { + Curator ret = Curator.curatorBuilder() + .accountType(R.curator.accountType) + .email(R.curator.email) + .nickname(R.curator.nickname) + .phone(R.curator.phone) + .profileImage(R.curator.profileImage) + .area(R.curator.area) + .gender(R.curator.gender) + .socialId(R.curator.socialId) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.curator.id); + ReflectionTestUtils.setField(ret, "intro", R.curator.intro); + ReflectionTestUtils.setField(ret, "hashtags", R.curator.hashtags); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } } - public static Member createValidWelcomeMember() { - MemberImage memberImage = ImageData.createValidMemberImage(); - Member ret = Member.builder() - .accountType(AccountType.kakao) - .email("member2@example.com") - .nickname("nick_normal_333") - .phone("010-4414-1144") - .profileImage(memberImage) - .area(Area.서울) - .gender("Men") - .socialId("456456456456") - .build(); - ReflectionTestUtils.setField(ret, "Id", validWelcomeMemberId); - ReflectionTestUtils.setField(memberImage, "baseMember", ret); - return ret; + public static class host { + public static class entity { + public static Host get() { + Host ret = Host.builder() + .email(R.host.email) + .nickname(R.host.nickname) + .phone(R.host.phone) + .hashedPassword(R.host.hashedPassword) + .profileImage(R.host.profileImage) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.host.id); + ReflectionTestUtils.setField(ret, "intro", R.host.intro); + ReflectionTestUtils.setField(ret, "hashtags", R.host.hashtags); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + + public static class welcome { + public static class entity { + public static Member get() { + Member ret = Member.builder() + .accountType(R.welcome.accountType) + .email(R.welcome.email) + .nickname(R.welcome.nickname) + .phone(R.welcome.phone) + .profileImage(R.welcome.profileImage) + .area(R.welcome.area) + .gender(R.welcome.gender) + .socialId(R.welcome.socialId) + .build(); + ReflectionTestUtils.setField(ret, "Id", R.welcome.id); +// ReflectionTestUtils.setField(ret.getProfileImage(), "baseMember", ret); + return ret; + } + } + public static class request { + + } + public static class response { + + } + } + + public static class admin { + public static class entity { + + public static final long validAdminId = 105L; + } + public static class request { + + } + public static class response { + + } } - public static ReservationMemberResponse createValidReservationMemberResponse() { - return ReservationMemberResponse.builder() - .id(validMemberId) - .email("member1@example.com") - .nickname("nick_normal_123") - .phone("010-1112-2233") - .gender("Men") - .build(); + public static class response { + public static class reservationMember { + public static ReservationMemberResponse get() { + return ReservationMemberResponse.builder() + .memberId(R.normal.id) + .email(R.normal.email) + .nickname(R.normal.nickname) + .phone(R.normal.phone) + .gender(R.normal.gender) + .build(); + } + } + public static class curationCurator { + public static CurationCuratorResponse get() { + return CurationCuratorResponse.builder() + .nickname(R.curator.nickname) + .email(R.curator.email) + .phone(R.curator.phone) + .profileImageUrl(R.curator.profileImageUrl) + .intro(R.curator.intro) + .likes(0) + .hashtags(R.curator.hashtags) + .build(); + } + } } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java new file mode 100644 index 00000000..a6e56405 --- /dev/null +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/testdata/ReservationData.java @@ -0,0 +1,77 @@ +package org.ktc2.cokaen.wouldyouin._global.testdata; + +import java.time.LocalDateTime; +import java.util.List; +import org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse.ReservationEventResponse; +import org.ktc2.cokaen.wouldyouin.event.persist.Event; +import org.ktc2.cokaen.wouldyouin.member.api.dto.relationResponse.ReservationMemberResponse; +import org.ktc2.cokaen.wouldyouin.member.persist.Member; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationResponse; +import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationSliceResponse; +import org.ktc2.cokaen.wouldyouin.reservation.persist.Reservation; +import org.springframework.test.util.ReflectionTestUtils; + +public class ReservationData { + + public static class R { + public static class reservation { + public static final Long id = 1L; + public static final Member member = MemberData.normal.entity.get(); + public static final Event event = EventData.event.entity.get(); + public static final Integer price = EventData.R.event.price; + public static final Integer quantity = 2; + public static final LocalDateTime reservationDate = LocalDateTime.of(2024, 3, 23, 0, 0); + + public static final ReservationMemberResponse memberResponse = MemberData.response.reservationMember.get(); + public static final ReservationEventResponse eventResponse = EventData.response.reservationEvent.createValidReservationEventResponse(); + } + } + + public static class reservation { + public static class entity { + public static Reservation get() { + Reservation ret = Reservation.builder() + .member(R.reservation.member) + .event(R.reservation.event) + .price(R.reservation.price) + .quantity(R.reservation.quantity) + .build(); + ReflectionTestUtils.setField(ret, "id", R.reservation.id); + ReflectionTestUtils.setField(ret, "reservationDate", R.reservation.reservationDate); + return ret; + } + } + public static class request { + public static ReservationRequest get() { + return ReservationRequest.builder() + .eventId(R.reservation.event.getId()) + .quantity(R.reservation.quantity) + .build(); + } + } + public static class response { + public static ReservationResponse get() { + return ReservationResponse.builder() + .id(R.reservation.id) + .member(R.reservation.memberResponse) + .event(R.reservation.eventResponse) + .price(R.reservation.price) + .quantity(R.reservation.quantity) + .reservationDate(R.reservation.reservationDate) + .build(); + + } + public static class slice { + public static ReservationSliceResponse get() { + return ReservationSliceResponse.builder() + .reservations(List.of( + ReservationData.reservation.response.get())) + .sliceInfo(CommonData.sliceInfo.get()) + .build(); + } + } + } + } + +} diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index fd437c1b..f64f4884 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -2,10 +2,6 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationCardRequest1; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationCreateRequest; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCurationEditRequest; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -29,7 +25,8 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; -import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.curation.api.CurationController; import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest; @@ -150,7 +147,7 @@ void getCurationByCurationId() throws Exception { void createCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); - CurationCreateRequest request = createValidCurationCreateRequest(); + CurationCreateRequest request = CurationData.curation.request.create.get(); // when mockMvc.perform(post("/api/curations") @@ -161,7 +158,7 @@ void createCuration1() throws Exception { .andExpect(status().isCreated()); // then - then(curationService).should(times(1)).create(eq(validCuratorId), captor.capture()); + then(curationService).should(times(1)).create(eq(curator.memberIdentifier), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -173,7 +170,7 @@ void createCuration2() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationCreateRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.create.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -191,7 +188,7 @@ void createCuration3() throws Exception { mockMvc.perform(post("/api/curations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationCreateRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.create.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -206,7 +203,7 @@ void createCuration3() throws Exception { @WithMockCurator void createCuration4() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() .title("").build(); // when @@ -227,8 +224,8 @@ void createCuration4() throws Exception { @WithMockCurator void createCuration5() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().subtitle("").build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().subtitle("").build())) .build(); // when @@ -249,8 +246,8 @@ void createCuration5() throws Exception { @WithMockCurator void createCuration6() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content(null).build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); // when @@ -271,8 +268,8 @@ void createCuration6() throws Exception { @WithMockCurator void createCuration7() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content(null).build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content(null).build())) .build(); // when @@ -293,8 +290,8 @@ void createCuration7() throws Exception { @WithMockCurator void createCuration8() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder().content("짧은 내용").build())) + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder().content("짧은 내용").build())) .build(); // when @@ -315,8 +312,8 @@ void createCuration8() throws Exception { @WithMockCurator void createCuration9() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -338,7 +335,7 @@ void createCuration9() throws Exception { @WithMockCurator void createCuration10() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder() + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder() .area(null).build(); // when @@ -359,7 +356,7 @@ void createCuration10() throws Exception { @WithMockCurator void createCuration11() throws Exception { // given - CurationCreateRequest request = createValidCurationCreateRequest().toBuilder(). + CurationCreateRequest request = CurationData.curation.request.create.get().toBuilder(). curationCards(List.of()).build(); // when @@ -381,7 +378,7 @@ void createCuration11() throws Exception { void updateCuration1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(CurationEditRequest.class); - CurationEditRequest request = createValidCurationEditRequest(); + CurationEditRequest request = CurationData.curation.request.edit.get(); // when mockMvc.perform(put("/api/curations/" + randomId) @@ -392,7 +389,7 @@ void updateCuration1() throws Exception { .andExpect(status().isOk()); // then - then(curationService).should(times(1)).update(eq(validCuratorId), eq(randomId), captor.capture()); + then(curationService).should(times(1)).update(eq(curator.memberIdentifier), eq(randomId), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -404,7 +401,7 @@ void updateCuration2() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationEditRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.edit.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -422,7 +419,7 @@ void updateCuration3() throws Exception { mockMvc.perform(put("/api/curations/" + randomId) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(createValidCurationEditRequest()))) + .content(objectMapper.writeValueAsString(CurationData.curation.request.edit.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -437,7 +434,7 @@ void updateCuration3() throws Exception { @WithMockCurator void updateCuration4() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() .title(null).build(); // when @@ -458,8 +455,8 @@ void updateCuration4() throws Exception { @WithMockCurator void updateCuration5() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .subtitle("").build())) .build(); @@ -481,8 +478,8 @@ void updateCuration5() throws Exception { @WithMockCurator void updateCuration6() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .content(null).build())) .build(); @@ -504,8 +501,8 @@ void updateCuration6() throws Exception { @WithMockCurator void updateCuration7() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .content("짧은 내용").build())) .build(); @@ -527,8 +524,8 @@ void updateCuration7() throws Exception { @WithMockCurator void updateCuration8() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() - .curationCards(List.of(createValidCurationCardRequest1().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() + .curationCards(List.of(CurationData.curationCard1.request.get().toBuilder() .imageIds(List.of(1L, 2L, 3L, 4L, 5L, 6L)).build())) .build(); @@ -550,7 +547,7 @@ void updateCuration8() throws Exception { @WithMockCurator void updateCuration9() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() .area(null).build(); // when @@ -571,7 +568,7 @@ void updateCuration9() throws Exception { @WithMockCurator void updateCuration10() throws Exception { // given - CurationEditRequest request = createValidCurationEditRequest().toBuilder() + CurationEditRequest request = CurationData.curation.request.edit.get().toBuilder() .curationCards(List.of()).build(); // when @@ -598,7 +595,7 @@ void deleteCuration1() throws Exception { .andExpect(status().isNoContent()); // then - then(curationService).should(times(1)).delete(eq(validCuratorId), eq(randomId)); + then(curationService).should(times(1)).delete(eq(curator.memberIdentifier), eq(randomId)); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java index d14d31bd..516f88d9 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationServiceTest.java @@ -3,7 +3,6 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.testdata.CurationData.createValidCuration; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -16,6 +15,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; +import org.ktc2.cokaen.wouldyouin._global.testdata.CurationData; +import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationResponse; import org.ktc2.cokaen.wouldyouin.curation.application.CurationCardService; import org.ktc2.cokaen.wouldyouin.curation.application.CurationService; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; @@ -45,20 +46,18 @@ class CurationServiceTest { @Mock private MemberImage memberImage; - private Curation validCuration; - private final long randomId = abs(new Random().nextLong()); @BeforeEach void setUp() { curationService = new CurationService(curationRepository, curatorService, eventService, curationCardService); - validCuration = createValidCuration(); } @Test @DisplayName("큐레이션 ID를 통해 큐레이션 조회한다.") void getByIdOrThrow1() { // given + Curation validCuration = CurationData.curation.entity.get(); given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); // when @@ -78,12 +77,25 @@ void getByIdOrThrow2() { // when, then EntityNotFoundException thrown = assertThrows( EntityNotFoundException.class, () -> curationService.getByIdOrThrow(randomId)); + then(curationRepository).should(times(1)).findById(randomId); assertThat(thrown.getMessage()).isEqualTo("해당하는 큐레이션을 찾을 수 없습니다."); } - @Test - void getById() { - } + // TODO: 이게 통과하면 데이터 정합성은 완벽한 것일거임 +// @Test +// @DisplayName("큐레이션 ID를 통해 큐레이션을 찾지 못한 경우, 예외를 던진다.") +// void getById() { +// // given +// Curation validCuration = CurationData.curation.entity.get(); +// given(curationRepository.findById(randomId)).willReturn(Optional.of(validCuration)); +// +// // when +// CurationResponse response = curationService.getById(randomId); +// +// // then +// then(curationRepository).should(times(1)).findById(randomId); +// assertThat(response).usingRecursiveComparison().isEqualTo(CurationData.curation.response.get()); +// } @Test void getAllByAreaOrderByCreatedDateDesc() { diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index a840608b..7207c369 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -1,7 +1,5 @@ package org.ktc2.cokaen.wouldyouin.event; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -24,8 +22,10 @@ import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host.entity; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.auth.application.JwtService; import org.ktc2.cokaen.wouldyouin.event.api.EventController; @@ -70,7 +70,7 @@ class EventControllerUnitTest { @BeforeAll public static void init() { id = 3L; - validHost = createValidHost(); + validHost = entity.get(); objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); } @@ -186,12 +186,12 @@ void createEvent() throws Exception { mockMvc.perform(post("/api/events") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventDomain.createValidEventCreateRequest()))) + .content(objectMapper.writeValueAsString(EventData.event.request.create.get()))) .andDo(print()) .andExpect(status().isCreated()); //then - then(eventService).should(times(1)).create(eq(validHostId), any(EventCreateRequest.class)); + then(eventService).should(times(1)).create(eq(host.memberIdentifier), any(EventCreateRequest.class)); } @Test @@ -203,11 +203,12 @@ void updateEvent() throws Exception { mockMvc.perform(put("/api/events/" + id) .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(EventDomain.createValidEventCreateRequest()))) + .content(objectMapper.writeValueAsString(EventData.event.request.create.get()))) + .andDo(print()) .andExpect(status().isOk()); //then - then(eventService).should(times(1)).update(eq(validHostId), eq(id), any(EventEditRequest.class)); + then(eventService).should(times(1)).update(eq(host.memberIdentifier), eq(id), any(EventEditRequest.class)); } @Test @@ -221,6 +222,6 @@ void deleteEvent() throws Exception { ).andExpect(status().isNoContent()); //then - then(eventService).should(times(1)).delete(eq(validHostId), eq(id)); + then(eventService).should(times(1)).delete(eq(host.memberIdentifier), eq(id)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index 1590e5ec..60414a94 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -18,7 +18,10 @@ import org.ktc2.cokaen.wouldyouin.Image.application.EventImageService; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; +import org.ktc2.cokaen.wouldyouin._global.testdata.EventData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; @@ -27,6 +30,7 @@ import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; import org.ktc2.cokaen.wouldyouin.member.application.HostService; +import org.ktc2.cokaen.wouldyouin.member.persist.MemberType; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.PageRequest; @@ -52,7 +56,7 @@ class EventServiceUnitTest { @BeforeEach void setUp() { eventService = new EventService(eventRepository, hostService, eventImageService); - validEvent = EventDomain.createValidEvent(); + validEvent = EventData.event.entity.get(); } @Test @@ -135,11 +139,11 @@ void getByInvalidId() { void create() { // given Long hostId = validEvent.getHost().getId(); - EventCreateRequest validEventCreateRequest = EventDomain.createValidEventCreateRequest(); + EventCreateRequest validEventCreateRequest = EventData.event.request.create.get(); given(eventRepository.save(any())).willReturn(validEvent); // when - eventService.create(hostId, validEventCreateRequest); + eventService.create(host.memberIdentifier, validEventCreateRequest); // then then(eventRepository).should(times(1)).save(any(Event.class)); @@ -151,11 +155,11 @@ void update() { // given Long eventId = validEvent.getId(); Long hostId = validEvent.getHost().getId(); - EventEditRequest validEventEditRequest = EventDomain.createValidEventEditRequest(); + EventEditRequest validEventEditRequest = EventData.event.request.edit.get(); given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); // when - eventService.update(hostId, eventId, validEventEditRequest); + eventService.update(host.memberIdentifier, eventId, validEventEditRequest); // then then(eventRepository).should(times(1)).findById(eventId); @@ -176,14 +180,14 @@ void update() { @DisplayName("유효하지 않은 행사 id를 통한 행사 수정 - 실패") void updateByInvalidId() { // given - EventEditRequest request = EventDomain.createValidEventEditRequest(); + EventEditRequest request = EventData.event.request.edit.get(); Long invalidHostId = 999L; given(eventRepository.findById(invalidHostId)).willThrow(RuntimeException.class); // when & then assertThrows(RuntimeException.class, - () -> eventService.update(invalidHostId, validEvent.getId(), - EventDomain.createValidEventEditRequest())); + () -> eventService.update(new MemberIdentifier(invalidHostId, MemberType.host), validEvent.getId(), + EventData.event.request.edit.get())); } @Test @@ -196,7 +200,7 @@ void delete() { // when given(eventRepository.findById(eventId)).willReturn(Optional.of(validEvent)); willDoNothing().given(eventRepository).deleteById(eventId); - eventService.delete(hostId, eventId); + eventService.delete(host.memberIdentifier, eventId); // then then(eventRepository).should(times(1)).findById(eventId); @@ -212,6 +216,6 @@ void deleteByInvalidId() { given(eventRepository.findById(eventId)).willThrow(RuntimeException.class); // when & then - assertThrows(RuntimeException.class, () -> eventService.delete(hostId, eventId)); + assertThrows(RuntimeException.class, () -> eventService.delete(host.memberIdentifier, eventId)); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 52e6f2ff..9160fc52 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -1,10 +1,6 @@ package org.ktc2.cokaen.wouldyouin.image; import static java.lang.Math.abs; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidImageResponse1; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidImageResponse2; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMultipartFile1; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMultipartFile2; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -32,6 +28,9 @@ import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile1; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.mockMultipartFile2; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -96,11 +95,11 @@ void getImage() throws Exception { @WithMockCurator void uploadImages1() throws Exception { // given - MockMultipartFile image1 = createValidMultipartFile1(); - MockMultipartFile image2 = createValidMultipartFile2(); + MockMultipartFile image1 = mockMultipartFile1.get(); + MockMultipartFile image2 = mockMultipartFile2.get(); given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); given(curationImageService.saveImages(List.of(image1, image2))) - .willReturn(List.of(createValidImageResponse1(), createValidImageResponse2())); + .willReturn(List.of(ImageData.curation1.response.get(), ImageData.curation2.response.get())); // when mockMvc.perform(multipart("/api/images") @@ -122,8 +121,8 @@ void uploadImages1() throws Exception { @WithMockCurator void uploadImages2() throws Exception { // given - MockMultipartFile image1 = createValidMultipartFile1(); - MockMultipartFile image2 = createValidMultipartFile2(); + MockMultipartFile image1 = mockMultipartFile1.get(); + MockMultipartFile image2 = mockMultipartFile2.get(); // when mockMvc.perform(multipart("/api/images") @@ -157,7 +156,7 @@ void deleteImage1() throws Exception { // then then(imageServiceFactory).should(times(1)).getImageService(eq(ImageDomain.CURATION)); - then(curationImageService).should(times(1)).deleteImage(randomId); + then(curationImageService).should(times(1)).deleteImage(curator.memberIdentifier, randomId); } @Test diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java index 28968e9e..3f4497c1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/BaseMemberServiceUnitTest.java @@ -2,14 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidWelcomeMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validMemberId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validWelcomeMemberId; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -25,6 +17,11 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.welcome; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; @@ -61,10 +58,10 @@ class BaseMemberServiceUnitTest { private BaseMemberService baseMemberService; private static Map members; - private static final Member validMember = createValidMember(); - private static final Member validWelcomeMember = createValidWelcomeMember(); - private static final Host validHost = createValidHost(); - private static final Curator validCurator = createValidCurator(); + private static final Member validMember = MemberData.normal.entity.get(); + private static final Member validWelcomeMember = MemberData.welcome.entity.get(); + private static final Host validHost = MemberData.host.entity.get(); + private static final Curator validCurator = MemberData.curator.entity.get(); @BeforeAll static void beforeAll() { @@ -92,7 +89,7 @@ MemberType welcomeTypeMapping(MemberType memberType) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("임의의 사용자를 찾는 메서드 테스트") void getByIdOrThrow(long id) { // when @@ -105,7 +102,7 @@ void getByIdOrThrow(long id) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("임의의 사용자의 타입을 반환하는 메서드 테스트") void getMemberType(long id) { // when @@ -118,7 +115,7 @@ void getMemberType(long id) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("각 유형의 사용자를 찾고 응답 반환하는 메서드 테스트") void findById(long id) { // given @@ -140,7 +137,7 @@ void findById(long id) { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("중복 있는 이메일 있는 경우 테스트") void checkUniqueEmailOrThrow(long id) { // given @@ -169,7 +166,7 @@ void checkUniqueEmailOrThrow_Unique() { } @ParameterizedTest - @ValueSource(longs = {validMemberId, validCuratorId, validHostId, validWelcomeMemberId}) + @ValueSource(longs = {normal.id, curator.id, host.id, welcome.id}) @DisplayName("각 유형의 사용자를 제거하는 메서드 테스트") void deleteById(long id) { // given diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java index 31a5b87f..c80d6144 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorServiceUnitTest.java @@ -1,8 +1,6 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidCurator; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; @@ -14,6 +12,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; @@ -46,14 +45,14 @@ class CuratorServiceUnitTest { @BeforeEach void setUp() { - validCurator = createValidCurator(); + validCurator = MemberData.curator.entity.get(); } @Test @DisplayName("큐레이터 사용자 생성 테스트") void createCurator() { // given - Member validMember = createValidMember(); + Member validMember = MemberData.normal.entity.get(); given(memberRepository.findById(validMember.getId())).willReturn(Optional.of(validMember)); // when diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 0c518e8e..1c287ae1 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -1,8 +1,7 @@ package org.ktc2.cokaen.wouldyouin.member.application; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMemberImage; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidHost; +import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.host.entity.get; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -15,6 +14,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._global.testdata.ImageData; import org.ktc2.cokaen.wouldyouin.auth.api.dto.LocalLoginRequest; import org.ktc2.cokaen.wouldyouin._global.TestUtil; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.HostCreateRequest; @@ -50,7 +50,7 @@ class HostServiceUnitTest { @BeforeEach void setUp() { - validHost = createValidHost(); + validHost = get(); } @Test @@ -88,7 +88,7 @@ void createHost() { void updateHost() { // given Long newProfileImageId = 5L; - MemberImage newProfileImage = createValidMemberImage(); + MemberImage newProfileImage = ImageData.member.host.entity.get(); newProfileImage.setBaseMember(validHost); HostEditRequest editRequest = HostEditRequest.builder() .nickname(TestUtil.getOrNull("newNickname")) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java index e26283f6..3d7cc5f3 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/MemberServiceUnitTest.java @@ -2,9 +2,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.createValidMemberImage; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidMember; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.createValidWelcomeMember; +import static org.ktc2.cokaen.wouldyouin._global.testdata.ImageData.member.normal.entity.get; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.never; @@ -18,6 +16,7 @@ import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; import org.ktc2.cokaen.wouldyouin._global.TestUtil; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.MemberAdditionalInfoRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.create.MemberCreateRequest; import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.MemberEditRequest; @@ -53,7 +52,7 @@ class MemberServiceUnitTest { @BeforeEach void setUp() { - validMember = createValidMember(); + validMember = MemberData.normal.entity.get(); } @Test @@ -76,7 +75,7 @@ void createMember() { @DisplayName("사용자 업데이트 테스트") void updateMember() { // given - MemberImage validMemberImage = createValidMemberImage(); + MemberImage validMemberImage = get(); Long givenMemberId = validMember.getId(); given(memberRepository.findById(givenMemberId)).willReturn(Optional.of(validMember)); given(memberImageService.getById(validMember.getProfileImage().getId())).willReturn(validMemberImage); @@ -101,7 +100,7 @@ void updateMember() { @Test @DisplayName("소셜 신규 사용자 추가정보 기입 테스트") void updateWelcomeMember() { - Member validWelcomeMember = createValidWelcomeMember(); + Member validWelcomeMember = MemberData.welcome.entity.get(); given(memberRepository.findById(validWelcomeMember.getId())).willReturn(Optional.of(validWelcomeMember)); given(memberAdditionalInfoRequest.getPhone()).willReturn(validWelcomeMember.getPhone()); given(memberAdditionalInfoRequest.getArea()).willReturn(validWelcomeMember.getArea()); diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java index 1e9c2195..7af9d013 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/reservation/ReservationControllerUnitTest.java @@ -2,9 +2,6 @@ import static java.lang.Math.abs; import static org.assertj.core.api.Assertions.assertThat; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validCuratorId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validHostId; -import static org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.validMemberId; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; @@ -22,10 +19,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.ktc2.cokaen.wouldyouin._global.TestData.ReservationDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.curator; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.host; +import org.ktc2.cokaen.wouldyouin._global.testdata.MemberData.R.normal; +import org.ktc2.cokaen.wouldyouin._global.testdata.ReservationData; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.ktc2.cokaen.wouldyouin.reservation.api.ReservationController; import org.ktc2.cokaen.wouldyouin.reservation.api.dto.ReservationRequest; @@ -80,7 +80,7 @@ void getReservationsByMemberId1() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(validMemberId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(normal.id), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -93,7 +93,7 @@ void getReservationsByMemberId2() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(validMemberId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(normal.id), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -109,7 +109,7 @@ void getReservationsByMemberId3() throws Exception { // then then(reservationService).should(times(1)).getAllByMemberId( - eq(validCuratorId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(curator.id), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -141,7 +141,7 @@ void getReservationByEventId1() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(validHostId), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); + eq(host.memberIdentifier), eq(randomId), eq(PageRequest.of(5, 20)), eq(100L)); } @Test @@ -155,7 +155,7 @@ void getReservationByEventId2() throws Exception { // then then(reservationService).should(times(1)).getAllByEventId( - eq(validHostId), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); + eq(host.memberIdentifier), eq(randomId), eq(PageRequest.of(0, 10)), eq(Long.MAX_VALUE)); } @Test @@ -205,7 +205,7 @@ void getReservationById1() throws Exception { void createReservation1() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); - ReservationRequest request = ReservationDomain.createValidReservationRequest(); + ReservationRequest request = ReservationData.reservation.request.get(); // when mockMvc.perform(post("/api/reservations") @@ -216,7 +216,7 @@ void createReservation1() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(validMemberId), captor.capture()); + then(reservationService).should(times(1)).create(eq(normal.id), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -226,7 +226,7 @@ void createReservation1() throws Exception { void createReservation2() throws Exception { // given ArgumentCaptor captor = ArgumentCaptor.forClass(ReservationRequest.class); - ReservationRequest request = ReservationDomain.createValidReservationRequest(); + ReservationRequest request = ReservationData.reservation.request.get(); // when mockMvc.perform(post("/api/reservations") @@ -237,7 +237,7 @@ void createReservation2() throws Exception { .andExpect(status().isCreated()); // then - then(reservationService).should(times(1)).create(eq(validCuratorId), captor.capture()); + then(reservationService).should(times(1)).create(eq(curator.id), captor.capture()); assertThat(captor.getValue()).isEqualTo(request); } @@ -249,7 +249,7 @@ void createReservation3() throws Exception { mockMvc.perform(post("/api/reservations") .with(csrf()) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(ReservationDomain.createValidReservationRequest()))) + .content(objectMapper.writeValueAsString(ReservationData.reservation.request.get()))) .andDo(print()) .andExpect(status().isUnauthorized()) .andExpect(jsonPath("$.message").value("요구된 멤버 형식과 실제 형식이 다릅니다.")); @@ -263,7 +263,7 @@ void createReservation3() throws Exception { @WithMockMember void createReservation4() throws Exception { // given - ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + ReservationRequest request = ReservationData.reservation.request.get().toBuilder() .eventId(null).build(); // when @@ -284,7 +284,7 @@ void createReservation4() throws Exception { @WithMockMember void createReservation5() throws Exception { // given - ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + ReservationRequest request = ReservationData.reservation.request.get().toBuilder() .quantity(null).build(); // when @@ -305,7 +305,7 @@ void createReservation5() throws Exception { @WithMockMember void createReservation6() throws Exception { // given - ReservationRequest request = ReservationDomain.createValidReservationRequest().toBuilder() + ReservationRequest request = ReservationData.reservation.request.get().toBuilder() .quantity(0).build(); // when @@ -332,7 +332,7 @@ void deleteReservation1() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(validMemberId, randomId); + then(reservationService).should(times(1)).delete(normal.id, randomId); } @Test @@ -346,7 +346,7 @@ void deleteReservation2() throws Exception { .andExpect(status().isNoContent()); // then - then(reservationService).should(times(1)).delete(validCuratorId, randomId); + then(reservationService).should(times(1)).delete(curator.id, randomId); } @Test