From 3bc6c67158d3006fc66376e5ebabdbe067458561 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 01:24:12 +0900 Subject: [PATCH 01/16] Add: querydsl config #67 --- .gitignore | 3 +++ build.gradle | 26 ++++++++++++++++--- .../pochak/global/config/QueryDSLConfig.java | 18 +++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java diff --git a/.gitignore b/.gitignore index caa1151f..da1c4d87 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ application-API-KEY.tar application-OAUTH.tar application-JWT.tar +### Qclass ### +/src/main/generated/ + ### STS ### .apt_generated .classpath diff --git a/build.gradle b/build.gradle index b31c4f7c..dbdf4f1c 100644 --- a/build.gradle +++ b/build.gradle @@ -52,8 +52,8 @@ dependencies { asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor' - testImplementation("org.springframework.boot:spring-boot-starter-test"){ - exclude group: "com.vaadin.external.google", module:"android-json" + testImplementation("org.springframework.boot:spring-boot-starter-test") { + exclude group: "com.vaadin.external.google", module: "android-json" } testImplementation 'org.springframework.security:spring-security-test' @@ -63,6 +63,12 @@ dependencies { implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.30.1' implementation group: 'org.json', name: 'json', version: '20090211' + + // QueryDSL + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" } ext { @@ -108,7 +114,21 @@ jar { enabled = false } - build { dependsOn copyDocument +} + +def generated = 'src/main/generated' + +clean { + delete file(generated) +} + +tasks.withType(JavaCompile) { + options.generatedSourceOutputDirectory = file(generated) +} + +sourceSets { + main.java.srcDirs += "$projectDir/build/generated" + print "$projectDir" } \ No newline at end of file diff --git a/src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java b/src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java new file mode 100644 index 00000000..1d266646 --- /dev/null +++ b/src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java @@ -0,0 +1,18 @@ +package com.apps.pochak.global.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@RequiredArgsConstructor +public class QueryDSLConfig { + private final EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } +} From 5166d712c35991968bbd174666f9837bb18aa79a Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 03:51:24 +0900 Subject: [PATCH 02/16] =?UTF-8?q?Refactor:=20`findPostByIdWithoutBlockPost?= =?UTF-8?q?()`=20querydsl=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= =?UTF-8?q?=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/service/CommentService.java | 4 +- .../apps/pochak/like/service/LikeService.java | 4 +- .../repository/PostCustomRepository.java | 65 +++++++++++++++++++ .../domain/repository/PostRepository.java | 24 ++----- .../apps/pochak/post/service/PostService.java | 4 +- .../pochak/report/service/ReportService.java | 2 +- 6 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java diff --git a/src/main/java/com/apps/pochak/comment/service/CommentService.java b/src/main/java/com/apps/pochak/comment/service/CommentService.java index 4831f83e..2f9155a8 100644 --- a/src/main/java/com/apps/pochak/comment/service/CommentService.java +++ b/src/main/java/com/apps/pochak/comment/service/CommentService.java @@ -44,7 +44,7 @@ public CommentElements getComments( final Pageable pageable ) { final Member loginMember = memberRepository.findMemberById(accessor.getMemberId()); - final Post post = postRepository.findPublicPostById(postId, loginMember); + final Post post = postRepository.findPublicPostById(postId); final Page commentList = commentRepository.findParentCommentByPost(post, loginMember, pageable); return new CommentElements(loginMember, commentList); } @@ -68,7 +68,7 @@ public void saveComment( final CommentUploadRequest request ) { final Member loginMember = memberRepository.findMemberById(accessor.getMemberId()); - final Post post = postRepository.findPublicPostById(postId, loginMember); + final Post post = postRepository.findPublicPostById(postId); if (request.checkChildComment()) { saveChildComment( diff --git a/src/main/java/com/apps/pochak/like/service/LikeService.java b/src/main/java/com/apps/pochak/like/service/LikeService.java index aeac7121..57a2b92e 100644 --- a/src/main/java/com/apps/pochak/like/service/LikeService.java +++ b/src/main/java/com/apps/pochak/like/service/LikeService.java @@ -34,7 +34,7 @@ public void likePost( final Long postId ) { final Member loginMember = memberRepository.findMemberById(accessor.getMemberId()); - final Post post = postRepository.findPostById(postId, loginMember); + final Post post = postRepository.findPostById(postId); final Optional optionalLike = likeRepository.findByLikeMemberAndLikedPost(loginMember, post); if (optionalLike.isPresent()) { @@ -76,7 +76,7 @@ public LikeElements getMemberLikedPost( final Long postId ) { final Member loginMember = memberRepository.findMemberById(accessor.getMemberId()); - final Post likedPost = postRepository.findPostById(postId, loginMember); + final Post likedPost = postRepository.findPostById(postId); final List likeElements = likeRepository.findLikesAndIsFollow( loginMember.getId(), diff --git a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java new file mode 100644 index 00000000..96df3f4c --- /dev/null +++ b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java @@ -0,0 +1,65 @@ +package com.apps.pochak.post.domain.repository; + +import com.apps.pochak.global.BaseEntityStatus; +import com.apps.pochak.global.api_payload.exception.GeneralException; +import com.apps.pochak.post.domain.Post; +import com.querydsl.core.types.dsl.BooleanExpression; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +import static com.apps.pochak.block.domain.QBlock.block; +import static com.apps.pochak.global.api_payload.code.status.ErrorStatus.INVALID_POST_ID; +import static com.apps.pochak.post.domain.QPost.post; +import static com.apps.pochak.tag.domain.QTag.tag; + +@Repository +@RequiredArgsConstructor +public class PostCustomRepository { + private final JPAQueryFactory query; + + public Post findPostByIdWithoutBlockPost( + final Long postId, + final Long loginMemberId + ) { + return findByIdWithoutBlockPost(postId, loginMemberId).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); + } + + public Optional findByIdWithoutBlockPost( + final Long postId, + final Long loginMemberId + ) { + return Optional.ofNullable( + query.selectFrom(post) + .distinct() + .join(post.owner).fetchJoin() + .join(tag).on(tag.post.eq(post)) + .leftJoin(block).on( + checkOwnerOrTaggedMemberBlockLoginMember(loginMemberId) + .or(checkLoginMemberBlockOwnerOrTaggedMember(loginMemberId)) + ) + .where( + post.id.eq(postId), + post.status.eq(BaseEntityStatus.ACTIVE), + block.isNull() + ) + .fetchOne() + ); + } + + private BooleanExpression checkOwnerOrTaggedMemberBlockLoginMember( + final Long loginMemberId + ) { + return (block.blocker.eq(tag.member).or(block.blocker.eq(post.owner))) + .and(block.blockedMember.id.eq(loginMemberId)); + } + + private BooleanExpression checkLoginMemberBlockOwnerOrTaggedMember( + final Long loginMemberId + ) { + return (block.blocker.id.eq(loginMemberId)) + .and(block.blockedMember.eq(tag.member).or(block.blockedMember.eq(post.owner))); + } +} diff --git a/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java b/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java index 037b780e..b9773f3d 100644 --- a/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java +++ b/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java @@ -21,32 +21,18 @@ public interface PostRepository extends JpaRepository { - @Query(""" - select p from Post p - join fetch p.owner - where p.id = :postId and p.status = 'ACTIVE' - and p.owner not in (select b.blockedMember from Block b where b.blocker = :loginMember) - and :loginMember not in (select b.blockedMember from Block b where b.blocker = p.owner) - and not exists (select t.member from Tag t where t.post = p intersect select b.blockedMember from Block b where b.blocker = :loginMember) - and :loginMember not in (select b.blockedMember from Block b where b.blocker in (select t.member from Tag t where t.post = p)) - """) - Optional findById( - @Param("postId") final Long postId, - @Param("loginMember") final Member loginMember - ); + Optional findById(final Long id); default Post findPostById( - final Long postId, - final Member loginMember + final Long postId ) { - return findById(postId, loginMember).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); + return findById(postId).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); } default Post findPublicPostById( - final Long postId, - final Member loginMember + final Long postId ) { - final Post post = findById(postId, loginMember).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); + final Post post = findById(postId).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); if (post.isPrivate()) { throw new GeneralException(PRIVATE_POST); } diff --git a/src/main/java/com/apps/pochak/post/service/PostService.java b/src/main/java/com/apps/pochak/post/service/PostService.java index 8a90054c..a7a3e7a2 100644 --- a/src/main/java/com/apps/pochak/post/service/PostService.java +++ b/src/main/java/com/apps/pochak/post/service/PostService.java @@ -14,6 +14,7 @@ import com.apps.pochak.member.domain.Member; import com.apps.pochak.member.domain.repository.MemberRepository; import com.apps.pochak.post.domain.Post; +import com.apps.pochak.post.domain.repository.PostCustomRepository; import com.apps.pochak.post.domain.repository.PostRepository; import com.apps.pochak.post.dto.PostElements; import com.apps.pochak.post.dto.request.PostUploadRequest; @@ -38,6 +39,7 @@ @RequiredArgsConstructor public class PostService { private final PostRepository postRepository; + private final PostCustomRepository postCustomRepository; private final MemberRepository memberRepository; private final FollowRepository followRepository; private final TagRepository tagRepository; @@ -66,7 +68,7 @@ public PostDetailResponse getPostDetail( final Long postId ) { final Member loginMember = memberRepository.findMemberById(accessor.getMemberId()); - final Post post = postRepository.findPostById(postId, loginMember); + final Post post = postCustomRepository.findPostByIdWithoutBlockPost(postId, accessor.getMemberId()); final List tagList = tagRepository.findTagsByPost(post); if (post.isPrivate()) { throw new GeneralException(PRIVATE_POST); diff --git a/src/main/java/com/apps/pochak/report/service/ReportService.java b/src/main/java/com/apps/pochak/report/service/ReportService.java index 455c2780..3aa1e544 100644 --- a/src/main/java/com/apps/pochak/report/service/ReportService.java +++ b/src/main/java/com/apps/pochak/report/service/ReportService.java @@ -27,7 +27,7 @@ public void saveReport( final ReportUploadRequest request ) { final Member reporter = memberRepository.findMemberById(accessor.getMemberId()); - final Post reportedPost = postRepository.findPostById(request.getPostId(), reporter); + final Post reportedPost = postRepository.findPostById(request.getPostId()); Report report = request.toEntity(reporter, reportedPost); reportRepository.save(report); From 3f2207072dfb35b5339f0474a3e9b5a8d21c286c Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 03:59:32 +0900 Subject: [PATCH 03/16] =?UTF-8?q?Chore:=20=EC=BB=A8=EB=B2=A4=EC=85=98=20?= =?UTF-8?q?=EA=B3=B5=EB=B0=B1=20=EC=82=AD=EC=A0=9C=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/domain/repository/PostCustomRepository.java | 8 ++------ .../pochak/post/domain/repository/PostRepository.java | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java index 96df3f4c..adf62e9f 100644 --- a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java +++ b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java @@ -49,16 +49,12 @@ public Optional findByIdWithoutBlockPost( ); } - private BooleanExpression checkOwnerOrTaggedMemberBlockLoginMember( - final Long loginMemberId - ) { + private BooleanExpression checkOwnerOrTaggedMemberBlockLoginMember(final Long loginMemberId) { return (block.blocker.eq(tag.member).or(block.blocker.eq(post.owner))) .and(block.blockedMember.id.eq(loginMemberId)); } - private BooleanExpression checkLoginMemberBlockOwnerOrTaggedMember( - final Long loginMemberId - ) { + private BooleanExpression checkLoginMemberBlockOwnerOrTaggedMember(final Long loginMemberId) { return (block.blocker.id.eq(loginMemberId)) .and(block.blockedMember.eq(tag.member).or(block.blockedMember.eq(post.owner))); } diff --git a/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java b/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java index b9773f3d..d65c59eb 100644 --- a/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java +++ b/src/main/java/com/apps/pochak/post/domain/repository/PostRepository.java @@ -23,15 +23,11 @@ public interface PostRepository extends JpaRepository { Optional findById(final Long id); - default Post findPostById( - final Long postId - ) { + default Post findPostById(final Long postId) { return findById(postId).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); } - default Post findPublicPostById( - final Long postId - ) { + default Post findPublicPostById(final Long postId) { final Post post = findById(postId).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); if (post.isPrivate()) { throw new GeneralException(PRIVATE_POST); From ee66ec924ff696704f757a547d3c5ac1971e0d38 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 12:59:19 +0900 Subject: [PATCH 04/16] =?UTF-8?q?Fix:=20`findByIdWithoutBlockPost()`=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pochak/post/domain/repository/PostCustomRepository.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java index adf62e9f..7e46f5b1 100644 --- a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java +++ b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java @@ -33,17 +33,17 @@ public Optional findByIdWithoutBlockPost( ) { return Optional.ofNullable( query.selectFrom(post) - .distinct() .join(post.owner).fetchJoin() .join(tag).on(tag.post.eq(post)) .leftJoin(block).on( checkOwnerOrTaggedMemberBlockLoginMember(loginMemberId) .or(checkLoginMemberBlockOwnerOrTaggedMember(loginMemberId)) ) + .groupBy(post) + .having(block.id.count().eq(0L)) .where( post.id.eq(postId), - post.status.eq(BaseEntityStatus.ACTIVE), - block.isNull() + post.status.eq(BaseEntityStatus.ACTIVE) ) .fetchOne() ); From b9d14ec589f94cd8616a12dd2a9d0d06b6e35722 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 13:09:35 +0900 Subject: [PATCH 05/16] =?UTF-8?q?Fix:=20=EC=B0=A8=EB=8B=A8=EB=90=9C=20?= =?UTF-8?q?=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=97=90=EB=9F=AC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pochak/global/api_payload/code/status/ErrorStatus.java | 3 +-- .../pochak/post/domain/repository/PostCustomRepository.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/apps/pochak/global/api_payload/code/status/ErrorStatus.java b/src/main/java/com/apps/pochak/global/api_payload/code/status/ErrorStatus.java index 81f55181..4d241f29 100644 --- a/src/main/java/com/apps/pochak/global/api_payload/code/status/ErrorStatus.java +++ b/src/main/java/com/apps/pochak/global/api_payload/code/status/ErrorStatus.java @@ -6,8 +6,6 @@ import lombok.Getter; import org.springframework.http.HttpStatus; -import java.security.NoSuchAlgorithmException; - import static org.springframework.http.HttpStatus.*; @Getter @@ -78,6 +76,7 @@ public enum ErrorStatus implements BaseErrorCode { EXCEED_TAG_LIMIT(BAD_REQUEST, "POST4004", "최대 멤버 태그 수를 초과하였습니다."), TAGGED_ONESELF(BAD_REQUEST, "POST4005", "자기 자신을 태그하였습니다."), INVALID_TAG_INFO(BAD_REQUEST, "POST4006", "태그된 멤버의 정보가 확인되지 않습니다."), + BLOCKED_POST(BAD_REQUEST, "POST4007", "확인할 수 없는 게시물입니다."), // Tag INVALID_TAG_ID(BAD_REQUEST, "TAG4001", "유효하지 않은 태그 아이디입니다."), diff --git a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java index 7e46f5b1..c44114c5 100644 --- a/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java +++ b/src/main/java/com/apps/pochak/post/domain/repository/PostCustomRepository.java @@ -11,7 +11,7 @@ import java.util.Optional; import static com.apps.pochak.block.domain.QBlock.block; -import static com.apps.pochak.global.api_payload.code.status.ErrorStatus.INVALID_POST_ID; +import static com.apps.pochak.global.api_payload.code.status.ErrorStatus.BLOCKED_POST; import static com.apps.pochak.post.domain.QPost.post; import static com.apps.pochak.tag.domain.QTag.tag; @@ -24,7 +24,7 @@ public Post findPostByIdWithoutBlockPost( final Long postId, final Long loginMemberId ) { - return findByIdWithoutBlockPost(postId, loginMemberId).orElseThrow(() -> new GeneralException(INVALID_POST_ID)); + return findByIdWithoutBlockPost(postId, loginMemberId).orElseThrow(() -> new GeneralException(BLOCKED_POST)); } public Optional findByIdWithoutBlockPost( From 245e03455ad92eb20a7511f3d710d67c1efdfcc5 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 13:44:37 +0900 Subject: [PATCH 06/16] Feat: querydsl test config file #67 --- .../pochak/global/TestQueryDSLConfig.java | 24 +++++++++++++++++++ .../repository/PostCustomRepositoryTest.java | 17 +++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java create mode 100644 src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java diff --git a/src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java b/src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java new file mode 100644 index 00000000..d3139b1e --- /dev/null +++ b/src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java @@ -0,0 +1,24 @@ +package com.apps.pochak.global; + +import com.apps.pochak.post.domain.repository.PostCustomRepository; +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +@TestConfiguration +public class TestQueryDSLConfig { + @PersistenceContext + private EntityManager entityManager; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(entityManager); + } + + @Bean + public PostCustomRepository postCustomRepository() { + return new PostCustomRepository(jpaQueryFactory()); + } +} diff --git a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java new file mode 100644 index 00000000..c77622b9 --- /dev/null +++ b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java @@ -0,0 +1,17 @@ +package com.apps.pochak.post.domain.repository; + +import com.apps.pochak.global.TestQueryDSLConfig; +import com.apps.pochak.member.domain.repository.MemberRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; + +@DataJpaTest +@Import(TestQueryDSLConfig.class) +class PostCustomRepositoryTest { + @Autowired + PostCustomRepository postCustomRepository; + + @Autowired + MemberRepository memberRepository; +} \ No newline at end of file From 308c90ae51e238512c562308bf4e25fa13f1ea6f Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 14:04:50 +0900 Subject: [PATCH 07/16] =?UTF-8?q?Rename:=20Querydsl=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/{QueryDSLConfig.java => QuerydslConfig.java} | 2 +- .../{TestQueryDSLConfig.java => TestQuerydslConfig.java} | 4 +++- .../post/domain/repository/PostCustomRepositoryTest.java | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) rename src/main/java/com/apps/pochak/global/config/{QueryDSLConfig.java => QuerydslConfig.java} (94%) rename src/test/java/com/apps/pochak/global/{TestQueryDSLConfig.java => TestQuerydslConfig.java} (84%) diff --git a/src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java b/src/main/java/com/apps/pochak/global/config/QuerydslConfig.java similarity index 94% rename from src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java rename to src/main/java/com/apps/pochak/global/config/QuerydslConfig.java index 1d266646..ed8836c9 100644 --- a/src/main/java/com/apps/pochak/global/config/QueryDSLConfig.java +++ b/src/main/java/com/apps/pochak/global/config/QuerydslConfig.java @@ -8,7 +8,7 @@ @Configuration @RequiredArgsConstructor -public class QueryDSLConfig { +public class QuerydslConfig { private final EntityManager entityManager; @Bean diff --git a/src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java b/src/test/java/com/apps/pochak/global/TestQuerydslConfig.java similarity index 84% rename from src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java rename to src/test/java/com/apps/pochak/global/TestQuerydslConfig.java index d3139b1e..5c3e5b65 100644 --- a/src/test/java/com/apps/pochak/global/TestQueryDSLConfig.java +++ b/src/test/java/com/apps/pochak/global/TestQuerydslConfig.java @@ -6,9 +6,11 @@ import jakarta.persistence.PersistenceContext; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @TestConfiguration -public class TestQueryDSLConfig { +@EnableJpaAuditing +public class TestQuerydslConfig { @PersistenceContext private EntityManager entityManager; diff --git a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java index c77622b9..e5a9a9fa 100644 --- a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java +++ b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java @@ -1,17 +1,19 @@ package com.apps.pochak.post.domain.repository; -import com.apps.pochak.global.TestQueryDSLConfig; +import com.apps.pochak.global.TestQuerydslConfig; import com.apps.pochak.member.domain.repository.MemberRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; @DataJpaTest -@Import(TestQueryDSLConfig.class) +@Import(TestQuerydslConfig.class) class PostCustomRepositoryTest { @Autowired PostCustomRepository postCustomRepository; @Autowired MemberRepository memberRepository; + + } \ No newline at end of file From 04741c3dc3cb49a7d04e0575e2b4b3d50ea0a7d1 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sat, 28 Sep 2024 17:18:30 +0900 Subject: [PATCH 08/16] =?UTF-8?q?Test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=84=A4=EC=A0=95=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PostCustomRepositoryTest.java | 85 ++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java index e5a9a9fa..603a444b 100644 --- a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java +++ b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java @@ -2,18 +2,101 @@ import com.apps.pochak.global.TestQuerydslConfig; import com.apps.pochak.member.domain.repository.MemberRepository; +import com.apps.pochak.tag.domain.repository.TagRepository; +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 org.springframework.context.annotation.Import; +import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; +import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.tag.fixture.TagFixture.APPROVED_TAG; + @DataJpaTest @Import(TestQuerydslConfig.class) class PostCustomRepositoryTest { @Autowired PostCustomRepository postCustomRepository; + @Autowired + PostRepository postRepository; + @Autowired MemberRepository memberRepository; - + @Autowired + TagRepository tagRepository; + + @BeforeEach + void setUp() { + memberRepository.save(MEMBER1); + memberRepository.save(MEMBER2); + + PUBLIC_POST.makePublic(); + postRepository.save(PUBLIC_POST); + tagRepository.save(APPROVED_TAG); + } + + @DisplayName("차단된 게시물을 제외한 게시물이 조회된다.") + @Test + void findById() throws Exception{ + //given + + //when + + //then + } + + @DisplayName("유효한 id가 없는 경우 조회되지 않는다.") + @Test + void findById_WhenIdIsInvalid() throws Exception{ + //given + + //when + + //then + } + + @DisplayName("게시물을 업로드한 사람이 현재 로그인한 사람을 차단하였다면 조회되지 않는다.") + @Test + void findById_WhenOwnerBlockLoginMember() throws Exception{ + //given + + //when + + //then + } + + @DisplayName("게시물에 태그된 사람 중 한명이라도 현재 로그인한 사람을 차단하였다면 조회되지 않는다.") + @Test + void findById_WhenTaggedMemberBlockLoginMember() throws Exception{ + //given + + //when + + //then + } + + @DisplayName("현재 로그인한 사람이 게시물을 업로드한 사람을 차단하였다면 조회되지 않는다.") + @Test + void findById_WhenLoginMemberBlockOwner() throws Exception{ + //given + + //when + + //then + } + + @DisplayName("현재 로그인한 사람이 게시물에 태그된 사람 중 한명이라도 차단하였다면 조회되지 않는다.") + @Test + void findPostByIdWithoutBlockPostWhenLoginMemberBlockTaggedMember() throws Exception{ + //given + + //when + + //then + } } \ No newline at end of file From 51cd0dbe3ed6ab8d9c50e488e381180f26ddfddc Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sun, 29 Sep 2024 01:46:00 +0900 Subject: [PATCH 09/16] =?UTF-8?q?Refactor:=20Fixture=20static=ED=95=9C=20?= =?UTF-8?q?=EA=B2=83=EA=B3=BC=20=EB=B6=84=EB=A6=AC=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pochak/alarm/fixture/AlarmFixture.java | 40 +++++----- .../pochak/block/fixture/BlockFixture.java | 9 +-- .../comment/fixture/CommentFixture.java | 19 +++-- .../pochak/follow/fixture/FollowFixture.java | 16 ++-- .../apps/pochak/like/fixture/LikeFixture.java | 18 ++--- .../login/controller/OAuthControllerTest.java | 4 +- .../pochak/member/fixture/MemberFixture.java | 78 ++++++++++++------- .../apps/pochak/post/fixture/PostFixture.java | 27 ++++--- .../apps/pochak/tag/fixture/TagFixture.java | 43 +++++----- 9 files changed, 141 insertions(+), 113 deletions(-) diff --git a/src/test/java/com/apps/pochak/alarm/fixture/AlarmFixture.java b/src/test/java/com/apps/pochak/alarm/fixture/AlarmFixture.java index 35ffbe64..92c091af 100644 --- a/src/test/java/com/apps/pochak/alarm/fixture/AlarmFixture.java +++ b/src/test/java/com/apps/pochak/alarm/fixture/AlarmFixture.java @@ -7,39 +7,39 @@ import static com.apps.pochak.alarm.domain.AlarmType.COMMENT_REPLY; import static com.apps.pochak.alarm.domain.AlarmType.OWNER_LIKE; -import static com.apps.pochak.comment.fixture.CommentFixture.CHILD_COMMENT; -import static com.apps.pochak.follow.fixture.FollowFixture.RECEIVE_FOLLOW; -import static com.apps.pochak.like.fixture.LikeFixture.LIKE2; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; -import static com.apps.pochak.tag.fixture.TagFixture.WAITING_TAG; +import static com.apps.pochak.comment.fixture.CommentFixture.STATIC_CHILD_COMMENT; +import static com.apps.pochak.follow.fixture.FollowFixture.STATIC_RECEIVE_FOLLOW; +import static com.apps.pochak.like.fixture.LikeFixture.STATIC_LIKE2; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; +import static com.apps.pochak.tag.fixture.TagFixture.STATIC_WAITING_TAG; public class AlarmFixture { - public static final CommentAlarm COMMENT_REPLY_ALARM = new CommentAlarm( + public static final CommentAlarm STATIC_COMMENT_REPLY_ALARM = new CommentAlarm( 1L, - CHILD_COMMENT, - MEMBER1, + STATIC_CHILD_COMMENT, + STATIC_MEMBER1, COMMENT_REPLY ); - public static final FollowAlarm FOLLOW_ALARM = new FollowAlarm( + public static final FollowAlarm STATIC_FOLLOW_ALARM = new FollowAlarm( 2L, - RECEIVE_FOLLOW, - MEMBER1 + STATIC_RECEIVE_FOLLOW, + STATIC_MEMBER1 ); - public static final LikeAlarm TAGGED_LIKE_ALARM = new LikeAlarm( + public static final LikeAlarm STATIC_TAGGED_LIKE_ALARM = new LikeAlarm( 3L, - LIKE2, - MEMBER1, + STATIC_LIKE2, + STATIC_MEMBER1, OWNER_LIKE ); - public static final TagAlarm TAG_ALARM = new TagAlarm( - 4L, - WAITING_TAG, - MEMBER2, - MEMBER1 + public static final TagAlarm STATIC_TAG_ALARM = new TagAlarm( + 4L, + STATIC_WAITING_TAG, + STATIC_MEMBER2, + STATIC_MEMBER1 ); } diff --git a/src/test/java/com/apps/pochak/block/fixture/BlockFixture.java b/src/test/java/com/apps/pochak/block/fixture/BlockFixture.java index b2532842..c7eafd9e 100644 --- a/src/test/java/com/apps/pochak/block/fixture/BlockFixture.java +++ b/src/test/java/com/apps/pochak/block/fixture/BlockFixture.java @@ -2,14 +2,13 @@ import com.apps.pochak.block.domain.Block; -import static com.apps.pochak.member.fixture.MemberFixture.BLOCKED_MEMBER; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; public class BlockFixture { - public static final Block BLOCK = new Block( + public static final Block STATIC_BLOCK = new Block( 1L, - MEMBER1, - BLOCKED_MEMBER + STATIC_MEMBER1, + STATIC_MEMBER1 ); } diff --git a/src/test/java/com/apps/pochak/comment/fixture/CommentFixture.java b/src/test/java/com/apps/pochak/comment/fixture/CommentFixture.java index 1c890e86..ff6d2c8e 100644 --- a/src/test/java/com/apps/pochak/comment/fixture/CommentFixture.java +++ b/src/test/java/com/apps/pochak/comment/fixture/CommentFixture.java @@ -2,24 +2,23 @@ import com.apps.pochak.comment.domain.Comment; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; public class CommentFixture { - public static final Comment PARENT_COMMENT = new Comment( + public static final Comment STATIC_PARENT_COMMENT = new Comment( 1L, "부모 댓글입니다.", - MEMBER1, - PUBLIC_POST + STATIC_MEMBER1, + STATIC_PUBLIC_POST ); - public static final Comment CHILD_COMMENT = new Comment( + public static final Comment STATIC_CHILD_COMMENT = new Comment( 2L, "자식 댓글입니다.", - MEMBER2, - PUBLIC_POST, - PARENT_COMMENT + STATIC_MEMBER1, + STATIC_PUBLIC_POST, + STATIC_PARENT_COMMENT ); } diff --git a/src/test/java/com/apps/pochak/follow/fixture/FollowFixture.java b/src/test/java/com/apps/pochak/follow/fixture/FollowFixture.java index 61b3a35d..eb7b6702 100644 --- a/src/test/java/com/apps/pochak/follow/fixture/FollowFixture.java +++ b/src/test/java/com/apps/pochak/follow/fixture/FollowFixture.java @@ -2,19 +2,19 @@ import com.apps.pochak.follow.domain.Follow; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; public class FollowFixture { - public static final Follow SEND_FOLLOW = new Follow( + public static final Follow STATIC_SEND_FOLLOW = new Follow( 1L, - MEMBER1, - MEMBER2 + STATIC_MEMBER1, + STATIC_MEMBER2 ); - public static final Follow RECEIVE_FOLLOW = new Follow( + public static final Follow STATIC_RECEIVE_FOLLOW = new Follow( 2L, - MEMBER2, - MEMBER1 + STATIC_MEMBER2, + STATIC_MEMBER1 ); } \ No newline at end of file diff --git a/src/test/java/com/apps/pochak/like/fixture/LikeFixture.java b/src/test/java/com/apps/pochak/like/fixture/LikeFixture.java index 6c4a4519..d5d902d8 100644 --- a/src/test/java/com/apps/pochak/like/fixture/LikeFixture.java +++ b/src/test/java/com/apps/pochak/like/fixture/LikeFixture.java @@ -2,21 +2,21 @@ import com.apps.pochak.like.domain.LikeEntity; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; public class LikeFixture { - public static final LikeEntity LIKE1 = new LikeEntity( + public static final LikeEntity STATIC_LIKE1 = new LikeEntity( 1L, - MEMBER1, - PUBLIC_POST + STATIC_MEMBER1, + STATIC_PUBLIC_POST ); - public static final LikeEntity LIKE2 = new LikeEntity( + public static final LikeEntity STATIC_LIKE2 = new LikeEntity( 2L, - MEMBER2, - PUBLIC_POST + STATIC_MEMBER2, + STATIC_PUBLIC_POST ); } diff --git a/src/test/java/com/apps/pochak/login/controller/OAuthControllerTest.java b/src/test/java/com/apps/pochak/login/controller/OAuthControllerTest.java index 83654f14..4bedff04 100644 --- a/src/test/java/com/apps/pochak/login/controller/OAuthControllerTest.java +++ b/src/test/java/com/apps/pochak/login/controller/OAuthControllerTest.java @@ -7,6 +7,7 @@ import com.apps.pochak.login.service.AppleOAuthService; import com.apps.pochak.login.service.GoogleOAuthService; import com.apps.pochak.login.service.OAuthService; +import com.apps.pochak.member.domain.Member; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -19,7 +20,7 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.MockMultipartFileConverter.getSampleMultipartFile; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -39,6 +40,7 @@ @WebMvcTest(OAuthController.class) @MockBean(JpaMetamodelMappingContext.class) public class OAuthControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; @MockBean OAuthService oAuthService; diff --git a/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java b/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java index 3930754d..3b9db8e9 100644 --- a/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java +++ b/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java @@ -7,9 +7,9 @@ public class MemberFixture { private static final String PROFILE_IMAGE = "https://avatars.githubusercontent.com/u/163827369?s=200&v=4"; - public static final Member MEMBER1 = new Member( + public static final Member STATIC_MEMBER1 = new Member( 1L, - "member1", + "static-member1", "1번 회원의 이름", "한 줄 소개", "aaa@pochak.com", @@ -20,9 +20,9 @@ public class MemberFixture { "SOCIAL_REFRESH_TOKEN" ); - public static final Member MEMBER2 = new Member( + public static final Member STATIC_MEMBER2 = new Member( 2L, - "member2", + "static-member2", "2번 회원의 이름", "한 줄 소개", "aaa@pochak.com", @@ -33,29 +33,51 @@ public class MemberFixture { "SOCIAL_REFRESH_TOKEN" ); - public static final Member MEMBER3 = new Member( - 3L, - "member3", - "3번 회원의 이름", - "한 줄 소개", - "aaa@pochak.com", - PROFILE_IMAGE, - "REFRESH_TOKEN", - "SOCIAL_ID", - SocialType.APPLE, - "SOCIAL_REFRESH_TOKEN" - ); + public static final Member OWNER = Member.signupMember() + .name("게시물 업로드한 사람") + .email("aaa@pochak.com") + .handle("owner") + .message("한 줄 소개") + .socialId("SOCIAL_ID") + .profileImage(PROFILE_IMAGE) + .refreshToken("REFRESH_TOKEN") + .socialType(SocialType.GOOGLE) + .socialRefreshToken("SOCIAL_REFRESH_TOKEN") + .build(); - public static final Member BLOCKED_MEMBER = new Member( - 4L, - "blocked_member", - "차단된 회원의 이름", - "한 줄 소개", - "aaa@pochak.com", - PROFILE_IMAGE, - "REFRESH_TOKEN", - "SOCIAL_ID", - SocialType.APPLE, - "SOCIAL_REFRESH_TOKEN" - ); + public static final Member TAGGED_MEMBER1 = Member.signupMember() + .name("태그된 사람 1번") + .email("aaa@pochak.com") + .handle("tagged_member1") + .message("한 줄 소개") + .socialId("SOCIAL_ID") + .profileImage(PROFILE_IMAGE) + .refreshToken("REFRESH_TOKEN") + .socialType(SocialType.GOOGLE) + .socialRefreshToken("SOCIAL_REFRESH_TOKEN") + .build(); + + public static final Member TAGGED_MEMBER2 = Member.signupMember() + .name("태그된 사람 2번") + .email("aaa@pochak.com") + .handle("tagged_member1") + .message("한 줄 소개") + .socialId("SOCIAL_ID") + .profileImage(PROFILE_IMAGE) + .refreshToken("REFRESH_TOKEN") + .socialType(SocialType.GOOGLE) + .socialRefreshToken("SOCIAL_REFRESH_TOKEN") + .build(); + + public static final Member LOGIN_MEMBER = Member.signupMember() + .name("로그인한 사람") + .email("aaa@pochak.com") + .handle("login_member") + .message("한 줄 소개") + .socialId("SOCIAL_ID") + .profileImage(PROFILE_IMAGE) + .refreshToken("REFRESH_TOKEN") + .socialType(SocialType.GOOGLE) + .socialRefreshToken("SOCIAL_REFRESH_TOKEN") + .build(); } diff --git a/src/test/java/com/apps/pochak/post/fixture/PostFixture.java b/src/test/java/com/apps/pochak/post/fixture/PostFixture.java index b304a1e2..145e11e7 100644 --- a/src/test/java/com/apps/pochak/post/fixture/PostFixture.java +++ b/src/test/java/com/apps/pochak/post/fixture/PostFixture.java @@ -12,30 +12,33 @@ public class PostFixture { private static final String POST_IMAGE = "https://avatars.githubusercontent.com/u/163827369?s=200&v=4"; - public static final Post PUBLIC_POST = new Post( + public static final Post STATIC_PUBLIC_POST = new Post( 1L, PUBLIC, LocalDateTime.now(), - MEMBER1, + STATIC_MEMBER1, POST_IMAGE, "공개 게시물 캡션입니다." ); - public static final Post PRIVATE_POST = new Post( + public static final Post STATIC_PRIVATE_POST = new Post( 2L, PRIVATE, LocalDateTime.now(), - MEMBER2, + STATIC_MEMBER2, POST_IMAGE, "아직 수락되지 않은 게시물의 캡션입니다." ); - public static final Post POST_WITH_MULTI_TAG = new Post( - 3L, - PUBLIC, - LocalDateTime.now(), - MEMBER3, - POST_IMAGE, - "공개 게시물2 캡션입니다." - ); // 다수의 태그 생성 목적 + public static final Post PUBLIC_POST = Post.builder() + .owner(OWNER) + .postImage(POST_IMAGE) + .caption("하나의 태그를 가진 게시물입니다.") + .build(); + + public static final Post POST_WITH_MULTI_TAG = Post.builder() + .owner(OWNER) + .postImage(POST_IMAGE) + .caption("다중 태그를 가진 게시물입니다.") + .build(); } diff --git a/src/test/java/com/apps/pochak/tag/fixture/TagFixture.java b/src/test/java/com/apps/pochak/tag/fixture/TagFixture.java index b4b03123..17d59fef 100644 --- a/src/test/java/com/apps/pochak/tag/fixture/TagFixture.java +++ b/src/test/java/com/apps/pochak/tag/fixture/TagFixture.java @@ -2,33 +2,36 @@ import com.apps.pochak.tag.domain.Tag; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; +import static com.apps.pochak.member.fixture.MemberFixture.*; import static com.apps.pochak.post.fixture.PostFixture.*; public class TagFixture { - public static final Tag APPROVED_TAG = new Tag( + public static final Tag STATIC_APPROVED_TAG = new Tag( 1L, - PUBLIC_POST, - MEMBER2, + STATIC_PUBLIC_POST, + STATIC_MEMBER2, true ); - public static final Tag WAITING_TAG = new Tag( + + public static final Tag STATIC_WAITING_TAG = new Tag( 2L, - PRIVATE_POST, - MEMBER1, + STATIC_PRIVATE_POST, + STATIC_MEMBER1, false ); - public static final Tag TAG1_WITH_ONE_POST = new Tag( - 3L, - POST_WITH_MULTI_TAG, - MEMBER1, - true - ); - public static final Tag TAG2_WITH_ONE_POST = new Tag( - 4L, - POST_WITH_MULTI_TAG, - MEMBER2, - true - ); + + public static final Tag APPROVAL_TAG = Tag.builder() + .post(PUBLIC_POST) + .member(TAGGED_MEMBER1) + .build(); + + public static final Tag TAG1_WITH_ONE_POST = Tag.builder() + .post(POST_WITH_MULTI_TAG) + .member(TAGGED_MEMBER1) + .build(); + + public static final Tag TAG2_WITH_ONE_POST = Tag.builder() + .post(POST_WITH_MULTI_TAG) + .member(TAGGED_MEMBER2) + .build(); } From 64d7d52e1cc389f9ccf1cb0dbde9d157ed335035 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sun, 29 Sep 2024 01:46:51 +0900 Subject: [PATCH 10/16] =?UTF-8?q?Chore:=20Fixture=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../alarm/controller/AlarmControllerTest.java | 18 ++++++++++-------- .../block/controller/BlockControllerTest.java | 12 ++++++++---- .../controller/CommentControllerTest.java | 13 ++++++++----- .../controller/FollowControllerTest.java | 10 ++++++---- .../like/controller/LikeControllerTest.java | 19 ++++++++----------- .../controller/MemberControllerTest.java | 10 +++++++--- .../controller/MemoriesControllerTest.java | 16 ++++++++++++---- .../post/controller/PostControllerTest.java | 16 ++++++++++++---- .../controller/ReportControllerTest.java | 8 ++++++-- .../tag/controller/TagControllerTest.java | 12 ++++++++---- 11 files changed, 87 insertions(+), 49 deletions(-) diff --git a/build.gradle b/build.gradle index dbdf4f1c..76a412ee 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,8 @@ dependencies { compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' + testCompileOnly 'org.projectlombok:lombok:1.18.34' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.34' implementation 'com.h2database:h2' runtimeOnly 'com.h2database:h2' diff --git a/src/test/java/com/apps/pochak/alarm/controller/AlarmControllerTest.java b/src/test/java/com/apps/pochak/alarm/controller/AlarmControllerTest.java index 0795f384..232da86c 100644 --- a/src/test/java/com/apps/pochak/alarm/controller/AlarmControllerTest.java +++ b/src/test/java/com/apps/pochak/alarm/controller/AlarmControllerTest.java @@ -1,6 +1,7 @@ package com.apps.pochak.alarm.controller; import com.apps.pochak.alarm.domain.Alarm; +import com.apps.pochak.alarm.domain.TagAlarm; import com.apps.pochak.alarm.dto.response.AlarmElements; import com.apps.pochak.alarm.service.AlarmService; import com.apps.pochak.auth.domain.Accessor; @@ -24,8 +25,8 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.api_payload.code.status.SuccessStatus.SUCCESS_CHECK_ALARM; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.tag.fixture.TagFixture.WAITING_TAG; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.tag.fixture.TagFixture.STATIC_WAITING_TAG; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; @@ -45,13 +46,14 @@ @MockBean(JpaMetamodelMappingContext.class) class AlarmControllerTest extends ControllerTest { - private static final Member MEMBER = MEMBER1; + private static final Member MEMBER = STATIC_MEMBER1; + private static final TagAlarm TAG_ALARM = STATIC_TAG_ALARM; private static final List ALARM_LIST = List.of( - COMMENT_REPLY_ALARM, - FOLLOW_ALARM, - TAGGED_LIKE_ALARM, - TAG_ALARM + STATIC_COMMENT_REPLY_ALARM, + STATIC_FOLLOW_ALARM, + STATIC_TAGGED_LIKE_ALARM, + STATIC_TAG_ALARM ); @MockBean @@ -184,7 +186,7 @@ void getPreviewPostTest() throws Exception { when(postService.getPreviewPost(any(), any())) .thenReturn( - new PostPreviewResponse(TAG_ALARM.getTag().getPost(), List.of(WAITING_TAG)) + new PostPreviewResponse(TAG_ALARM.getTag().getPost(), List.of(STATIC_WAITING_TAG)) ); this.mockMvc.perform( diff --git a/src/test/java/com/apps/pochak/block/controller/BlockControllerTest.java b/src/test/java/com/apps/pochak/block/controller/BlockControllerTest.java index f8139f8f..f0a1bab0 100644 --- a/src/test/java/com/apps/pochak/block/controller/BlockControllerTest.java +++ b/src/test/java/com/apps/pochak/block/controller/BlockControllerTest.java @@ -5,6 +5,7 @@ import com.apps.pochak.block.dto.response.BlockElements; import com.apps.pochak.block.service.BlockService; import com.apps.pochak.global.ControllerTest; +import com.apps.pochak.member.domain.Member; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -16,12 +17,12 @@ import java.util.List; -import static com.apps.pochak.block.fixture.BlockFixture.BLOCK; +import static com.apps.pochak.block.fixture.BlockFixture.STATIC_BLOCK; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -41,8 +42,11 @@ @MockBean(JpaMetamodelMappingContext.class) class BlockControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Member MEMBER2 = STATIC_MEMBER2; + private static final List BLOCK_LIST = List.of( - BLOCK + STATIC_BLOCK ); @MockBean diff --git a/src/test/java/com/apps/pochak/comment/controller/CommentControllerTest.java b/src/test/java/com/apps/pochak/comment/controller/CommentControllerTest.java index e2003c57..54a39c22 100644 --- a/src/test/java/com/apps/pochak/comment/controller/CommentControllerTest.java +++ b/src/test/java/com/apps/pochak/comment/controller/CommentControllerTest.java @@ -7,6 +7,7 @@ import com.apps.pochak.comment.dto.response.ParentCommentElement; import com.apps.pochak.comment.service.CommentService; import com.apps.pochak.global.ControllerTest; +import com.apps.pochak.member.domain.Member; import com.apps.pochak.post.domain.Post; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; @@ -21,12 +22,12 @@ import java.util.List; -import static com.apps.pochak.comment.fixture.CommentFixture.PARENT_COMMENT; +import static com.apps.pochak.comment.fixture.CommentFixture.STATIC_PARENT_COMMENT; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -45,10 +46,12 @@ @MockBean(JpaMetamodelMappingContext.class) class CommentControllerTest extends ControllerTest { - private static final Post POST = PUBLIC_POST; + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Post POST = STATIC_PUBLIC_POST; + private static final Comment PARENT_COMMENT = STATIC_PARENT_COMMENT; private static final List PARENT_COMMENT_LIST = List.of( - PARENT_COMMENT + STATIC_PARENT_COMMENT ); @MockBean diff --git a/src/test/java/com/apps/pochak/follow/controller/FollowControllerTest.java b/src/test/java/com/apps/pochak/follow/controller/FollowControllerTest.java index 7b5ddc8f..a971715c 100644 --- a/src/test/java/com/apps/pochak/follow/controller/FollowControllerTest.java +++ b/src/test/java/com/apps/pochak/follow/controller/FollowControllerTest.java @@ -22,8 +22,8 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.api_payload.code.status.SuccessStatus.SUCCESS_FOLLOW; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -42,10 +42,12 @@ @WebMvcTest(FollowController.class) @MockBean(JpaMetamodelMappingContext.class) class FollowControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Member MEMBER2 = STATIC_MEMBER2; private static final List MEMBER_LIST = List.of( - MEMBER1, - MEMBER2 + STATIC_MEMBER1, + STATIC_MEMBER2 ); @MockBean diff --git a/src/test/java/com/apps/pochak/like/controller/LikeControllerTest.java b/src/test/java/com/apps/pochak/like/controller/LikeControllerTest.java index fbaf4781..93539468 100644 --- a/src/test/java/com/apps/pochak/like/controller/LikeControllerTest.java +++ b/src/test/java/com/apps/pochak/like/controller/LikeControllerTest.java @@ -2,10 +2,11 @@ import com.apps.pochak.auth.domain.Accessor; import com.apps.pochak.global.ControllerTest; -import com.apps.pochak.like.domain.LikeEntity; import com.apps.pochak.like.dto.response.LikeElement; import com.apps.pochak.like.dto.response.LikeElements; import com.apps.pochak.like.service.LikeService; +import com.apps.pochak.member.domain.Member; +import com.apps.pochak.post.domain.Post; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -21,11 +22,9 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; -import static com.apps.pochak.like.fixture.LikeFixture.LIKE1; -import static com.apps.pochak.like.fixture.LikeFixture.LIKE2; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -45,11 +44,9 @@ @WebMvcTest(LikeController.class) @MockBean(JpaMetamodelMappingContext.class) public class LikeControllerTest extends ControllerTest { - - private static final List LIKE_LIST = List.of( - LIKE1, - LIKE2 - ); + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Member MEMBER2 = STATIC_MEMBER2; + private static final Post PUBLIC_POST = STATIC_PUBLIC_POST; @MockBean LikeService likeService; diff --git a/src/test/java/com/apps/pochak/member/controller/MemberControllerTest.java b/src/test/java/com/apps/pochak/member/controller/MemberControllerTest.java index c3b07018..214bf286 100644 --- a/src/test/java/com/apps/pochak/member/controller/MemberControllerTest.java +++ b/src/test/java/com/apps/pochak/member/controller/MemberControllerTest.java @@ -7,6 +7,7 @@ import com.apps.pochak.member.dto.response.ProfileResponse; import com.apps.pochak.member.dto.response.ProfileUpdateResponse; import com.apps.pochak.member.service.MemberService; +import com.apps.pochak.post.domain.Post; import com.apps.pochak.post.dto.PostElements; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -26,9 +27,9 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.MockMultipartFileConverter.getSampleMultipartFile; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -47,6 +48,9 @@ @WebMvcTest(MemberController.class) @MockBean(JpaMetamodelMappingContext.class) class MemberControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Member MEMBER2 = STATIC_MEMBER2; + private static final Post PUBLIC_POST = STATIC_PUBLIC_POST; private static final List MEMBER_LIST = List.of( MEMBER1, diff --git a/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java b/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java index f86c28f7..98cc71b8 100644 --- a/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java +++ b/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java @@ -1,10 +1,13 @@ package com.apps.pochak.memories.controller; import com.apps.pochak.auth.domain.Accessor; +import com.apps.pochak.follow.domain.Follow; import com.apps.pochak.global.ControllerTest; +import com.apps.pochak.member.domain.Member; import com.apps.pochak.memories.dto.response.MemoriesPostResponse; import com.apps.pochak.memories.dto.response.MemoriesPreviewResponse; import com.apps.pochak.memories.service.MemoriesService; +import com.apps.pochak.tag.domain.Tag; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -16,13 +19,13 @@ import java.util.List; -import static com.apps.pochak.follow.fixture.FollowFixture.RECEIVE_FOLLOW; -import static com.apps.pochak.follow.fixture.FollowFixture.SEND_FOLLOW; +import static com.apps.pochak.follow.fixture.FollowFixture.STATIC_RECEIVE_FOLLOW; +import static com.apps.pochak.follow.fixture.FollowFixture.STATIC_SEND_FOLLOW; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; import static com.apps.pochak.tag.fixture.TagFixture.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -41,6 +44,11 @@ @WebMvcTest(MemoriesController.class) @MockBean(JpaMetamodelMappingContext.class) class MemoriesControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Member MEMBER2 = STATIC_MEMBER2; + private static final Follow SEND_FOLLOW = STATIC_SEND_FOLLOW; + private static final Follow RECEIVE_FOLLOW = STATIC_RECEIVE_FOLLOW; + private static final Tag APPROVED_TAG = STATIC_APPROVED_TAG; @MockBean MemoriesService memoriesService; diff --git a/src/test/java/com/apps/pochak/post/controller/PostControllerTest.java b/src/test/java/com/apps/pochak/post/controller/PostControllerTest.java index ebc9ad01..a3b91bb2 100644 --- a/src/test/java/com/apps/pochak/post/controller/PostControllerTest.java +++ b/src/test/java/com/apps/pochak/post/controller/PostControllerTest.java @@ -1,10 +1,14 @@ package com.apps.pochak.post.controller; import com.apps.pochak.auth.domain.Accessor; +import com.apps.pochak.comment.domain.Comment; import com.apps.pochak.global.ControllerTest; +import com.apps.pochak.member.domain.Member; +import com.apps.pochak.post.domain.Post; import com.apps.pochak.post.dto.PostElements; import com.apps.pochak.post.dto.response.PostDetailResponse; import com.apps.pochak.post.service.PostService; +import com.apps.pochak.tag.domain.Tag; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -16,14 +20,14 @@ import java.util.List; -import static com.apps.pochak.comment.fixture.CommentFixture.CHILD_COMMENT; +import static com.apps.pochak.comment.fixture.CommentFixture.STATIC_CHILD_COMMENT; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.MockMultipartFileConverter.getSampleMultipartFile; import static com.apps.pochak.global.converter.ListToPageConverter.toPage; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; -import static com.apps.pochak.tag.fixture.TagFixture.APPROVED_TAG; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; +import static com.apps.pochak.tag.fixture.TagFixture.STATIC_APPROVED_TAG; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -43,6 +47,10 @@ @WebMvcTest(PostController.class) @MockBean(JpaMetamodelMappingContext.class) class PostControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Comment CHILD_COMMENT = STATIC_CHILD_COMMENT; + private static final Post PUBLIC_POST = STATIC_PUBLIC_POST; + private static final Tag APPROVED_TAG = STATIC_APPROVED_TAG; @MockBean PostService postService; diff --git a/src/test/java/com/apps/pochak/report/controller/ReportControllerTest.java b/src/test/java/com/apps/pochak/report/controller/ReportControllerTest.java index e880fd32..9a535a1d 100644 --- a/src/test/java/com/apps/pochak/report/controller/ReportControllerTest.java +++ b/src/test/java/com/apps/pochak/report/controller/ReportControllerTest.java @@ -2,6 +2,8 @@ import com.apps.pochak.auth.domain.Accessor; import com.apps.pochak.global.ControllerTest; +import com.apps.pochak.member.domain.Member; +import com.apps.pochak.post.domain.Post; import com.apps.pochak.report.domain.ReportType; import com.apps.pochak.report.dto.request.ReportUploadRequest; import com.apps.pochak.report.service.ReportService; @@ -18,8 +20,8 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.post.fixture.PostFixture.STATIC_PUBLIC_POST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; @@ -35,6 +37,8 @@ @WebMvcTest(ReportController.class) @MockBean(JpaMetamodelMappingContext.class) class ReportControllerTest extends ControllerTest { + private static final Member MEMBER1 = STATIC_MEMBER1; + private static final Post PUBLIC_POST = STATIC_PUBLIC_POST; @MockBean ReportService reportService; diff --git a/src/test/java/com/apps/pochak/tag/controller/TagControllerTest.java b/src/test/java/com/apps/pochak/tag/controller/TagControllerTest.java index 05dcc064..b1419640 100644 --- a/src/test/java/com/apps/pochak/tag/controller/TagControllerTest.java +++ b/src/test/java/com/apps/pochak/tag/controller/TagControllerTest.java @@ -2,6 +2,8 @@ import com.apps.pochak.auth.domain.Accessor; import com.apps.pochak.global.ControllerTest; +import com.apps.pochak.member.domain.Member; +import com.apps.pochak.tag.domain.Tag; import com.apps.pochak.tag.service.TagService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -15,8 +17,8 @@ import static com.apps.pochak.global.ApiDocumentUtils.getDocumentRequest; import static com.apps.pochak.global.ApiDocumentUtils.getDocumentResponse; import static com.apps.pochak.global.api_payload.code.status.SuccessStatus.SUCCESS_ACCEPT; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.tag.fixture.TagFixture.WAITING_TAG; +import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; +import static com.apps.pochak.tag.fixture.TagFixture.STATIC_WAITING_TAG; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; @@ -35,6 +37,8 @@ @WebMvcTest(TagController.class) @MockBean(JpaMetamodelMappingContext.class) class TagControllerTest extends ControllerTest { + private static final Member MEMBER = STATIC_MEMBER1; + private static final Tag WAITING_TAG = STATIC_WAITING_TAG; @MockBean TagService tagService; @@ -42,9 +46,9 @@ class TagControllerTest extends ControllerTest { @BeforeEach void setUp() { given(jwtProvider.validateAccessToken(any())).willReturn(true); - given(jwtProvider.getSubject(any())).willReturn(MEMBER1.getId().toString()); + given(jwtProvider.getSubject(any())).willReturn(MEMBER.getId().toString()); given(loginArgumentResolver.resolveArgument(any(), any(), any(), any())) - .willReturn(Accessor.member(MEMBER1.getId())); + .willReturn(Accessor.member(MEMBER.getId())); } @Test From 061c630e7193553b7006a3c6170455428a038794 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sun, 29 Sep 2024 01:47:48 +0900 Subject: [PATCH 11/16] =?UTF-8?q?Test:=20`findPostByIdWithoutBlockPost()`?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PostCustomRepositoryTest.java | 165 +++++++++++++++--- 1 file changed, 144 insertions(+), 21 deletions(-) diff --git a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java index 603a444b..4b400e83 100644 --- a/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java +++ b/src/test/java/com/apps/pochak/post/domain/repository/PostCustomRepositoryTest.java @@ -1,23 +1,42 @@ package com.apps.pochak.post.domain.repository; +import com.apps.pochak.block.domain.Block; +import com.apps.pochak.block.domain.repository.BlockRepository; import com.apps.pochak.global.TestQuerydslConfig; +import com.apps.pochak.global.api_payload.exception.GeneralException; +import com.apps.pochak.member.domain.Member; import com.apps.pochak.member.domain.repository.MemberRepository; +import com.apps.pochak.member.fixture.MemberFixture; +import com.apps.pochak.post.domain.Post; +import com.apps.pochak.tag.domain.Tag; import com.apps.pochak.tag.domain.repository.TagRepository; -import org.junit.jupiter.api.BeforeEach; +import lombok.Builder; +import lombok.Data; 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 org.springframework.context.annotation.Import; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER1; -import static com.apps.pochak.member.fixture.MemberFixture.MEMBER2; -import static com.apps.pochak.post.fixture.PostFixture.PUBLIC_POST; -import static com.apps.pochak.tag.fixture.TagFixture.APPROVED_TAG; +import static com.apps.pochak.global.api_payload.code.status.ErrorStatus.BLOCKED_POST; +import static com.apps.pochak.post.fixture.PostFixture.POST_WITH_MULTI_TAG; +import static com.apps.pochak.tag.fixture.TagFixture.TAG1_WITH_ONE_POST; +import static com.apps.pochak.tag.fixture.TagFixture.TAG2_WITH_ONE_POST; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; @DataJpaTest @Import(TestQuerydslConfig.class) class PostCustomRepositoryTest { + + private static final Post POST = POST_WITH_MULTI_TAG; + private static final Tag TAG1 = TAG1_WITH_ONE_POST; + private static final Tag TAG2 = TAG2_WITH_ONE_POST; + private static final Member OWNER = MemberFixture.OWNER; + private static final Member TAGGED_MEMBER1 = MemberFixture.TAGGED_MEMBER1; + private static final Member TAGGED_MEMBER2 = MemberFixture.TAGGED_MEMBER2; + private static final Member LOGIN_MEMBER = MemberFixture.LOGIN_MEMBER; + @Autowired PostCustomRepository postCustomRepository; @@ -30,73 +49,177 @@ class PostCustomRepositoryTest { @Autowired TagRepository tagRepository; - @BeforeEach - void setUp() { - memberRepository.save(MEMBER1); - memberRepository.save(MEMBER2); - - PUBLIC_POST.makePublic(); - postRepository.save(PUBLIC_POST); - tagRepository.save(APPROVED_TAG); + @Autowired + BlockRepository blockRepository; + + private SavedPostData savePost() { + return SavedPostData.of() + .owner(memberRepository.save(OWNER)) + .taggedMember1(memberRepository.save(TAGGED_MEMBER1)) + .taggedMember2(memberRepository.save(TAGGED_MEMBER2)) + .loginMember(memberRepository.save(LOGIN_MEMBER)) + .savedPost(postRepository.save(POST)) + .tag1(tagRepository.save(TAG1)) + .tag2(tagRepository.save(TAG2)) + .build(); } @DisplayName("차단된 게시물을 제외한 게시물이 조회된다.") @Test - void findById() throws Exception{ + void findById() throws Exception { //given - + SavedPostData savedPostData = savePost(); + Member loginMember = savedPostData.getLoginMember(); + Post savedPost = savedPostData.getSavedPost(); + //when - + Post findPost = postCustomRepository.findPostByIdWithoutBlockPost(savedPost.getId(), loginMember.getId()); + //then + assertEquals(savedPost.getId(), findPost.getId()); } @DisplayName("유효한 id가 없는 경우 조회되지 않는다.") @Test - void findById_WhenIdIsInvalid() throws Exception{ + void findById_WhenIdIsInvalid() throws Exception { //given + SavedPostData savedPostData = savePost(); + Member loginMember = savedPostData.getLoginMember(); + Long invalidPostId = 0L; //when + GeneralException exception = assertThrows( + GeneralException.class, + () -> postCustomRepository.findPostByIdWithoutBlockPost(invalidPostId, loginMember.getId()) + ); //then + assertEquals(BLOCKED_POST, exception.getCode()); } @DisplayName("게시물을 업로드한 사람이 현재 로그인한 사람을 차단하였다면 조회되지 않는다.") @Test - void findById_WhenOwnerBlockLoginMember() throws Exception{ + void findById_WhenOwnerBlockLoginMember() throws Exception { //given + SavedPostData savedPostData = savePost(); + Member owner = savedPostData.getOwner(); + Member loginMember = savedPostData.getLoginMember(); + Post savedPost = savedPostData.getSavedPost(); + + blockRepository.save(new Block( + owner, + loginMember + )); //when + GeneralException exception = assertThrows( + GeneralException.class, + () -> postCustomRepository.findPostByIdWithoutBlockPost(savedPost.getId(), loginMember.getId()) + ); //then + assertEquals(BLOCKED_POST, exception.getCode()); } @DisplayName("게시물에 태그된 사람 중 한명이라도 현재 로그인한 사람을 차단하였다면 조회되지 않는다.") @Test - void findById_WhenTaggedMemberBlockLoginMember() throws Exception{ + void findById_WhenTaggedMemberBlockLoginMember() throws Exception { //given + SavedPostData savedPostData = savePost(); + Member taggedMember1 = savedPostData.getTaggedMember1(); + Member loginMember = savedPostData.getLoginMember(); + Post savedPost = savedPostData.getSavedPost(); + + blockRepository.save(new Block( + taggedMember1, + loginMember + )); //when + GeneralException exception = assertThrows( + GeneralException.class, + () -> postCustomRepository.findPostByIdWithoutBlockPost(savedPost.getId(), loginMember.getId()) + ); //then + assertEquals(BLOCKED_POST, exception.getCode()); } @DisplayName("현재 로그인한 사람이 게시물을 업로드한 사람을 차단하였다면 조회되지 않는다.") @Test - void findById_WhenLoginMemberBlockOwner() throws Exception{ + void findById_WhenLoginMemberBlockOwner() throws Exception { //given + SavedPostData savedPostData = savePost(); + Member loginMember = savedPostData.getLoginMember(); + Member owner = savedPostData.getOwner(); + Post savedPost = savedPostData.getSavedPost(); + + blockRepository.save(new Block( + loginMember, + owner + )); //when + GeneralException exception = assertThrows( + GeneralException.class, + () -> postCustomRepository.findPostByIdWithoutBlockPost(savedPost.getId(), loginMember.getId()) + ); //then + assertEquals(BLOCKED_POST, exception.getCode()); } @DisplayName("현재 로그인한 사람이 게시물에 태그된 사람 중 한명이라도 차단하였다면 조회되지 않는다.") @Test - void findPostByIdWithoutBlockPostWhenLoginMemberBlockTaggedMember() throws Exception{ + void findPostByIdWithoutBlockPostWhenLoginMemberBlockTaggedMember() throws Exception { //given + SavedPostData savedPostData = savePost(); + Member loginMember = savedPostData.getLoginMember(); + Member taggedMember1 = savedPostData.getTaggedMember1(); + Post savedPost = savedPostData.getSavedPost(); + + blockRepository.save(new Block( + loginMember, + taggedMember1 + )); //when + GeneralException exception = assertThrows( + GeneralException.class, + () -> postCustomRepository.findPostByIdWithoutBlockPost(savedPost.getId(), loginMember.getId()) + ); //then + assertEquals(BLOCKED_POST, exception.getCode()); + } +} + +@Data +class SavedPostData { + private Post savedPost; + private Tag tag1; + private Tag tag2; + private Member owner; + private Member taggedMember1; + private Member taggedMember2; + private Member loginMember; + + @Builder(builderMethodName = "of") + public SavedPostData( + final Post savedPost, + final Tag tag1, + final Tag tag2, + final Member owner, + final Member taggedMember1, + final Member taggedMember2, + final Member loginMember + ) { + this.savedPost = savedPost; + this.tag1 = tag1; + this.tag2 = tag2; + this.owner = owner; + this.taggedMember1 = taggedMember1; + this.taggedMember2 = taggedMember2; + this.loginMember = loginMember; } } \ No newline at end of file From 1dfc91bba1d98cd00f0544144598078c02eebf3f Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sun, 29 Sep 2024 02:10:50 +0900 Subject: [PATCH 12/16] =?UTF-8?q?Chore:=20handle=20unique=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=EB=B3=80=EA=B2=BD=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/apps/pochak/member/fixture/MemberFixture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java b/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java index 3b9db8e9..70281c0d 100644 --- a/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java +++ b/src/test/java/com/apps/pochak/member/fixture/MemberFixture.java @@ -60,7 +60,7 @@ public class MemberFixture { public static final Member TAGGED_MEMBER2 = Member.signupMember() .name("태그된 사람 2번") .email("aaa@pochak.com") - .handle("tagged_member1") + .handle("tagged_member2") .message("한 줄 소개") .socialId("SOCIAL_ID") .profileImage(PROFILE_IMAGE) From cce886270855efc87422ccf28f114a994acdae8e Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Sun, 29 Sep 2024 02:11:20 +0900 Subject: [PATCH 13/16] =?UTF-8?q?Chore:=20static=20fixture=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pochak/memories/controller/MemoriesControllerTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java b/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java index 98cc71b8..6ac7e8e3 100644 --- a/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java +++ b/src/test/java/com/apps/pochak/memories/controller/MemoriesControllerTest.java @@ -26,7 +26,7 @@ import static com.apps.pochak.global.converter.ListToPageConverter.toPage; import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER1; import static com.apps.pochak.member.fixture.MemberFixture.STATIC_MEMBER2; -import static com.apps.pochak.tag.fixture.TagFixture.*; +import static com.apps.pochak.tag.fixture.TagFixture.STATIC_APPROVED_TAG; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; @@ -78,8 +78,8 @@ void getMemories() throws Exception { .countTagged(30L) .firstTagged(APPROVED_TAG) .firstTag(APPROVED_TAG) - .firstTaggedWith(TAG1_WITH_ONE_POST) - .latestTag(TAG2_WITH_ONE_POST) + .firstTaggedWith(APPROVED_TAG) + .latestTag(APPROVED_TAG) .build() ); From a1a6e48af579c0f1f40616b398bc1496904b37b9 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Mon, 30 Sep 2024 02:09:00 +0900 Subject: [PATCH 14/16] =?UTF-8?q?Chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20print=EB=AC=B8=20=EC=82=AD=EC=A0=9C=20#67?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index 76a412ee..976dc32b 100644 --- a/build.gradle +++ b/build.gradle @@ -132,5 +132,4 @@ tasks.withType(JavaCompile) { sourceSets { main.java.srcDirs += "$projectDir/build/generated" - print "$projectDir" } \ No newline at end of file From da726801ca78acdb08217cc5f793d7adc5ac0ffc Mon Sep 17 00:00:00 2001 From: yeahjinjeong Date: Mon, 30 Sep 2024 16:40:08 +0900 Subject: [PATCH 15/16] =?UTF-8?q?Fix:=20=EC=B6=94=EC=96=B5=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20TagRepository=20-=20countByMember()=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20Fixture?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?#59?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tag/domain/repository/TagRepository.java | 13 ++--- .../domain/repository/TagRepositoryTest.java | 57 ++++++++----------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/apps/pochak/tag/domain/repository/TagRepository.java b/src/main/java/com/apps/pochak/tag/domain/repository/TagRepository.java index 5691f2cc..01720833 100644 --- a/src/main/java/com/apps/pochak/tag/domain/repository/TagRepository.java +++ b/src/main/java/com/apps/pochak/tag/domain/repository/TagRepository.java @@ -97,14 +97,11 @@ void deleteTagByMemberOrPostList( Long countByPost_PostStatusAndPost_OwnerAndMember(PostStatus postStatus, Member owner, Member member); @Query(""" - select count(t) from Tag t - join t.member m - join t.post p - where p.postStatus = 'PUBLIC' - and p.status = 'ACTIVE' - and ((m = :member and p.owner = :loginMember) - or (m = :loginMember and p.owner = :member)) - order by p.allowedDate desc + select count(t1) from Tag t1 + join Tag t2 on t1.post = t2.post + where t1.post.postStatus = 'PUBLIC' + and t1.post.status = 'ACTIVE' + and (t1.member = :loginMember and t2.member = :member) """) Long countByMember(@Param("loginMember") Member loginMember, @Param("member")Member member); } diff --git a/src/test/java/com/apps/pochak/tag/domain/repository/TagRepositoryTest.java b/src/test/java/com/apps/pochak/tag/domain/repository/TagRepositoryTest.java index f169bb14..5242b5df 100644 --- a/src/test/java/com/apps/pochak/tag/domain/repository/TagRepositoryTest.java +++ b/src/test/java/com/apps/pochak/tag/domain/repository/TagRepositoryTest.java @@ -41,39 +41,27 @@ class TagRepositoryTest { @BeforeEach void setUp() { - Member owner = MEMBER1; - memberRepository.save(owner); + memberRepository.save(OWNER); + memberRepository.save(TAGGED_MEMBER1); + memberRepository.save(TAGGED_MEMBER2); - Member member = MEMBER2; - memberRepository.save(member); + PUBLIC_POST.makePublic(); + postRepository.save(PUBLIC_POST);; + tagRepository.save(APPROVAL_TAG); - Member friend = MEMBER3; - memberRepository.save(friend); + POST_WITH_MULTI_TAG.makePublic(); + postRepository.save(POST_WITH_MULTI_TAG); - Post post = PUBLIC_POST; - postRepository.save(post); - post.makePublic(); - - Tag tag = APPROVED_TAG; - tagRepository.save(tag); - - Post post2 = POST_WITH_MULTI_TAG; - postRepository.save(post2); - post2.makePublic(); - - Tag tags1 = TAG1_WITH_ONE_POST; - tagRepository.save(tags1); - - Tag tags2 = TAG2_WITH_ONE_POST; - tagRepository.save(tags2); + tagRepository.save(TAG1_WITH_ONE_POST); + tagRepository.save(TAG2_WITH_ONE_POST); } @Test @DisplayName("[추억 페이지] 친구를 태그한 첫 게시물을 조회한다.") void findFirstTaggedPost() { // given - Member owner = memberRepository.findByHandleWithoutLogin("member1"); - Member member = memberRepository.findByHandleWithoutLogin("member2"); + Member owner = memberRepository.findByHandleWithoutLogin("owner"); + Member member = memberRepository.findByHandleWithoutLogin("tagged_member1"); // when Page tag = tagRepository.findTagByOwnerAndMember(owner, member, PageRequest.of(0, 1)); // then @@ -88,8 +76,8 @@ void findFirstTaggedPost() { @DisplayName("[추억 페이지] 함께 태그된 첫 게시물을 조회한다.") void findTaggedWith() { // given - Member loginMember = memberRepository.findByHandleWithoutLogin("member1"); - Member member = memberRepository.findByHandleWithoutLogin("member2"); + Member loginMember = memberRepository.findByHandleWithoutLogin("tagged_member1"); + Member member = memberRepository.findByHandleWithoutLogin("tagged_member2"); // when Page tag = tagRepository.findTaggedWith(loginMember, member, PageRequest.of(0, 1, Sort.by(Sort.Direction.ASC, "post.allowedDate"))); // then @@ -107,8 +95,8 @@ void findTaggedWith() { @DisplayName("[추억 페이지] 가장 최근 게시물을 조회한다.") void findLatestTag() { // given - Member loginMember = memberRepository.findByHandleWithoutLogin("member1"); - Member member = memberRepository.findByHandleWithoutLogin("member2"); + Member loginMember = memberRepository.findByHandleWithoutLogin("tagged_member1"); + Member member = memberRepository.findByHandleWithoutLogin("tagged_member2"); // when Page taggedWithDesc = tagRepository.findTaggedWith(loginMember, member, PageRequest.of(0, 1, Sort.by(Sort.Direction.DESC, "post.allowedDate"))); Page tagOrTagged = tagRepository.findLatestTagged(loginMember, member, PageRequest.of(0, 1)); @@ -131,18 +119,19 @@ void findLatestTag() { @Test @DisplayName("[추억 페이지] 함께 태그된 게시물의 수를 조회한다.") void countByMember() { - Member owner = memberRepository.findByHandleWithoutLogin("member1"); - Member member = memberRepository.findByHandleWithoutLogin("member2"); + Member loginMember = memberRepository.findByHandleWithoutLogin("tagged_member1"); + Member member = memberRepository.findByHandleWithoutLogin("tagged_member2"); - Long count = tagRepository.countByMember(owner, member); - assertThat(count).isEqualTo(1); + Page taggedWith = tagRepository.findTaggedWith(loginMember, member, PageRequest.of(0, 1, Sort.by(Sort.Direction.ASC, "post.allowedDate"))); + Long count = tagRepository.countByMember(loginMember, member); + assertThat(count).isEqualTo(taggedWith.getTotalElements()); } @Test @DisplayName("[추억 페이지] 내가 태그한, 태그된 게시물의 수를 조회한다.") void countByPostOwner() { - Member owner = memberRepository.findByHandleWithoutLogin("member1"); - Member member = memberRepository.findByHandleWithoutLogin("member2"); + Member owner = memberRepository.findByHandleWithoutLogin("owner"); + Member member = memberRepository.findByHandleWithoutLogin("tagged_member1"); Page tag = tagRepository.findTagByOwnerAndMember(owner, member, PageRequest.of(0, 1)); Long count = tagRepository.countByPost_PostStatusAndPost_OwnerAndMember(PostStatus.PUBLIC, owner, member); From bc2b9ec45ba295e23546959c828e247b4d57d6d0 Mon Sep 17 00:00:00 2001 From: Lucy Oh <56earls@gmail.com> Date: Tue, 1 Oct 2024 00:03:32 +0900 Subject: [PATCH 16/16] =?UTF-8?q?Fix:=20ARG,=20ENV=20=EC=84=B8=ED=8C=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20#46?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5a598cf3..7c6eb89b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM openjdk:17-jdk WORKDIR /app COPY build/libs/*.jar app.jar EXPOSE 3000 -ENV SPRING_PROFILES_ACTIVE=DEV +ARG SPRING_PROFILES_ACTIVE +ENV SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-DEV} CMD java -jar -Duser.timezone=Asia/Seoul app.jar