From c5b622fdb420d2f44071ff9b4e91df670dfff7f5 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Wed, 27 Oct 2021 22:38:43 +0900 Subject: [PATCH 01/20] =?UTF-8?q?refactor:=20ImageRepositoryTest=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image/repository/ImageRepositoryTest.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index c4e60f2e..c7ba1ac4 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -1,9 +1,10 @@ package com.cvi.image.repository; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; -import com.cvi.image.repository.ImageRepository; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; import com.cvi.post.domain.repository.PostRepository; @@ -31,32 +32,32 @@ class ImageRepositoryTest { @Autowired private ImageRepository imageRepository; - private User user1; - private Image image1; - private Post post1; + private User user; + private Image image; + private Post post; @BeforeEach void setUp() { - user1 = User.builder() + user = User.builder() .nickname("인비") .ageRange(AgeRange.TEENS) .socialProvider(SocialProvider.KAKAO) .socialId("1000") .profileUrl("profile url 1") .build(); - userRepository.save(user1); + userRepository.save(user); - image1 = Image.builder() + image = Image.builder() .url("image1_s3_url") .build(); - imageRepository.save(image1); + imageRepository.save(image); - post1 = Post.builder() - .user(user1) + post = Post.builder() + .user(user) .content("내용 1") .vaccinationType(VaccinationType.PFIZER) .build(); - postRepository.save(post1); + postRepository.save(post); } @DisplayName("Post에 Image 추가 시 양방향 매핑 테스트") @@ -64,10 +65,10 @@ void setUp() { void assignImageToPost() { //given //when - post1.assignImages(Collections.singletonList(image1)); + post.assignImages(Collections.singletonList(image)); //then - assertThat(post1.getImages().getImages().contains(image1)).isTrue(); - assertThat(image1.getPost()).isEqualTo(post1); + assertThat(post.getImages().getImages().contains(image)).isTrue(); + assertThat(image.getPost()).isEqualTo(post); } @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트") @@ -75,9 +76,18 @@ void assignImageToPost() { void assignPostToImage() { //given //when - image1.assignPost(post1); + image.assignPost(post); //then - assertThat(post1.getImages().getImages().contains(image1)).isTrue(); - assertThat(image1.getPost()).isEqualTo(post1); + assertThat(post.getImages().getImages().contains(image)).isTrue(); + assertThat(image.getPost()).isEqualTo(post); + } + + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 실패") + @Test + void assignPostToImageFailure() { + //given + //when + //then + assertThatThrownBy(() -> image.assignPost(null)).isInstanceOf(NotFoundException.class); } } From b6436d45deb0d5225def7f8668eb5e0f579f5859 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Wed, 27 Oct 2021 22:38:43 +0900 Subject: [PATCH 02/20] =?UTF-8?q?refactor:=20ImageRepositoryTest=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../image/repository/ImageRepositoryTest.java | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index c4e60f2e..cadf0a73 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -1,9 +1,10 @@ package com.cvi.image.repository; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; -import com.cvi.image.repository.ImageRepository; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; import com.cvi.post.domain.repository.PostRepository; @@ -31,32 +32,31 @@ class ImageRepositoryTest { @Autowired private ImageRepository imageRepository; - private User user1; - private Image image1; - private Post post1; + private Image image; + private Post post; @BeforeEach void setUp() { - user1 = User.builder() + User user = User.builder() .nickname("인비") .ageRange(AgeRange.TEENS) .socialProvider(SocialProvider.KAKAO) .socialId("1000") .profileUrl("profile url 1") .build(); - userRepository.save(user1); + userRepository.save(user); - image1 = Image.builder() + image = Image.builder() .url("image1_s3_url") .build(); - imageRepository.save(image1); + imageRepository.save(image); - post1 = Post.builder() - .user(user1) + post = Post.builder() + .user(user) .content("내용 1") .vaccinationType(VaccinationType.PFIZER) .build(); - postRepository.save(post1); + postRepository.save(post); } @DisplayName("Post에 Image 추가 시 양방향 매핑 테스트") @@ -64,10 +64,10 @@ void setUp() { void assignImageToPost() { //given //when - post1.assignImages(Collections.singletonList(image1)); + post.assignImages(Collections.singletonList(image)); //then - assertThat(post1.getImages().getImages().contains(image1)).isTrue(); - assertThat(image1.getPost()).isEqualTo(post1); + assertThat(post.getImages().getImages().contains(image)).isTrue(); + assertThat(image.getPost()).isEqualTo(post); } @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트") @@ -75,9 +75,18 @@ void assignImageToPost() { void assignPostToImage() { //given //when - image1.assignPost(post1); + image.assignPost(post); //then - assertThat(post1.getImages().getImages().contains(image1)).isTrue(); - assertThat(image1.getPost()).isEqualTo(post1); + assertThat(post.getImages().getImages().contains(image)).isTrue(); + assertThat(image.getPost()).isEqualTo(post); + } + + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 실패") + @Test + void assignPostToImageFailure() { + //given + //when + //then + assertThatThrownBy(() -> image.assignPost(null)).isInstanceOf(NotFoundException.class); } } From 780ce519d3c0c08c70e5ca95b9ea9bb3008bb72b Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Wed, 27 Oct 2021 22:46:01 +0900 Subject: [PATCH 03/20] =?UTF-8?q?refactor:=20LikeRepositoryTest=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/LikeRepositoryTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index 229f71fc..98886375 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -2,6 +2,7 @@ import com.cvi.comment.domain.model.Comment; import com.cvi.comment.domain.repository.CommentRepository; +import com.cvi.exception.NotFoundException; import com.cvi.like.domain.model.Like; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; @@ -17,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.*; @DisplayName("LikeRepository 테스트") @@ -120,6 +122,15 @@ void findCommentByUserId() { assertThat(likeRepository.findByUserId(user2.getId())).hasSize(2); } + @DisplayName("유저 아이디로 댓글을 조회한다. - 실패") + @Test + void findCommentByUserIdFailure() { + //given + //when + //then + assertThat(likeRepository.findByUserId(null)).hasSize(3); + } + @DisplayName("유저 아이디로 좋아요를 페이징 조회한다.") @Test void findCommentByUserIdPaging() { @@ -129,4 +140,13 @@ void findCommentByUserIdPaging() { assertThat(likeRepository.findByUserId(user1.getId(), 0, 2)).hasSize(1); assertThat(likeRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } + + @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - 실패") + @Test + void findCommentByUserIdPagingFailure() { + //given + //when + //then + assertThat(likeRepository.findByUserId(null, 0, 2)).hasSize(2); + } } \ No newline at end of file From 68a7d3920367cab97c4247f05969df1b8544810b Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Wed, 27 Oct 2021 22:58:58 +0900 Subject: [PATCH 04/20] =?UTF-8?q?refactor:=20JpaConfiguration=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=8C=80=EC=83=81=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/build.gradle | 3 ++- .../config/entity/BooleanToYNConverterTest.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/build.gradle b/backend/build.gradle index 346de5c3..7d8ee384 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -84,6 +84,7 @@ subprojects { '**/Sort*', '**/Filter*', '**/ImageType*', + '**/JpaConfiguration*', // domain-cvi-oauth-service '**/KakaoProfile*', '**/NaverProfile*' @@ -106,7 +107,7 @@ subprojects { // cvi-publicdata-parser "**/Parser.java, " + // domain-cvi - "**/Sort.java, **/Filter.java, **/ImageType.java, " + + "**/Sort.java, **/Filter.java, **/ImageType.java, **/JpaConfiguration.java," + // domain-cvi-oauth-service "**/KakaoProfile.java, **/NaverProfile.java" } diff --git a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java index 5fe78ce6..ddbbbcbc 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java @@ -13,13 +13,25 @@ class BooleanToYNConverterTest { @Test @DisplayName("true 입력시 Y 반환") - void convertToDatabaseColumn() { + void convertToDatabaseColumnTrueToY() { assertThat(booleanToYNConverter.convertToDatabaseColumn(true)).isEqualTo("Y"); } + @Test + @DisplayName("false 입력시 N 반환") + void convertToDatabaseColumnFalseToN() { + assertThat(booleanToYNConverter.convertToDatabaseColumn(false)).isEqualTo("N"); + } + @Test @DisplayName("Y 입력시 true 반환") - void convertToEntityAttribute() { + void convertToEntityAttributeYToTrue() { assertThat(booleanToYNConverter.convertToEntityAttribute("Y")).isEqualTo(true); } + + @Test + @DisplayName("N 입력시 false 반환") + void convertToEntityAttributeNToFalse() { + assertThat(booleanToYNConverter.convertToEntityAttribute("N")).isEqualTo(false); + } } \ No newline at end of file From 6a279c743e7d57b8617e748eeee97a00253627e8 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 00:09:41 +0900 Subject: [PATCH 05/20] =?UTF-8?q?refactor:=20PostService=20=EC=93=B0?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=95=8A=EB=8A=94=20return=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0(=EC=9D=B8=EB=B9=84=ED=99=95=EC=9D=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/cvi/service/post/PostService.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java b/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java index 016df9fd..f95e3d49 100644 --- a/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java +++ b/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java @@ -78,17 +78,14 @@ private List getUploadedImageUrls(List imageRequests) { return imageUrls; } - private List assignPostToImages(Post post, List imageUrls) { - final List images = new ArrayList<>(); + private void assignPostToImages(Post post, List imageUrls) { for (String imageUrl : imageUrls) { final Image image = Image.builder() .url(imageUrl) .build(); image.assignPost(post); imageRepository.save(image); - images.add(image); } - return images; } @Transactional @@ -146,8 +143,7 @@ public void delete(Long id, Optional optionalUser) { User user = optionalUser.get(); Post post = findPostByPostId(id); post.validateAuthor(user); - deleteImagesFromAwsS3(post.getS3PathsOfAllImages()); - imageRepository.deleteAll(post.getAllImagesAsList()); + deleteAllImagesInPost(post); postRepository.deleteById(id); } From 155f7c81e83380f343e646a05f8de0a9d8732b8c Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:11:17 +0900 Subject: [PATCH 06/20] =?UTF-8?q?refactor:=20=EC=93=B0=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/cvi/post/domain/model/Sort.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java index d9af748f..6b8d5d83 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java @@ -25,14 +25,6 @@ public enum Sort { } public static OrderSpecifier toOrderSpecifier(Sort input) { - return Arrays.stream(values()) - .filter(Sort::isSameTypeOf) - .findAny() - .map(sort -> input.getSort()) - .orElseThrow(() -> new InvalidInputException("잘못된 정렬 형식입니다.")); - } - - private static boolean isSameTypeOf(Sort sort) { - return sort == sort; + return input.getSort(); } } \ No newline at end of file From b0203f8def23e0346351d39b01e5f7c0bbb558cf Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:36:27 +0900 Subject: [PATCH 07/20] =?UTF-8?q?refactor:=20Sort=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/cvi/service/post/PostService.java | 2 +- .../src/main/java/com/cvi/parser/AuthorizationManager.java | 2 +- .../src/main/java/com/cvi/post/domain/model/Sort.java | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java b/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java index f95e3d49..865aee06 100644 --- a/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java +++ b/backend/app-cvi-api/src/main/java/com/cvi/service/post/PostService.java @@ -105,7 +105,7 @@ public List findByVaccineType(VaccinationType vaccinationType, Opt } public List findByVaccineType(VaccinationType vaccinationType, int offset, int size, Sort sort, Optional optionalUser) { - List posts = postRepository.findByVaccineType(vaccinationType, offset, size, Sort.toOrderSpecifier(sort)); + List posts = postRepository.findByVaccineType(vaccinationType, offset, size, sort.getSort()); return PostResponse.toList(posts, optionalUser.orElse(null)); } diff --git a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java b/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java index fc0a56ef..a166f9ab 100644 --- a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java +++ b/backend/domain-cvi-oauth-service/src/main/java/com/cvi/parser/AuthorizationManager.java @@ -24,7 +24,7 @@ public UserInformation requestUserInfo(SocialProvider provider, String code, Str private Authorization extractAuthorization(SocialProvider provider) { validateSocialProvider(provider); - String key = provider.convertToComponentName(); + String key = provider.getProvider(); if (!authorizationMap.containsKey(key)) { log.info(String.format("해당 OAuth 제공자가 존재하지 않습니다 입력값: %s", key)); throw new InvalidOperationException(String.format("해당 OAuth 제공자가 존재하지 않습니다 입력값: %s", key)); diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java index 6b8d5d83..2a5ebff8 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java @@ -23,8 +23,4 @@ public enum Sort { Sort(OrderSpecifier sort) { this.sort = sort; } - - public static OrderSpecifier toOrderSpecifier(Sort input) { - return input.getSort(); - } } \ No newline at end of file From 617625b76def27b351c7e0a4494353ed60f1ba85 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:37:56 +0900 Subject: [PATCH 08/20] =?UTF-8?q?refactor:=20SocialProvider=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cvi/user/domain/model/SocialProvider.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java index 171edfb2..d4e1bc73 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java +++ b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/SocialProvider.java @@ -1,5 +1,8 @@ package com.cvi.user.domain.model; +import lombok.Getter; + +@Getter public enum SocialProvider { NAVER("naverAuthorization"), KAKAO("kakaoAuthorization"); @@ -9,8 +12,4 @@ public enum SocialProvider { SocialProvider(String provider) { this.provider = provider; } - - public String convertToComponentName() { - return this.provider; - } } From 4f86a5398f98d889c8e23139240fd112cce77d01 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:39:05 +0900 Subject: [PATCH 09/20] =?UTF-8?q?refactor:=20Post=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cvi/service/PostServiceTest.java | 5 +- .../com/cvi/post/domain/model/PostTest.java | 247 +++++++++++++----- .../domain/repository/PostRepositoryTest.java | 32 ++- 3 files changed, 210 insertions(+), 74 deletions(-) diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java index 24132ae6..845bcc76 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/PostServiceTest.java @@ -354,8 +354,9 @@ void createWithImages() { assertThat(postResponse.getImages()).containsExactly(IMAGE1_S3_URL, IMAGE2_S3_URL, IMAGE3_S3_URL); assertThat(foundPost).isNotNull(); + assertThat(foundPost.hasImages()).isTrue(); assertThat(foundPost.getUser()).isNotNull(); - assertThat(foundPost.getImages().getImages()) + assertThat(foundPost.getAllImagesAsList()) .extracting("url").containsExactly(IMAGE1_S3_URL, IMAGE2_S3_URL, IMAGE3_S3_URL); verify(awsS3Uploader, times(3)).upload(any(String.class), any(File.class)); @@ -439,7 +440,7 @@ void updateWithImages() { .orElseThrow(() -> new NotFoundException("게시글을 찾을 수 없음.")); //then assertThat(updatedPost.getContent()).isEqualTo(updateRequest.getContent()); - assertThat(updatedPost.getImages().getImages()) + assertThat(updatedPost.getAllImagesAsList()) .extracting("url").containsExactly(IMAGE4_S3_URL, IMAGE5_S3_URL); assertThat(imageRepository.findAll()).extracting("url").containsExactly(IMAGE4_S3_URL, IMAGE5_S3_URL); verify(awsS3Uploader, times(3)).delete(any(String.class), any(String.class)); diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java index fc3ba624..86211ed8 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java @@ -1,9 +1,5 @@ package com.cvi.post.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.CustomParameterizedTest; import com.cvi.comment.domain.model.Comment; import com.cvi.exception.InvalidOperationException; @@ -14,17 +10,20 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.*; + @DisplayName("게시글 도메인 테스트") class PostTest { @@ -37,27 +36,27 @@ class PostTest { @BeforeEach void init() { post = Post.builder() - .content("content1") - .vaccinationType(VaccinationType.ASTRAZENECA) - .createdAt(LocalDateTime.now()) - .build(); + .content("content1") + .vaccinationType(VaccinationType.ASTRAZENECA) + .createdAt(LocalDateTime.now()) + .build(); user = User.builder() - .id(1L) - .nickname("안녕하세욘") - .ageRange(AgeRange.TEENS) - .profileUrl("") - .socialProvider(SocialProvider.KAKAO) - .createdAt(LocalDateTime.now()) - .build(); + .id(1L) + .nickname("안녕하세욘") + .ageRange(AgeRange.TEENS) + .profileUrl("") + .socialProvider(SocialProvider.KAKAO) + .createdAt(LocalDateTime.now()) + .build(); comment = Comment.builder() - .id(1L) - .content("댓글입니다.") - .user(user) - .build(); + .id(1L) + .content("댓글입니다.") + .user(user) + .build(); like = Like.builder() - .id(1L) - .user(user) - .build(); + .id(1L) + .user(user) + .build(); image = Image.builder() .id(1L) .url("image1_s3_url/image") @@ -79,14 +78,14 @@ void assignUser() { void assignUserFailureWhenAlreadyExists() { //given User targetUser = User.builder() - .id(2L) - .nickname("독함") - .build(); + .id(2L) + .nickname("독함") + .build(); //when post.assignUser(user); //then assertThatThrownBy(() -> post.assignUser(targetUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 작성자 할당 - 실패 - 할당하려는 작성자가 없음") @@ -96,7 +95,7 @@ void assignUserFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignUser(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 댓글 할당 - 성공") @@ -127,7 +126,7 @@ void assignCommentFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignComment(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 댓글 수정") @@ -161,7 +160,7 @@ void updateCommentFailure() { post.assignComment(comment); //then assertThatThrownBy(() -> post.updateComment(1L, updateComment, anotherUser)) - .isInstanceOf(UnAuthorizedException.class); + .isInstanceOf(UnAuthorizedException.class); } @DisplayName("게시글 댓글 삭제") @@ -287,8 +286,8 @@ void increaseViewCount() { void update() { //given Post updatedPost = Post.builder() - .content("content2") - .build(); + .content("content2") + .build(); post.assignUser(user); //when post.updateContent(updatedPost, user); @@ -301,17 +300,17 @@ void update() { void updateFailWhenUserNotMatch() { //given User targetUser = User.builder() - .id(2L) - .nickname("라이언방구") - .build(); + .id(2L) + .nickname("라이언방구") + .build(); Post updatedPost = Post.builder() - .content("content2") - .build(); + .content("content2") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.updateContent(updatedPost, targetUser)) - .isExactlyInstanceOf(InvalidOperationException.class); + .isExactlyInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 작성자 확인 - 성공") @@ -319,17 +318,17 @@ void updateFailWhenUserNotMatch() { void deletePost() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatCode(() -> post.validateAuthor(user)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } @DisplayName("게시글 작성자 확인 - 실패 - 글 작성자가 아님") @@ -337,21 +336,135 @@ void deletePost() { void deletePostFailureWhenNotAuthor() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); + User otherUser = User.builder() + .id(3L) + .nickname("라이언") + .build(); + Post post = Post.builder() + .content("내용") + .build(); + post.assignUser(user); + //when + //then + assertThatThrownBy(() -> post.validateAuthor(otherUser)) + .isInstanceOf(InvalidOperationException.class); + } + + @DisplayName("게시글 좋아요 이미 누름") + @Test + void isAlreadyLikedBy() { + //given + post.assignLike(like); + //when + //then + assertThat(post.isAlreadyLikedBy(user)).isTrue(); + } + + @DisplayName("게시글 좋아요 누르지 않음") + @Test + void isNotLikedBy() { + //given + //when + //then + assertThat(post.isAlreadyLikedBy(null)).isFalse(); + } + + @DisplayName("게시글 작성자 확인 - 실패 - 글 작성자가 아님") + @Test + void isNotAlreadyLikedBy() { + //given + User user = User.builder() + .id(2L) + .nickname("인비") + .build(); User otherUser = User.builder() - .id(3L) - .nickname("라이언") - .build(); + .id(3L) + .nickname("라이언") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.validateAuthor(otherUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); + } + + @DisplayName("게시글이 이미지 보유 확인 - 있음") + @Test + void hasImages() { + //given + Image image1 = Image.builder() + .url("s3/image1_s3_url") + .id(1L) + .build(); + Image image2 = Image.builder() + .url("s3/image2_s3_url") + .id(2L) + .build(); + image1.assignPost(post); + image2.assignPost(post); + post.assignImages(Arrays.asList(image1, image2)); + //when + final boolean hasImages = post.hasImages(); + //then + assertThat(hasImages).isTrue(); + } + + @DisplayName("게시글이 이미지 보유 확인 - 없음") + @Test + void hasNoImages() { + //given + //when + final boolean hasImages = post.hasImages(); + //then + assertThat(hasImages).isFalse(); + } + + @DisplayName("게시글이 이미지 보유 확인 - url 확인") + @Test + void getImagesAsUrlList() { + //given + Image image1 = Image.builder() + .url("s3/image1_s3_url") + .id(1L) + .build(); + Image image2 = Image.builder() + .url("s3/image2_s3_url") + .id(2L) + .build(); + image1.assignPost(post); + image2.assignPost(post); + post.assignImages(Arrays.asList(image1, image2)); + //when + final List imagesAsUrlList = post.getImagesAsUrlList(); + //then + assertThat(imagesAsUrlList).containsExactly("s3/image1_s3_url", "s3/image2_s3_url"); + } + + @DisplayName("게시글 s3url 이미지 보유 확인 - s3 url 확인") + @Test + void getS3PathsOfAllImages() { + //given + Image image1 = Image.builder() + .url("s3/image1_s3_url") + .id(1L) + .build(); + Image image2 = Image.builder() + .url("s3/image2_s3_url") + .id(2L) + .build(); + image1.assignPost(post); + image2.assignPost(post); + post.assignImages(Arrays.asList(image1, image2)); + //when + final List imagesAsUrlList = post.getS3PathsOfAllImages(); + //then + assertThat(imagesAsUrlList).containsExactly("image1_s3_url", "image2_s3_url"); } @DisplayName("페이징 요청 값 resize - 성공") @@ -360,13 +473,13 @@ void deletePostFailureWhenNotAuthor() { void resizePagingRangeTest(int offset, int size, List contentResult) { //given User user = User.builder() - .id(1L) - .nickname("인비") - .build(); + .id(1L) + .nickname("인비") + .build(); Post post = Post.builder() - .content("내용") - .user(user) - .build(); + .content("내용") + .user(user) + .build(); Comment comment1 = Comment.builder().content("댓글1").user(user).createdAt(LocalDateTime.now().minusHours(1L)).build(); Comment comment2 = Comment.builder().content("댓글2").user(user).createdAt(LocalDateTime.now().minusHours(2L)).build(); post.assignComment(comment1); @@ -379,10 +492,10 @@ void resizePagingRangeTest(int offset, int size, List contentResult) { static Stream resizePagingRangeTest() { return Stream.of( - Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), - Arguments.of(1, 1, Arrays.asList("댓글2")), - Arguments.of(0, 1, Arrays.asList("댓글1")), - Arguments.of(2, 1, Collections.emptyList()) + Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), + Arguments.of(1, 1, Arrays.asList("댓글2")), + Arguments.of(0, 1, Arrays.asList("댓글1")), + Arguments.of(2, 1, Collections.emptyList()) ); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java index 1d05a691..4eb134f9 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java @@ -97,19 +97,19 @@ private void initPost() { .user(user1) .content("화이자 1차 맞았어요.") .vaccinationType(VaccinationType.PFIZER) - .createdAt(LocalDateTime.now().minusDays(1)) + .createdAt(LocalDateTime.now().minusHours(3)) .build(); post2 = Post.builder() .user(user2) .content("모더나 1차 맞았어요.") .vaccinationType(VaccinationType.MODERNA) - .createdAt(LocalDateTime.now()) + .createdAt(LocalDateTime.now().minusHours(2)) .build(); post3 = Post.builder() .user(user1) .content("화이자 2차 맞았어요.") .vaccinationType(VaccinationType.PFIZER) - .createdAt(LocalDateTime.now()) + .createdAt(LocalDateTime.now().minusHours(1)) .build(); postRepository.save(post1); postRepository.save(post2); @@ -240,13 +240,13 @@ void deleteImage() { void findByVaccineTypePaging() { //given //when - List posts = postRepository.findByVaccineType(VaccinationType.PFIZER, 0, 3, Sort.toOrderSpecifier(Sort.CREATED_AT_DESC)); + List posts = postRepository.findByVaccineType(VaccinationType.PFIZER, 0, 3, Sort.CREATED_AT_DESC.getSort()); //then assertThat(posts).extracting("id").containsExactlyElementsOf(Arrays.asList(post3.getId(), post1.getId())); assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post1.getContent())); } - @DisplayName("백신 타입별 조회") + @DisplayName("백신 타입별 조회 - 특정 타입 검색") @Test void findByVaccineType() { //given @@ -257,6 +257,28 @@ void findByVaccineType() { assertThat(posts).extracting("content").containsExactlyElementsOf(Collections.singletonList(post2.getContent())); } + @DisplayName("백신 타입별 조회 - 백신타입이 주어지지 않은 경우 모든 타입 검색") + @Test + void findByVaccineTypeNull() { + //given + //when + List posts = postRepository.findByVaccineType(null); + //then + assertThat(posts).hasSize(3); + assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent())); + } + + @DisplayName("백신 타입별 조회 - All로 주어지는 경우 모든 타입 검색") + @Test + void findByVaccineTypeAll() { + //given + //when + List posts = postRepository.findByVaccineType(VaccinationType.ALL); + //then + assertThat(posts).hasSize(3); + assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent())); + } + @DisplayName("작성자 ID로 게시글 페이징 조회") @Test void findByUserId() { From 060c818c50bd2a71235a96efed19407950c94271 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:39:27 +0900 Subject: [PATCH 10/20] =?UTF-8?q?refactor:=20LikeRepositoryTest=20?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cvi/like/domain/repository/LikeRepositoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index 98886375..357f4bab 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -112,7 +112,7 @@ private void assertIdAssigned() { assertThat(post1.getId()).isNotNull(); } - @DisplayName("유저 아이디로 좋아요를 조회한다.") + @DisplayName("유저 아이디로 좋아요를 조회한다. - 성공") @Test void findCommentByUserId() { //given From cd7401c360fc9c0188167a1bc8541e931a4ab003 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:39:51 +0900 Subject: [PATCH 11/20] =?UTF-8?q?refactor:=20UserTest=20update=20=EC=BC=80?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/domain-cvi/build.gradle | 2 +- .../java/com/cvi/user/domain/model/UserTest.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/domain-cvi/build.gradle b/backend/domain-cvi/build.gradle index 7b1f1ff0..a9210cec 100644 --- a/backend/domain-cvi/build.gradle +++ b/backend/domain-cvi/build.gradle @@ -31,7 +31,7 @@ jacocoTestCoverageVerification { // 코드 커버리지 측정항목 시행 limit { counter = 'INSTRUCTION' value = 'COVEREDRATIO' - minimum = 0.85 + minimum = 0.95 } excludes = [ diff --git a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java index 01f63ab1..a7a9d677 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java @@ -4,10 +4,13 @@ import com.cvi.exception.InvalidInputException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; import java.time.LocalDateTime; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.*; @@ -65,20 +68,27 @@ void saveFailure(String name) { @DisplayName("사용자 수정 - 성공") @CustomParameterizedTest - @ValueSource(strings = {"ㅁㅇㄹㅁㅇㄹ", "ㅓㅓㅓㅓ", "adfdf", "검프", "검프23213"}) - void update(String name) { + @MethodSource + void update(String name, AgeRange ageRange, boolean shotVerified) { //given User updateUser = User.builder() .id(1L) - .ageRange(AgeRange.TWENTIES) + .ageRange(ageRange) .createdAt(LocalDateTime.now()) .nickname(name) .profileUrl("www.budae.com") + .shotVerified(shotVerified) .socialProvider(SocialProvider.KAKAO) .build(); //when user.update(updateUser); //then assertThat(user.getNickname()).isEqualTo(updateUser.getNickname()); + assertThat(user.getAgeRange()).isEqualTo(updateUser.getAgeRange()); + assertThat(user.isShotVerified()).isEqualTo(updateUser.isShotVerified()); + } + + static Stream update(){ + return Stream.of(Arguments.of("1", AgeRange.TWENTIES, true), Arguments.of("2", AgeRange.THIRTIES, false)); } } From 67ccddc89957534899e91aecc8f5d219103e9392 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 01:54:25 +0900 Subject: [PATCH 12/20] =?UTF-8?q?refactor:=20sonarcube=20=EB=B2=84?= =?UTF-8?q?=EA=B7=B8=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/com/cvi/service/CommentServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java index b0583bd7..1fa79c4a 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java @@ -160,6 +160,7 @@ void updateCommentWhenWrongUser() { void deleteComment() { //given CommentResponse commentResponse = commentService.createComment(post.getId(), optionalUser, commentRequest); + commentService.createComment(post.getId(), optionalUser, commentRequest); //when commentService.deleteComment(post.getId(), commentResponse.getId(), optionalUser); postRepository.flush(); From c6d742a2dc0cf43c11ada814d0d18adf0d3317f9 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 02:00:31 +0900 Subject: [PATCH 13/20] =?UTF-8?q?refactor:=20=EC=BB=A4=EB=B2=84=EB=A6=AC?= =?UTF-8?q?=EC=A7=80=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/domain-cvi/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/domain-cvi/build.gradle b/backend/domain-cvi/build.gradle index a9210cec..7b1f1ff0 100644 --- a/backend/domain-cvi/build.gradle +++ b/backend/domain-cvi/build.gradle @@ -31,7 +31,7 @@ jacocoTestCoverageVerification { // 코드 커버리지 측정항목 시행 limit { counter = 'INSTRUCTION' value = 'COVEREDRATIO' - minimum = 0.95 + minimum = 0.85 } excludes = [ From ce657512ae532938fb855af434d0f418a560e6b4 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 02:04:31 +0900 Subject: [PATCH 14/20] =?UTF-8?q?refactor:=20UserInformation.java=20?= =?UTF-8?q?=EB=91=90=EA=B0=9C=20=EC=9E=88=EB=8D=98=EA=B1=B0=20=ED=95=98?= =?UTF-8?q?=EB=82=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cvi/dto/UserInformation.java | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java diff --git a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java b/backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java deleted file mode 100644 index 67ce5ae6..00000000 --- a/backend/domain-cvi-oauth-service/src/main/java/com/cvi/dto/UserInformation.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.cvi.dto; - -import com.cvi.dto.profile.SocialProfile; -import lombok.Getter; - -import javax.validation.constraints.NotBlank; - -@Getter -public class UserInformation { - - @NotBlank(message = "socialId(OAuth 고유의 id)는 null, '', ' ' 일 수 없습니다.") - private final String socialId; - - @NotBlank(message = "socialProfileUrl(OAuth profile url)은 null일 수 없습니다.") - private final String socialProfileUrl; - - private UserInformation(String socialId, String socialProfileUrl) { - this.socialId = socialId; - this.socialProfileUrl = socialProfileUrl; - } - - public static UserInformation of(SocialProfile socialProfile) { - return new UserInformation(socialProfile.extractSocialId(), socialProfile.extractProfileUrl()); - } -} From c16fc8fd4d5aa906f5fb7d12a19bbc21d483cbb1 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 02:58:49 +0900 Subject: [PATCH 15/20] =?UTF-8?q?refactor:=20=EC=86=8C=EB=82=98=ED=81=90?= =?UTF-8?q?=EB=B8=8C=20=EB=B2=84=EA=B7=B8=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/com/cvi/service/CommentServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java index 1fa79c4a..511ddfc6 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java @@ -160,7 +160,6 @@ void updateCommentWhenWrongUser() { void deleteComment() { //given CommentResponse commentResponse = commentService.createComment(post.getId(), optionalUser, commentRequest); - commentService.createComment(post.getId(), optionalUser, commentRequest); //when commentService.deleteComment(post.getId(), commentResponse.getId(), optionalUser); postRepository.flush(); @@ -169,6 +168,7 @@ void deleteComment() { Post foundPost = postRepository.findById(this.post.getId()).get(); //then assertThat(foundComment).isEmpty(); + assertThat(foundPost.getCommentsAsList()).isNotEmpty(); assertThat(foundPost.getCommentsAsList()).extracting("id").doesNotContain(commentResponse.getId()); } From c0b8d7d61374a39904f25311b341f460512ec5af Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 04:03:26 +0900 Subject: [PATCH 16/20] =?UTF-8?q?refactor:=20=EC=86=8C=EB=82=98=ED=81=90?= =?UTF-8?q?=EB=B8=8C=20=EB=B2=84=EA=B7=B8=20=EB=A6=AC=ED=8F=AC=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/test/java/com/cvi/service/CommentServiceTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java index 511ddfc6..c490fac8 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/CommentServiceTest.java @@ -168,8 +168,7 @@ void deleteComment() { Post foundPost = postRepository.findById(this.post.getId()).get(); //then assertThat(foundComment).isEmpty(); - assertThat(foundPost.getCommentsAsList()).isNotEmpty(); - assertThat(foundPost.getCommentsAsList()).extracting("id").doesNotContain(commentResponse.getId()); + assertThat(foundPost.getCommentsAsList()).isEmpty(); } @DisplayName("댓글 삭제 - 실패 - 댓글을 찾을 수 없음") From 29a32e7b609413f0e1e681eb87cfc7cd9c43c327 Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 11:16:56 +0900 Subject: [PATCH 17/20] =?UTF-8?q?refactor:=20displayname=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EA=B5=AC=EC=B2=B4=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cvi/comment/domain/repository/CommentRepositoryTest.java | 4 ++-- .../java/com/cvi/image/repository/ImageRepositoryTest.java | 2 +- .../com/cvi/like/domain/repository/LikeRepositoryTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java index 547e954c..078e9c67 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java @@ -116,7 +116,7 @@ void findCommentByUserId() { assertThat(commentRepository.findByUserId(user2.getId())).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 조회한다. - 실패") + @DisplayName("유저 아이디로 댓글을 조회한다. - null인 경우") @Test void findCommentByUserIdFailure() { //given @@ -135,7 +135,7 @@ void findCommentByUserIdPaging() { assertThat(commentRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - 실패") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - null인 경우") @Test void findCommentByUserIdPagingFailure() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index cadf0a73..ab62d1e4 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -81,7 +81,7 @@ void assignPostToImage() { assertThat(image.getPost()).isEqualTo(post); } - @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 실패") + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - null인 경우") @Test void assignPostToImageFailure() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index 357f4bab..becc9649 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -141,7 +141,7 @@ void findCommentByUserIdPaging() { assertThat(likeRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - 실패") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - null인 경우") @Test void findCommentByUserIdPagingFailure() { //given From 0237e91371d4ff32cb58a5b348256e6cad36965b Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 12:07:08 +0900 Subject: [PATCH 18/20] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cvi/service/PostFindServiceTest.java | 2 +- backend/build.gradle | 2 +- .../config/entity/BooleanToYNConverter.java | 6 +- .../java/com/cvi/post/domain/model/Sort.java | 2 +- .../cvi/comment/domain/model/CommentTest.java | 4 +- .../repository/CommentRepositoryTest.java | 12 ++-- .../entity/BooleanToYNConverterTest.java | 10 +-- .../java/com/cvi/image/model/ImageTest.java | 2 +- .../image/repository/ImageRepositoryTest.java | 8 +-- .../com/cvi/like/domain/model/LikeTest.java | 2 +- .../domain/repository/LikeRepositoryTest.java | 19 ++--- .../com/cvi/post/domain/model/PostTest.java | 69 ++++++------------- .../domain/repository/PostRepositoryTest.java | 12 ++-- .../com/cvi/user/domain/model/UserTest.java | 5 +- 14 files changed, 64 insertions(+), 91 deletions(-) diff --git a/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java b/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java index 6e452b4e..f6568e64 100644 --- a/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java +++ b/backend/app-cvi-api/src/test/java/com/cvi/service/PostFindServiceTest.java @@ -194,7 +194,7 @@ void findByVaccineTypeNextPageAll() { List postResponses = postService.findByVaccineType(VaccinationType.ALL, 1, 1, Sort.CREATED_AT_DESC, optionalUser); //then assertThat(postResponses).size().isEqualTo(1); - assertThat(postResponses).extracting("content").containsExactlyElementsOf(Arrays.asList("Test 1")); + assertThat(postResponses).extracting("content").containsExactlyElementsOf(Collections.singletonList("Test 1")); assertThat(postResponses).extracting("vaccinationType").filteredOn(vaccinationType -> vaccinationType instanceof VaccinationType); } diff --git a/backend/build.gradle b/backend/build.gradle index 7d8ee384..aeb058c2 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -107,7 +107,7 @@ subprojects { // cvi-publicdata-parser "**/Parser.java, " + // domain-cvi - "**/Sort.java, **/Filter.java, **/ImageType.java, **/JpaConfiguration.java," + + "**/Sort.java, **/Filter.java, **/ImageType.java, **/JpaConfiguration.java, " + // domain-cvi-oauth-service "**/KakaoProfile.java, **/NaverProfile.java" } diff --git a/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java b/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java index 658763eb..6b4332f8 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java +++ b/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java @@ -9,10 +9,10 @@ public class BooleanToYNConverter implements AttributeConverter @Override public String convertToDatabaseColumn(Boolean attribute) { - if (!Objects.isNull(attribute) && attribute) { - return "Y"; + if (Objects.isNull(attribute) || !attribute) { + return "N"; } - return "N"; + return "Y"; } @Override diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java index 2a5ebff8..53e14859 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java @@ -23,4 +23,4 @@ public enum Sort { Sort(OrderSpecifier sort) { this.sort = sort; } -} \ No newline at end of file +} diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java index 5209a98f..e27986fe 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java @@ -136,7 +136,7 @@ void updateFailure() { assertThatThrownBy(() -> comment.update(updateComment, anotherUser)).isInstanceOf(UnAuthorizedException.class); } - @DisplayName("댓글 작성자가 같은 지 확인") + @DisplayName("댓글 작성자가 같은 지 확인 - 성공") @Test void isSameUser() { //given @@ -147,7 +147,7 @@ void isSameUser() { assertThat(comment.isSameUser(user)).isTrue(); } - @DisplayName("같은 댓글인지 확인") + @DisplayName("같은 댓글인지 확인 - 성공") @Test void isSameAs() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java index 078e9c67..0d4a344d 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java @@ -106,7 +106,7 @@ private void assertIdAssigned() { assertThat(post1.getId()).isNotNull(); } - @DisplayName("유저 아이디로 댓글을 조회한다. - 성공") + @DisplayName("유저 아이디로 댓글을 조회한다 - 성공") @Test void findCommentByUserId() { //given @@ -116,16 +116,16 @@ void findCommentByUserId() { assertThat(commentRepository.findByUserId(user2.getId())).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 조회한다. - null인 경우") + @DisplayName("유저 아이디로 댓글을 조회한다 - 성공 - null인 경우") @Test - void findCommentByUserIdFailure() { + void findCommentByUserIdWhenNull() { //given //when //then assertThat(commentRepository.findByUserId(null)).hasSize(3); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - 성공") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다 - 성공") @Test void findCommentByUserIdPaging() { //given @@ -135,9 +135,9 @@ void findCommentByUserIdPaging() { assertThat(commentRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - null인 경우") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다 - 성공 - null인 경우") @Test - void findCommentByUserIdPagingFailure() { + void findCommentByUserIdPagingWhenNull() { //given //when //then diff --git a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java index ddbbbcbc..0d9ac89d 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java @@ -12,26 +12,26 @@ class BooleanToYNConverterTest { private final BooleanToYNConverter booleanToYNConverter = new BooleanToYNConverter(); @Test - @DisplayName("true 입력시 Y 반환") + @DisplayName("true 입력시 Y 반환 - 성공") void convertToDatabaseColumnTrueToY() { assertThat(booleanToYNConverter.convertToDatabaseColumn(true)).isEqualTo("Y"); } @Test - @DisplayName("false 입력시 N 반환") + @DisplayName("false 입력시 N 반환 - 성공") void convertToDatabaseColumnFalseToN() { assertThat(booleanToYNConverter.convertToDatabaseColumn(false)).isEqualTo("N"); } @Test - @DisplayName("Y 입력시 true 반환") + @DisplayName("Y 입력시 true 반환 - 성공") void convertToEntityAttributeYToTrue() { assertThat(booleanToYNConverter.convertToEntityAttribute("Y")).isEqualTo(true); } @Test - @DisplayName("N 입력시 false 반환") + @DisplayName("N 입력시 false 반환 - 성공") void convertToEntityAttributeNToFalse() { assertThat(booleanToYNConverter.convertToEntityAttribute("N")).isEqualTo(false); } -} \ No newline at end of file +} diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java index a2c8c2de..cce9c643 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java @@ -9,7 +9,7 @@ @DisplayName("Image 도메인 테스트") class ImageTest { - @DisplayName("객체 주소값, 내용이 달라도 id만 같으면 동일한 객체로 본다.") + @DisplayName("객체 주소값, 내용이 달라도 id만 같으면 동일한 객체 - 성공") @Test void equalsAndHashcode() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index ab62d1e4..4478b512 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -59,7 +59,7 @@ void setUp() { postRepository.save(post); } - @DisplayName("Post에 Image 추가 시 양방향 매핑 테스트") + @DisplayName("Post에 Image 추가 시 양방향 매핑 테스트 - 성공") @Test void assignImageToPost() { //given @@ -70,7 +70,7 @@ void assignImageToPost() { assertThat(image.getPost()).isEqualTo(post); } - @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트") + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 성공") @Test void assignPostToImage() { //given @@ -81,9 +81,9 @@ void assignPostToImage() { assertThat(image.getPost()).isEqualTo(post); } - @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - null인 경우") + @DisplayName("Image에 Post 추가 시 양방향 매핑 테스트 - 성공 - null인 경우") @Test - void assignPostToImageFailure() { + void assignPostToImageWhenNull() { //given //when //then diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java index c58dba92..743a29eb 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java @@ -71,7 +71,7 @@ void assignPostFailureWhenAlreadyAssignedPost() { assertThatThrownBy(() -> like.assignPost(post)).isInstanceOf(InvalidOperationException.class); } - @DisplayName("좋아요 누른 유저인지 확인") + @DisplayName("좋아요 누른 유저인지 확인 - 성공") @Test void isSameUser() { //given diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index becc9649..2614e662 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -1,8 +1,5 @@ package com.cvi.like.domain.repository; -import com.cvi.comment.domain.model.Comment; -import com.cvi.comment.domain.repository.CommentRepository; -import com.cvi.exception.NotFoundException; import com.cvi.like.domain.model.Like; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; @@ -18,8 +15,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.*; @DisplayName("LikeRepository 테스트") @DataJpaTest @@ -112,7 +107,7 @@ private void assertIdAssigned() { assertThat(post1.getId()).isNotNull(); } - @DisplayName("유저 아이디로 좋아요를 조회한다. - 성공") + @DisplayName("유저 아이디로 좋아요를 조회한다 - 성공") @Test void findCommentByUserId() { //given @@ -122,16 +117,16 @@ void findCommentByUserId() { assertThat(likeRepository.findByUserId(user2.getId())).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 조회한다. - 실패") + @DisplayName("유저 아이디로 댓글을 조회한다 - 실패") @Test - void findCommentByUserIdFailure() { + void findCommentByUserIdWhenNull() { //given //when //then assertThat(likeRepository.findByUserId(null)).hasSize(3); } - @DisplayName("유저 아이디로 좋아요를 페이징 조회한다.") + @DisplayName("유저 아이디로 좋아요를 페이징 조회한다 - 성공") @Test void findCommentByUserIdPaging() { //given @@ -141,12 +136,12 @@ void findCommentByUserIdPaging() { assertThat(likeRepository.findByUserId(user2.getId(), 0, 2)).hasSize(2); } - @DisplayName("유저 아이디로 댓글을 페이징 조회한다. - null인 경우") + @DisplayName("유저 아이디로 댓글을 페이징 조회한다 - 성공 - null인 경우") @Test - void findCommentByUserIdPagingFailure() { + void findCommentByUserIdPagingWhenNull() { //given //when //then assertThat(likeRepository.findByUserId(null, 0, 2)).hasSize(2); } -} \ No newline at end of file +} diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java index 86211ed8..d8b0638d 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java @@ -129,7 +129,7 @@ void assignCommentFailureWhenNull() { .isInstanceOf(NotFoundException.class); } - @DisplayName("게시글 댓글 수정") + @DisplayName("게시글 댓글 수정 - 성공") @Test void updateComment() { //given @@ -163,7 +163,7 @@ void updateCommentFailure() { .isInstanceOf(UnAuthorizedException.class); } - @DisplayName("게시글 댓글 삭제") + @DisplayName("게시글 댓글 삭제 - 성공") @Test void deleteCommentInComments() { //given @@ -231,7 +231,7 @@ void assignLikeFailureWhenNull() { void assignImage() { //given //when - post.assignImages(Arrays.asList(image)); + post.assignImages(Collections.singletonList(image)); //then assertThat(post.getAllImagesAsList()).hasSize(1); } @@ -246,7 +246,7 @@ void assignImagesFailureWhenAlreadyExists() { .isInstanceOf(NotFoundException.class); } - @DisplayName("게시글 이미지 삭제") + @DisplayName("게시글 이미지 삭제 - 성공") @Test void delete() { //given @@ -258,7 +258,7 @@ void delete() { assertThat(images.getImages()).isEmpty(); } - @DisplayName("게시글의 모든 이미지 주소 조회") + @DisplayName("게시글의 모든 이미지 주소 조회 - 성공") @Test void s3PathsOfAllImages() { //given @@ -353,7 +353,7 @@ void deletePostFailureWhenNotAuthor() { .isInstanceOf(InvalidOperationException.class); } - @DisplayName("게시글 좋아요 이미 누름") + @DisplayName("게시글 좋아요 이미 누름 - 성공") @Test void isAlreadyLikedBy() { //given @@ -363,7 +363,7 @@ void isAlreadyLikedBy() { assertThat(post.isAlreadyLikedBy(user)).isTrue(); } - @DisplayName("게시글 좋아요 누르지 않음") + @DisplayName("게시글 좋아요 누르지 않음 - 성공") @Test void isNotLikedBy() { //given @@ -394,28 +394,19 @@ void isNotAlreadyLikedBy() { .isInstanceOf(InvalidOperationException.class); } - @DisplayName("게시글이 이미지 보유 확인 - 있음") + @DisplayName("게시글이 이미지 보유 확인 - 성공 - 있음") @Test void hasImages() { //given - Image image1 = Image.builder() - .url("s3/image1_s3_url") - .id(1L) - .build(); - Image image2 = Image.builder() - .url("s3/image2_s3_url") - .id(2L) - .build(); - image1.assignPost(post); - image2.assignPost(post); - post.assignImages(Arrays.asList(image1, image2)); + image.assignPost(post); + post.assignImages(Collections.singletonList(image)); //when final boolean hasImages = post.hasImages(); //then assertThat(hasImages).isTrue(); } - @DisplayName("게시글이 이미지 보유 확인 - 없음") + @DisplayName("게시글이 이미지 보유 확인 - 성공 - 없음") @Test void hasNoImages() { //given @@ -425,46 +416,28 @@ void hasNoImages() { assertThat(hasImages).isFalse(); } - @DisplayName("게시글이 이미지 보유 확인 - url 확인") + @DisplayName("게시글이 이미지 보유 확인 - 성공 - url 확인") @Test void getImagesAsUrlList() { //given - Image image1 = Image.builder() - .url("s3/image1_s3_url") - .id(1L) - .build(); - Image image2 = Image.builder() - .url("s3/image2_s3_url") - .id(2L) - .build(); - image1.assignPost(post); - image2.assignPost(post); - post.assignImages(Arrays.asList(image1, image2)); + image.assignPost(post); + post.assignImages(Collections.singletonList(image)); //when final List imagesAsUrlList = post.getImagesAsUrlList(); //then - assertThat(imagesAsUrlList).containsExactly("s3/image1_s3_url", "s3/image2_s3_url"); + assertThat(imagesAsUrlList).containsExactly("image1_s3_url/image"); } - @DisplayName("게시글 s3url 이미지 보유 확인 - s3 url 확인") + @DisplayName("게시글 s3url 이미지 보유 확인 - 성공 - s3 url 확인") @Test void getS3PathsOfAllImages() { //given - Image image1 = Image.builder() - .url("s3/image1_s3_url") - .id(1L) - .build(); - Image image2 = Image.builder() - .url("s3/image2_s3_url") - .id(2L) - .build(); - image1.assignPost(post); - image2.assignPost(post); - post.assignImages(Arrays.asList(image1, image2)); + image.assignPost(post); + post.assignImages(Collections.singletonList(image)); //when final List imagesAsUrlList = post.getS3PathsOfAllImages(); //then - assertThat(imagesAsUrlList).containsExactly("image1_s3_url", "image2_s3_url"); + assertThat(imagesAsUrlList).containsExactly("image"); } @DisplayName("페이징 요청 값 resize - 성공") @@ -493,8 +466,8 @@ void resizePagingRangeTest(int offset, int size, List contentResult) { static Stream resizePagingRangeTest() { return Stream.of( Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), - Arguments.of(1, 1, Arrays.asList("댓글2")), - Arguments.of(0, 1, Arrays.asList("댓글1")), + Arguments.of(1, 1, Collections.singletonList("댓글2")), + Arguments.of(0, 1, Collections.singletonList("댓글1")), Arguments.of(2, 1, Collections.emptyList()) ); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java index 4eb134f9..d941c80c 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java @@ -242,8 +242,10 @@ void findByVaccineTypePaging() { //when List posts = postRepository.findByVaccineType(VaccinationType.PFIZER, 0, 3, Sort.CREATED_AT_DESC.getSort()); //then - assertThat(posts).extracting("id").containsExactlyElementsOf(Arrays.asList(post3.getId(), post1.getId())); - assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post1.getContent())); + final List extractedIds = Arrays.asList(post3.getId(), post1.getId()); + assertThat(posts).extracting("id").containsExactlyElementsOf(extractedIds); + final List extractedContents = Arrays.asList(post3.getContent(), post1.getContent()); + assertThat(posts).extracting("content").containsExactlyElementsOf(extractedContents); } @DisplayName("백신 타입별 조회 - 특정 타입 검색") @@ -265,7 +267,8 @@ void findByVaccineTypeNull() { List posts = postRepository.findByVaccineType(null); //then assertThat(posts).hasSize(3); - assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent())); + final List extractedContents = Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent()); + assertThat(posts).extracting("content").containsExactlyElementsOf(extractedContents); } @DisplayName("백신 타입별 조회 - All로 주어지는 경우 모든 타입 검색") @@ -276,7 +279,8 @@ void findByVaccineTypeAll() { List posts = postRepository.findByVaccineType(VaccinationType.ALL); //then assertThat(posts).hasSize(3); - assertThat(posts).extracting("content").containsExactlyElementsOf(Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent())); + final List extractedContents = Arrays.asList(post3.getContent(), post2.getContent(), post1.getContent()); + assertThat(posts).extracting("content").containsExactlyElementsOf(extractedContents); } @DisplayName("작성자 ID로 게시글 페이징 조회") diff --git a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java index a7a9d677..6e5977f4 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java @@ -88,7 +88,8 @@ void update(String name, AgeRange ageRange, boolean shotVerified) { assertThat(user.isShotVerified()).isEqualTo(updateUser.isShotVerified()); } - static Stream update(){ - return Stream.of(Arguments.of("1", AgeRange.TWENTIES, true), Arguments.of("2", AgeRange.THIRTIES, false)); + static Stream update() { + return Stream.of(Arguments.of("1", AgeRange.TWENTIES, true), + Arguments.of("2", AgeRange.THIRTIES, false)); } } From bf18137bc5212a839475234af4b7f677b0ae976f Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 12:12:39 +0900 Subject: [PATCH 19/20] style: auto-formatting --- .../repository/CommentRepositoryImpl.java | 20 +- .../main/java/com/cvi/image/domain/Image.java | 15 +- .../domain/repository/LikeRepositoryImpl.java | 20 +- .../com/cvi/post/domain/model/Images.java | 13 +- .../java/com/cvi/post/domain/model/Post.java | 23 +-- .../java/com/cvi/post/domain/model/Sort.java | 6 +- .../domain/repository/PostRepositoryImpl.java | 13 +- .../domain/model/RegionPopulation.java | 3 +- .../domain/model/VaccinationStatistic.java | 4 +- .../java/com/cvi/user/domain/model/User.java | 5 - .../cvi/comment/domain/model/CommentTest.java | 9 +- .../repository/CommentRepositoryTest.java | 53 +++-- .../entity/BooleanToYNConverterTest.java | 1 - .../java/com/cvi/image/model/ImageTest.java | 22 +-- .../image/repository/ImageRepositoryTest.java | 33 ++-- .../com/cvi/like/domain/model/LikeTest.java | 9 +- .../domain/repository/LikeRepositoryTest.java | 52 ++--- .../com/cvi/post/domain/model/PostTest.java | 182 +++++++++--------- .../domain/repository/PostRepositoryTest.java | 18 +- .../model/VaccinationStatisticFactory.java | 84 ++++---- .../model/VaccinationStatisticTest.java | 56 +++--- .../model/VaccinationStatisticsTest.java | 22 +-- .../com/cvi/user/domain/model/UserTest.java | 54 +++--- 23 files changed, 346 insertions(+), 371 deletions(-) diff --git a/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java index 318ee350..30ee70f2 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/comment/domain/repository/CommentRepositoryImpl.java @@ -23,21 +23,21 @@ public CommentRepositoryImpl(EntityManager em) { @Override public List findByUserId(Long userId) { return queryFactory.selectFrom(comment) - .leftJoin(comment.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(comment.createdAt.desc()) - .fetch(); + .leftJoin(comment.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(comment.createdAt.desc()) + .fetch(); } @Override public List findByUserId(Long userId, int offset, int size) { return queryFactory.selectFrom(comment) - .leftJoin(comment.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(comment.createdAt.desc()) - .offset(offset) - .limit(size) - .fetch(); + .leftJoin(comment.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(comment.createdAt.desc()) + .offset(offset) + .limit(size) + .fetch(); } private BooleanExpression userIdEq(Long userId) { diff --git a/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java b/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java index 4b65c7f3..04bed092 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java +++ b/backend/domain-cvi/src/main/java/com/cvi/image/domain/Image.java @@ -4,21 +4,16 @@ import com.cvi.config.entity.BaseEntity; import com.cvi.exception.NotFoundException; import com.cvi.post.domain.model.Post; -import java.time.LocalDateTime; -import java.util.Collections; -import java.util.Objects; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.Objects; + @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java index c3253449..db98b83d 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/like/domain/repository/LikeRepositoryImpl.java @@ -22,21 +22,21 @@ public LikeRepositoryImpl(EntityManager em) { @Override public List findByUserId(Long userId) { return queryFactory.selectFrom(like) - .leftJoin(like.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(like.createdAt.desc()) - .fetch(); + .leftJoin(like.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(like.createdAt.desc()) + .fetch(); } @Override public List findByUserId(Long userId, int offset, int size) { return queryFactory.selectFrom(like) - .leftJoin(like.user, user).fetchJoin() - .where(userIdEq(userId)) - .orderBy(like.createdAt.desc()) - .offset(offset) - .limit(size) - .fetch(); + .leftJoin(like.user, user).fetchJoin() + .where(userIdEq(userId)) + .orderBy(like.createdAt.desc()) + .offset(offset) + .limit(size) + .fetch(); } private BooleanExpression userIdEq(Long userId) { diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java index 2de7038c..16853772 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Images.java @@ -2,16 +2,17 @@ import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import javax.persistence.Embeddable; -import javax.persistence.OneToMany; -import javax.persistence.OrderBy; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.Embeddable; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Embeddable diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java index 80dd89dd..644697f8 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Post.java @@ -7,29 +7,16 @@ import com.cvi.image.domain.Image; import com.cvi.like.domain.model.Like; import com.cvi.user.domain.model.User; +import lombok.*; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.validation.constraints.NotBlank; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; @Getter @Entity @@ -62,7 +49,7 @@ public class Post extends BaseEntity { @Builder public Post(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, User user, - String content, int viewCount, VaccinationType vaccinationType) { + String content, int viewCount, VaccinationType vaccinationType) { super(id, createdAt, lastModifiedAt); this.user = user; this.content = content; diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java index 53e14859..73121ddc 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/model/Sort.java @@ -1,12 +1,10 @@ package com.cvi.post.domain.model; -import static com.cvi.post.domain.model.QPost.post; - -import com.cvi.exception.InvalidInputException; import com.querydsl.core.types.OrderSpecifier; -import java.util.Arrays; import lombok.Getter; +import static com.cvi.post.domain.model.QPost.post; + @Getter public enum Sort { LIKE_COUNT_ASC(post.likes.likes.size().asc()), diff --git a/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java b/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java index 301a041c..e7050a72 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java +++ b/backend/domain-cvi/src/main/java/com/cvi/post/domain/repository/PostRepositoryImpl.java @@ -1,10 +1,5 @@ package com.cvi.post.domain.repository; -import static com.cvi.comment.domain.model.QComment.comment; -import static com.cvi.like.domain.model.QLike.like; -import static com.cvi.post.domain.model.QPost.post; -import static com.cvi.user.domain.model.QUser.user; - import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.QPost; import com.cvi.post.domain.model.VaccinationType; @@ -12,10 +7,16 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.JPQLQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; import java.util.List; import java.util.Objects; import java.util.Optional; -import javax.persistence.EntityManager; + +import static com.cvi.comment.domain.model.QComment.comment; +import static com.cvi.like.domain.model.QLike.like; +import static com.cvi.post.domain.model.QPost.post; +import static com.cvi.user.domain.model.QUser.user; public class PostRepositoryImpl implements PostQueryDsl { diff --git a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java index 7ce619a1..5091b5ec 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java +++ b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/RegionPopulation.java @@ -1,9 +1,10 @@ package com.cvi.publicdata.domain.model; +import lombok.Getter; + import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import lombok.Getter; @Getter public enum RegionPopulation { diff --git a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java index 4ac68892..f016e4d3 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java +++ b/backend/domain-cvi/src/main/java/com/cvi/publicdata/domain/model/VaccinationStatistic.java @@ -39,8 +39,8 @@ public class VaccinationStatistic extends PublicData { @Builder public VaccinationStatistic(Long id, LocalDateTime createdAt, LocalDateTime lastModifiedAt, RegionPopulation regionPopulation, - LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt, - long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) { + LocalDate baseDate, long firstCnt, long secondCnt, long totalFirstCnt, long totalSecondCnt, long accumulatedFirstCnt, + long accumulatedSecondCnt, BigDecimal totalFirstRate, BigDecimal totalSecondRate) { super(id, createdAt, lastModifiedAt, regionPopulation); this.baseDate = baseDate; this.firstCnt = firstCnt; diff --git a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java index 7f306154..bb39b3de 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java +++ b/backend/domain-cvi/src/main/java/com/cvi/user/domain/model/User.java @@ -4,15 +4,10 @@ import com.cvi.exception.InvalidInputException; import lombok.*; import lombok.extern.slf4j.Slf4j; -import org.hibernate.validator.constraints.Length; -import org.springframework.util.StringUtils; import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; import java.util.Objects; -import java.util.regex.Matcher; import java.util.regex.Pattern; @Slf4j diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java index e27986fe..5830a573 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/model/CommentTest.java @@ -1,8 +1,5 @@ package com.cvi.comment.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.InvalidOperationException; import com.cvi.exception.NotFoundException; import com.cvi.exception.UnAuthorizedException; @@ -11,11 +8,15 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("댓글 도메인 테스트") class CommentTest { diff --git a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java index 0d4a344d..199a4171 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/comment/domain/repository/CommentRepositoryTest.java @@ -1,7 +1,6 @@ package com.cvi.comment.domain.repository; import com.cvi.comment.domain.model.Comment; -import com.cvi.image.domain.Image; import com.cvi.post.domain.model.Post; import com.cvi.post.domain.model.VaccinationType; import com.cvi.post.domain.repository.PostRepository; @@ -15,8 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import java.util.Arrays; - import static org.assertj.core.api.Assertions.assertThat; @DisplayName("CommentRepository 테스트") @@ -49,51 +46,51 @@ void setUp() { private void initUsers() { user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); user2 = User.builder() - .nickname("검프") - .ageRange(AgeRange.FIFTIES) - .socialProvider(SocialProvider.NAVER) - .socialId("1001") - .profileUrl("profile url 2") - .build(); + .nickname("검프") + .ageRange(AgeRange.FIFTIES) + .socialProvider(SocialProvider.NAVER) + .socialId("1001") + .profileUrl("profile url 2") + .build(); userRepository.save(user1); userRepository.save(user2); } private void initPost() { post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user1) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); postRepository.save(post1); } private void initComments() { comment1 = Comment.builder() - .content("댓글 내용1") - .user(user1) - .build(); + .content("댓글 내용1") + .user(user1) + .build(); comment1.assignPost(post1); commentRepository.save(comment1); comment2 = Comment.builder() - .content("댓글 내용2") - .user(user2) - .build(); + .content("댓글 내용2") + .user(user2) + .build(); comment2.assignPost(post1); commentRepository.save(comment2); comment3 = Comment.builder() - .content("댓글 내용3") - .user(user2) - .build(); + .content("댓글 내용3") + .user(user2) + .build(); comment3.assignPost(post1); commentRepository.save(comment3); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java index 0d9ac89d..962aca34 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/config/entity/BooleanToYNConverterTest.java @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; @DisplayName("Boolean 을 Y/N로 변환 테스트") class BooleanToYNConverterTest { diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java index cce9c643..8580cccc 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/model/ImageTest.java @@ -1,11 +1,11 @@ package com.cvi.image.model; -import static org.assertj.core.api.Assertions.assertThat; - import com.cvi.image.domain.Image; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("Image 도메인 테스트") class ImageTest { @@ -14,19 +14,19 @@ class ImageTest { void equalsAndHashcode() { //given final Image image1 = Image.builder() - .id(1L) - .url("aaaa/image1") - .build(); + .id(1L) + .url("aaaa/image1") + .build(); final Image image2 = Image.builder() - .id(1L) - .url("bbbb/image2") - .build(); + .id(1L) + .url("bbbb/image2") + .build(); //when //then assertThat(image1) - .isNotSameAs(image2) - .isEqualTo(image2) - .hasSameHashCodeAs(image2); + .isNotSameAs(image2) + .isEqualTo(image2) + .hasSameHashCodeAs(image2); assertThat(image1.getName()).isEqualTo("image1"); assertThat(image2.isSameAs(1L)).isTrue(); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java index 4478b512..888a48dd 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/image/repository/ImageRepositoryTest.java @@ -1,8 +1,5 @@ package com.cvi.image.repository; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.NotFoundException; import com.cvi.image.domain.Image; import com.cvi.post.domain.model.Post; @@ -12,13 +9,17 @@ import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; import com.cvi.user.domain.repository.UserRepository; -import java.util.Collections; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("ImageRepository 테스트") @DataJpaTest class ImageRepositoryTest { @@ -38,24 +39,24 @@ class ImageRepositoryTest { @BeforeEach void setUp() { User user = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); userRepository.save(user); image = Image.builder() - .url("image1_s3_url") - .build(); + .url("image1_s3_url") + .build(); imageRepository.save(image); post = Post.builder() - .user(user) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); postRepository.save(post); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java index 743a29eb..a36efbb5 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/model/LikeTest.java @@ -1,8 +1,5 @@ package com.cvi.like.domain.model; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - import com.cvi.exception.InvalidOperationException; import com.cvi.exception.NotFoundException; import com.cvi.post.domain.model.Post; @@ -10,11 +7,15 @@ import com.cvi.user.domain.model.AgeRange; import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; -import java.time.LocalDateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + @DisplayName("좋아요 도메인 테스트") class LikeTest { diff --git a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java index 2614e662..667abd6d 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/like/domain/repository/LikeRepositoryTest.java @@ -47,54 +47,54 @@ void setUp() { private void initUsers() { user1 = User.builder() - .nickname("인비") - .ageRange(AgeRange.TEENS) - .socialProvider(SocialProvider.KAKAO) - .socialId("1000") - .profileUrl("profile url 1") - .build(); + .nickname("인비") + .ageRange(AgeRange.TEENS) + .socialProvider(SocialProvider.KAKAO) + .socialId("1000") + .profileUrl("profile url 1") + .build(); user2 = User.builder() - .nickname("검프") - .ageRange(AgeRange.FIFTIES) - .socialProvider(SocialProvider.NAVER) - .socialId("1001") - .profileUrl("profile url 2") - .build(); + .nickname("검프") + .ageRange(AgeRange.FIFTIES) + .socialProvider(SocialProvider.NAVER) + .socialId("1001") + .profileUrl("profile url 2") + .build(); userRepository.save(user1); userRepository.save(user2); } private void initPost() { post1 = Post.builder() - .user(user1) - .content("내용 1") - .vaccinationType(VaccinationType.PFIZER) - .build(); + .user(user1) + .content("내용 1") + .vaccinationType(VaccinationType.PFIZER) + .build(); post2 = Post.builder() - .user(user1) - .content("내용 2") - .vaccinationType(VaccinationType.JANSSEN) - .build(); + .user(user1) + .content("내용 2") + .vaccinationType(VaccinationType.JANSSEN) + .build(); postRepository.save(post1); postRepository.save(post2); } private void initLikes() { like1 = Like.builder() - .user(user1) - .build(); + .user(user1) + .build(); like1.assignPost(post1); likeRepository.save(like1); like2 = Like.builder() - .user(user2) - .build(); + .user(user2) + .build(); like2.assignPost(post1); likeRepository.save(like2); like3 = Like.builder() - .user(user2) - .build(); + .user(user2) + .build(); like3.assignPost(post2); likeRepository.save(like3); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java index d8b0638d..607b9edd 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/model/PostTest.java @@ -36,31 +36,31 @@ class PostTest { @BeforeEach void init() { post = Post.builder() - .content("content1") - .vaccinationType(VaccinationType.ASTRAZENECA) - .createdAt(LocalDateTime.now()) - .build(); + .content("content1") + .vaccinationType(VaccinationType.ASTRAZENECA) + .createdAt(LocalDateTime.now()) + .build(); user = User.builder() - .id(1L) - .nickname("안녕하세욘") - .ageRange(AgeRange.TEENS) - .profileUrl("") - .socialProvider(SocialProvider.KAKAO) - .createdAt(LocalDateTime.now()) - .build(); + .id(1L) + .nickname("안녕하세욘") + .ageRange(AgeRange.TEENS) + .profileUrl("") + .socialProvider(SocialProvider.KAKAO) + .createdAt(LocalDateTime.now()) + .build(); comment = Comment.builder() - .id(1L) - .content("댓글입니다.") - .user(user) - .build(); + .id(1L) + .content("댓글입니다.") + .user(user) + .build(); like = Like.builder() - .id(1L) - .user(user) - .build(); + .id(1L) + .user(user) + .build(); image = Image.builder() - .id(1L) - .url("image1_s3_url/image") - .build(); + .id(1L) + .url("image1_s3_url/image") + .build(); } @DisplayName("게시글 작성자 할당 - 성공") @@ -78,14 +78,14 @@ void assignUser() { void assignUserFailureWhenAlreadyExists() { //given User targetUser = User.builder() - .id(2L) - .nickname("독함") - .build(); + .id(2L) + .nickname("독함") + .build(); //when post.assignUser(user); //then assertThatThrownBy(() -> post.assignUser(targetUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 작성자 할당 - 실패 - 할당하려는 작성자가 없음") @@ -95,7 +95,7 @@ void assignUserFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignUser(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 댓글 할당 - 성공") @@ -116,7 +116,7 @@ void assignCommentFailureWhenAlreadyExists() { post.assignComment(comment); //then assertThatThrownBy(() -> post.assignComment(comment)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 댓글 할당 - 실패 - 할당하려는 댓글이 없음") @@ -126,7 +126,7 @@ void assignCommentFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignComment(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 댓글 수정 - 성공") @@ -134,9 +134,9 @@ void assignCommentFailureWhenNull() { void updateComment() { //given Comment updateComment = Comment.builder() - .content("수정된 댓글입니다.") - .user(user) - .build(); + .content("수정된 댓글입니다.") + .user(user) + .build(); //when post.assignComment(comment); post.updateComment(1L, updateComment, user); @@ -149,18 +149,18 @@ void updateComment() { void updateCommentFailure() { //given User anotherUser = User.builder() - .id(2L) - .nickname("다른유저") - .build(); + .id(2L) + .nickname("다른유저") + .build(); Comment updateComment = Comment.builder() - .content("수정된 댓글입니다.") - .user(user) - .build(); + .content("수정된 댓글입니다.") + .user(user) + .build(); //when post.assignComment(comment); //then assertThatThrownBy(() -> post.updateComment(1L, updateComment, anotherUser)) - .isInstanceOf(UnAuthorizedException.class); + .isInstanceOf(UnAuthorizedException.class); } @DisplayName("게시글 댓글 삭제 - 성공") @@ -180,19 +180,19 @@ void deleteCommentInComments() { void deleteCommentInCommentsFailure() { //given User anotherUser = User.builder() - .id(2L) - .nickname("다른유저") - .ageRange(AgeRange.TEENS) - .profileUrl("") - .socialProvider(SocialProvider.KAKAO) - .createdAt(LocalDateTime.now()) - .build(); + .id(2L) + .nickname("다른유저") + .ageRange(AgeRange.TEENS) + .profileUrl("") + .socialProvider(SocialProvider.KAKAO) + .createdAt(LocalDateTime.now()) + .build(); //when post.assignComment(comment); Comments comments = post.getComments(); //then assertThatThrownBy(() -> comments.delete(comment.getId(), anotherUser)) - .isExactlyInstanceOf(UnAuthorizedException.class); + .isExactlyInstanceOf(UnAuthorizedException.class); } @DisplayName("게시글 좋아요 할당 - 성공") @@ -213,7 +213,7 @@ void assignLikeFailureWhenAlreadyExists() { post.assignLike(like); //then assertThatThrownBy(() -> post.assignLike(like)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 좋아요 할당 - 실패 - 할당하려는 좋아요가 없음") @@ -223,7 +223,7 @@ void assignLikeFailureWhenNull() { //when //then assertThatThrownBy(() -> post.assignLike(null)) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 사진 할당 - 성공") @@ -243,7 +243,7 @@ void assignImagesFailureWhenAlreadyExists() { //when //then assertThatThrownBy(() -> post.assignImages(Collections.emptyList())) - .isInstanceOf(NotFoundException.class); + .isInstanceOf(NotFoundException.class); } @DisplayName("게시글 이미지 삭제 - 성공") @@ -286,8 +286,8 @@ void increaseViewCount() { void update() { //given Post updatedPost = Post.builder() - .content("content2") - .build(); + .content("content2") + .build(); post.assignUser(user); //when post.updateContent(updatedPost, user); @@ -300,17 +300,17 @@ void update() { void updateFailWhenUserNotMatch() { //given User targetUser = User.builder() - .id(2L) - .nickname("라이언방구") - .build(); + .id(2L) + .nickname("라이언방구") + .build(); Post updatedPost = Post.builder() - .content("content2") - .build(); + .content("content2") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.updateContent(updatedPost, targetUser)) - .isExactlyInstanceOf(InvalidOperationException.class); + .isExactlyInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 작성자 확인 - 성공") @@ -318,17 +318,17 @@ void updateFailWhenUserNotMatch() { void deletePost() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatCode(() -> post.validateAuthor(user)) - .doesNotThrowAnyException(); + .doesNotThrowAnyException(); } @DisplayName("게시글 작성자 확인 - 실패 - 글 작성자가 아님") @@ -336,21 +336,21 @@ void deletePost() { void deletePostFailureWhenNotAuthor() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); User otherUser = User.builder() - .id(3L) - .nickname("라이언") - .build(); + .id(3L) + .nickname("라이언") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.validateAuthor(otherUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글 좋아요 이미 누름 - 성공") @@ -377,21 +377,21 @@ void isNotLikedBy() { void isNotAlreadyLikedBy() { //given User user = User.builder() - .id(2L) - .nickname("인비") - .build(); + .id(2L) + .nickname("인비") + .build(); User otherUser = User.builder() - .id(3L) - .nickname("라이언") - .build(); + .id(3L) + .nickname("라이언") + .build(); Post post = Post.builder() - .content("내용") - .build(); + .content("내용") + .build(); post.assignUser(user); //when //then assertThatThrownBy(() -> post.validateAuthor(otherUser)) - .isInstanceOf(InvalidOperationException.class); + .isInstanceOf(InvalidOperationException.class); } @DisplayName("게시글이 이미지 보유 확인 - 성공 - 있음") @@ -446,13 +446,13 @@ void getS3PathsOfAllImages() { void resizePagingRangeTest(int offset, int size, List contentResult) { //given User user = User.builder() - .id(1L) - .nickname("인비") - .build(); + .id(1L) + .nickname("인비") + .build(); Post post = Post.builder() - .content("내용") - .user(user) - .build(); + .content("내용") + .user(user) + .build(); Comment comment1 = Comment.builder().content("댓글1").user(user).createdAt(LocalDateTime.now().minusHours(1L)).build(); Comment comment2 = Comment.builder().content("댓글2").user(user).createdAt(LocalDateTime.now().minusHours(2L)).build(); post.assignComment(comment1); @@ -465,10 +465,10 @@ void resizePagingRangeTest(int offset, int size, List contentResult) { static Stream resizePagingRangeTest() { return Stream.of( - Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), - Arguments.of(1, 1, Collections.singletonList("댓글2")), - Arguments.of(0, 1, Collections.singletonList("댓글1")), - Arguments.of(2, 1, Collections.emptyList()) + Arguments.of(0, 2, Arrays.asList("댓글1", "댓글2")), + Arguments.of(1, 1, Collections.singletonList("댓글2")), + Arguments.of(0, 1, Collections.singletonList("댓글1")), + Arguments.of(2, 1, Collections.emptyList()) ); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java index d941c80c..6beee448 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/post/domain/repository/PostRepositoryTest.java @@ -1,7 +1,5 @@ package com.cvi.post.domain.repository; -import static org.assertj.core.api.Assertions.assertThat; - import com.cvi.comment.domain.model.Comment; import com.cvi.comment.domain.repository.CommentRepository; import com.cvi.image.domain.Image; @@ -15,19 +13,21 @@ import com.cvi.user.domain.model.SocialProvider; import com.cvi.user.domain.model.User; import com.cvi.user.domain.repository.UserRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; import java.time.LocalDateTime; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import static org.assertj.core.api.Assertions.assertThat; @DisplayName("PostRepository 테스트") @DataJpaTest diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java index f9dacaae..bd107eca 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticFactory.java @@ -9,54 +9,54 @@ public class VaccinationStatisticFactory { public static final LocalDate TARGET_DATE = LocalDate.now(); public static final List KOREA_VACCINATION_STATISTICS_FROM_API = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.REGION_WIDE).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEOUL).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.BUSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEGU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.INCHEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GWANGJU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.ULSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEJEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GANGWOND_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEJONG).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEJU_OD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.REGION_WIDE).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEOUL).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.BUSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEGU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.INCHEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GWANGJU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.ULSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.DAEJEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GANGWOND_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.SEJONG).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.JEJU_OD).build() ); public static final List WORLD_VACCINATION_STATISTICS_FROM_API = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(2)).regionPopulation(RegionPopulation.WORLD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(2)).regionPopulation(RegionPopulation.WORLD).build() ); public static final List VACCINATION_STATISTICS_FROM_DB = Arrays.asList( - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.REGION_WIDE).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEOUL).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.BUSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEGU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.INCHEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GWANGJU).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.ULSAN).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEJEON).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GANGWOND_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEJONG).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEJU_OD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(3)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(4)).regionPopulation(RegionPopulation.WORLD).build(), - VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(5)).regionPopulation(RegionPopulation.WORLD).build() + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.REGION_WIDE).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEOUL).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.BUSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEGU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.INCHEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GWANGJU).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.ULSAN).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.DAEJEON).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGGI_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GANGWOND_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.SEJONG).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.CHUNGCHEONGNAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLAKBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEOLLANAM_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGBUK_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.GYEONGSANGNAME_DO).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(1)).regionPopulation(RegionPopulation.JEJU_OD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(3)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(4)).regionPopulation(RegionPopulation.WORLD).build(), + VaccinationStatistic.builder().baseDate(TARGET_DATE.minusDays(5)).regionPopulation(RegionPopulation.WORLD).build() ); } diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java index 7db743ad..1c4a22d0 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticTest.java @@ -1,29 +1,29 @@ package com.cvi.publicdata.domain.model; -import static org.assertj.core.api.Assertions.assertThat; - -import java.math.BigDecimal; - import com.cvi.CustomParameterizedTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.provider.CsvSource; +import java.math.BigDecimal; + +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("백신 접종률 도메인 테스트") class VaccinationStatisticTest { @DisplayName("인구수 비례 1차 접종률 계산 - 성공 - 전국") @CustomParameterizedTest @CsvSource({ - "2100000, 4.1", - "21000000, 40.5", - "11000000, 21.2" + "2100000, 4.1", + "21000000, 40.5", + "11000000, 21.2" }) void accumulateFirstRate(long totalFirstCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.REGION_WIDE) - .totalFirstCnt(totalFirstCnt) - .build(); + .regionPopulation(RegionPopulation.REGION_WIDE) + .totalFirstCnt(totalFirstCnt) + .build(); //when BigDecimal accumulateFirstRate = vaccinationStatistic.getTotalFirstRate(); //then @@ -33,16 +33,16 @@ void accumulateFirstRate(long totalFirstCnt, double actual) { @DisplayName("인구수 비례 2차 접종률 계산 - 성공 - 전국") @CustomParameterizedTest @CsvSource({ - "1100000, 2.1", - "3000000, 5.8", - "11000000, 21.2" + "1100000, 2.1", + "3000000, 5.8", + "11000000, 21.2" }) void accumulateSecondRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.REGION_WIDE) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.REGION_WIDE) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then @@ -52,16 +52,16 @@ void accumulateSecondRate(long totalSecondCnt, double actual) { @DisplayName("인구수 비례 1차 접종률 계산 - 성공 - 전세계") @CustomParameterizedTest @CsvSource({ - "2253618189, 28.6", - "2276706840, 28.9", - "2303769251, 29.2" + "2253618189, 28.6", + "2276706840, 28.9", + "2303769251, 29.2" }) void accumulateWorldFirstRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.WORLD) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.WORLD) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then @@ -71,16 +71,16 @@ void accumulateWorldFirstRate(long totalSecondCnt, double actual) { @DisplayName("인구수 비례 2차 접종률 계산 - 성공 - 전세계") @CustomParameterizedTest @CsvSource({ - "1153697698, 14.6", - "1175939230, 14.9", - "1181952381, 15.0" + "1153697698, 14.6", + "1175939230, 14.9", + "1181952381, 15.0" }) void accumulateWorldSecondRate(long totalSecondCnt, double actual) { //given VaccinationStatistic vaccinationStatistic = VaccinationStatistic.builder() - .regionPopulation(RegionPopulation.WORLD) - .totalSecondCnt(totalSecondCnt) - .build(); + .regionPopulation(RegionPopulation.WORLD) + .totalSecondCnt(totalSecondCnt) + .build(); //when BigDecimal accumulatedSecondRate = vaccinationStatistic.getTotalSecondRate(); //then diff --git a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java index 75588d39..971867ce 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/publicdata/domain/model/VaccinationStatisticsTest.java @@ -1,15 +1,13 @@ package com.cvi.publicdata.domain.model; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.KOREA_VACCINATION_STATISTICS_FROM_API; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.TARGET_DATE; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.VACCINATION_STATISTICS_FROM_DB; -import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.WORLD_VACCINATION_STATISTICS_FROM_API; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import java.util.List; + +import static com.cvi.publicdata.domain.model.VaccinationStatisticFactory.*; +import static org.assertj.core.api.Assertions.assertThat; + @DisplayName("VaccinationStatistic 일급 컬렉션 기능 테스트") class VaccinationStatisticsTest { @@ -20,7 +18,7 @@ void findUnSavedStatisticsWhenAnotherDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(KOREA_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - VACCINATION_STATISTICS_FROM_DB, TARGET_DATE + VACCINATION_STATISTICS_FROM_DB, TARGET_DATE ); //then assertThat(unSavedStatistics.size()).isEqualTo(RegionPopulation.size() - 1); @@ -34,7 +32,7 @@ void findUnSavedStatisticsWhenSameDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(KOREA_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - KOREA_VACCINATION_STATISTICS_FROM_API, TARGET_DATE + KOREA_VACCINATION_STATISTICS_FROM_API, TARGET_DATE ); //then assertThat(unSavedStatistics).isEmpty(); @@ -47,7 +45,7 @@ void findWorldUnSavedStatisticsWhenTargetDate() { final VaccinationStatistics vaccinationStatistics = new VaccinationStatistics(WORLD_VACCINATION_STATISTICS_FROM_API); //when final List unSavedStatistics = vaccinationStatistics.findUnSavedStatistics( - VACCINATION_STATISTICS_FROM_DB, TARGET_DATE.minusDays(1) + VACCINATION_STATISTICS_FROM_DB, TARGET_DATE.minusDays(1) ); //then assertThat(unSavedStatistics.size()).isEqualTo(WORLD_VACCINATION_STATISTICS_FROM_API.size() - 1); @@ -65,7 +63,7 @@ void findWorldRecentlyStatistics() { assertThat(koreaRecentlyStatistics.size()).isEqualTo(RegionPopulation.size() - 1); assertThat(koreaRecentlyStatistics).noneMatch(it -> it.getRegionPopulation() == RegionPopulation.WORLD); assertThat(koreaRecentlyStatistics).extracting(VaccinationStatistic::getBaseDate) - .contains(TARGET_DATE.minusDays(1)); + .contains(TARGET_DATE.minusDays(1)); } @DisplayName("타겟 날짜 이전의 데이터가 DB에 저장되어 있을때(타겟날짜에 데이터가 저장되어 있지 않음) 이전 날짜의 데이터 반환 - 성공 - 세계 데이터") @@ -78,6 +76,6 @@ void findKoreaRecentlyStatistics() { //then assertThat(worldRecentlyStatistics).allMatch(it -> it.getRegionPopulation() == RegionPopulation.WORLD); assertThat(worldRecentlyStatistics).extracting(VaccinationStatistic::getBaseDate) - .doesNotContain(TARGET_DATE); + .doesNotContain(TARGET_DATE); } } diff --git a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java index 6e5977f4..39010b04 100644 --- a/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java +++ b/backend/domain-cvi/src/test/java/com/cvi/user/domain/model/UserTest.java @@ -22,13 +22,13 @@ class UserTest { @BeforeEach void init() { this.user = User.builder() - .id(1L) - .ageRange(AgeRange.TEENS) - .createdAt(LocalDateTime.now()) - .nickname("검프") - .profileUrl("www.gump.com") - .socialProvider(SocialProvider.KAKAO) - .build(); + .id(1L) + .ageRange(AgeRange.TEENS) + .createdAt(LocalDateTime.now()) + .nickname("검프") + .profileUrl("www.gump.com") + .socialProvider(SocialProvider.KAKAO) + .build(); } @DisplayName("사용자 생성 - 성공") @@ -39,11 +39,11 @@ void save(String name) { //when //then assertThatCode(() -> User.builder() - .ageRange(AgeRange.TWENTIES) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build() + .ageRange(AgeRange.TWENTIES) + .nickname(name) + .profileUrl("www.budae.com") + .socialProvider(SocialProvider.KAKAO) + .build() ).doesNotThrowAnyException(); } @@ -56,13 +56,13 @@ void saveFailure(String name) { //when //then assertThatThrownBy(() -> User.builder() - .ageRange(AgeRange.TWENTIES) - .nickname(name) - .profileUrl("www.budae.com") - .socialProvider(SocialProvider.KAKAO) - .build() + .ageRange(AgeRange.TWENTIES) + .nickname(name) + .profileUrl("www.budae.com") + .socialProvider(SocialProvider.KAKAO) + .build() ).isInstanceOf(InvalidInputException.class) - .hasMessageContaining("올바른 닉네임 형식이 아닙니다(특수 문자, 공백 불가)."); + .hasMessageContaining("올바른 닉네임 형식이 아닙니다(특수 문자, 공백 불가)."); } @@ -72,14 +72,14 @@ void saveFailure(String name) { void update(String name, AgeRange ageRange, boolean shotVerified) { //given User updateUser = User.builder() - .id(1L) - .ageRange(ageRange) - .createdAt(LocalDateTime.now()) - .nickname(name) - .profileUrl("www.budae.com") - .shotVerified(shotVerified) - .socialProvider(SocialProvider.KAKAO) - .build(); + .id(1L) + .ageRange(ageRange) + .createdAt(LocalDateTime.now()) + .nickname(name) + .profileUrl("www.budae.com") + .shotVerified(shotVerified) + .socialProvider(SocialProvider.KAKAO) + .build(); //when user.update(updateUser); //then @@ -90,6 +90,6 @@ void update(String name, AgeRange ageRange, boolean shotVerified) { static Stream update() { return Stream.of(Arguments.of("1", AgeRange.TWENTIES, true), - Arguments.of("2", AgeRange.THIRTIES, false)); + Arguments.of("2", AgeRange.THIRTIES, false)); } } From f124c33e6bf782b3690dc8bbe3496525a95a537c Mon Sep 17 00:00:00 2001 From: younghoonkwon Date: Thu, 28 Oct 2021 13:01:32 +0900 Subject: [PATCH 20/20] =?UTF-8?q?refactor:=20=EC=9B=90=EB=9E=98=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cvi/config/entity/BooleanToYNConverter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java b/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java index 6b4332f8..658763eb 100644 --- a/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java +++ b/backend/domain-cvi/src/main/java/com/cvi/config/entity/BooleanToYNConverter.java @@ -9,10 +9,10 @@ public class BooleanToYNConverter implements AttributeConverter @Override public String convertToDatabaseColumn(Boolean attribute) { - if (Objects.isNull(attribute) || !attribute) { - return "N"; + if (!Objects.isNull(attribute) && attribute) { + return "Y"; } - return "Y"; + return "N"; } @Override