-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: 커뮤니티 관련 통합 테스트 데이터 fixture 메서드로 변경 #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Gyuhyeok99
merged 7 commits into
solid-connection:develop
from
Gyuhyeok99:refactor/332-community-test-fixture-module
Jun 18, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d2f32a8
feat: BoardFixture에 Board 생성 메서드 추가
Gyuhyeok99 bfee896
feat: PostFixture에 Post 생성 메서드 추가
Gyuhyeok99 6ce2ee9
feat: PostImageFixture에 PostImage 생성 메서드 추가
Gyuhyeok99 b14d582
feat: CommentFixture에 Comment 생성 메서드 추가
Gyuhyeok99 d01e41a
refactor: Community 관련 데이터 fixture 메서드로 변경
Gyuhyeok99 00ea711
refactor: BaseIntegrationTest 제거
Gyuhyeok99 6c344f8
refactor: BoardFixture에서 BoardCode enum 상수 일관되게 사용
Gyuhyeok99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/test/java/com/example/solidconnection/community/board/fixture/BoardFixture.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.example.solidconnection.community.board.fixture; | ||
|
|
||
| import com.example.solidconnection.community.board.domain.Board; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.test.context.TestComponent; | ||
|
|
||
| import static com.example.solidconnection.community.board.domain.BoardCode.AMERICAS; | ||
| import static com.example.solidconnection.community.board.domain.BoardCode.ASIA; | ||
| import static com.example.solidconnection.community.board.domain.BoardCode.EUROPE; | ||
| import static com.example.solidconnection.community.board.domain.BoardCode.FREE; | ||
|
|
||
| @TestComponent | ||
| @RequiredArgsConstructor | ||
| public class BoardFixture { | ||
|
|
||
| private final BoardFixtureBuilder boardFixtureBuilder; | ||
|
|
||
| public Board 미주권() { | ||
| return boardFixtureBuilder.code(AMERICAS.name()) | ||
| .koreanName("미주권") | ||
| .findOrCreate(); | ||
| } | ||
|
|
||
| public Board 아시아권() { | ||
| return boardFixtureBuilder.code(ASIA.name()) | ||
| .koreanName("아시아권") | ||
| .findOrCreate(); | ||
| } | ||
|
|
||
| public Board 유럽권() { | ||
| return boardFixtureBuilder.code(EUROPE.name()) | ||
| .koreanName("유럽권") | ||
| .findOrCreate(); | ||
| } | ||
|
|
||
| public Board 자유게시판() { | ||
| return boardFixtureBuilder.code(FREE.name()) | ||
| .koreanName("자유게시판") | ||
| .findOrCreate(); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/example/solidconnection/community/board/fixture/BoardFixtureBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.example.solidconnection.community.board.fixture; | ||
|
|
||
| import com.example.solidconnection.community.board.domain.Board; | ||
| import com.example.solidconnection.community.board.repository.BoardRepositoryForTest; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.test.context.TestComponent; | ||
|
|
||
| @TestComponent | ||
| @RequiredArgsConstructor | ||
| public class BoardFixtureBuilder { | ||
|
|
||
| private final BoardRepositoryForTest boardRepositoryForTest; | ||
|
|
||
| private String code; | ||
| private String koreanName; | ||
|
|
||
| public BoardFixtureBuilder code(String code) { | ||
| this.code = code; | ||
| return this; | ||
| } | ||
|
|
||
| public BoardFixtureBuilder koreanName(String koreanName) { | ||
| this.koreanName = koreanName; | ||
| return this; | ||
| } | ||
|
|
||
| public Board findOrCreate() { | ||
| return boardRepositoryForTest.findByCodeWithPosts(code) | ||
| .orElseGet(() -> boardRepositoryForTest.save(new Board(code, koreanName))); | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
...t/java/com/example/solidconnection/community/board/repository/BoardRepositoryForTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.solidconnection.community.board.repository; | ||
|
|
||
| import com.example.solidconnection.community.board.domain.Board; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface BoardRepositoryForTest extends JpaRepository<Board, Long> { | ||
|
|
||
| @Query("SELECT b FROM Board b LEFT JOIN FETCH b.postList WHERE b.code = :code") | ||
| Optional<Board> findByCodeWithPosts(@Param("code") String code); | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.example.solidconnection.community.comment.fixture; | ||
|
|
||
| import com.example.solidconnection.community.comment.domain.Comment; | ||
| import com.example.solidconnection.community.post.domain.Post; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.test.context.TestComponent; | ||
|
|
||
| @TestComponent | ||
| @RequiredArgsConstructor | ||
| public class CommentFixture { | ||
|
|
||
| private final CommentFixtureBuilder commentFixtureBuilder; | ||
|
|
||
| public Comment 부모_댓글(String content, Post post, SiteUser siteUser) { | ||
| return commentFixtureBuilder | ||
| .content(content) | ||
| .post(post) | ||
| .siteUser(siteUser) | ||
| .createParent(); | ||
| } | ||
|
|
||
| public Comment 자식_댓글( | ||
| String content, | ||
| Post post, | ||
| SiteUser siteUser, | ||
| Comment parentComment) { | ||
| return commentFixtureBuilder | ||
| .content(content) | ||
| .post(post) | ||
| .siteUser(siteUser) | ||
| .parentComment(parentComment) | ||
| .createChild(); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
...est/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.example.solidconnection.community.comment.fixture; | ||
|
|
||
| import com.example.solidconnection.community.comment.domain.Comment; | ||
| import com.example.solidconnection.community.comment.repository.CommentRepository; | ||
| import com.example.solidconnection.community.post.domain.Post; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.test.context.TestComponent; | ||
|
|
||
| @TestComponent | ||
| @RequiredArgsConstructor | ||
| public class CommentFixtureBuilder { | ||
|
|
||
| private final CommentRepository commentRepository; | ||
|
|
||
| private String content; | ||
| private Post post; | ||
| private SiteUser siteUser; | ||
| private Comment parentComment; | ||
|
|
||
| public CommentFixtureBuilder content(String content) { | ||
| this.content = content; | ||
| return this; | ||
| } | ||
Gyuhyeok99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public CommentFixtureBuilder post(Post post) { | ||
| this.post = post; | ||
| return this; | ||
| } | ||
|
|
||
| public CommentFixtureBuilder siteUser(SiteUser siteUser) { | ||
| this.siteUser = siteUser; | ||
| return this; | ||
| } | ||
|
|
||
| public CommentFixtureBuilder parentComment(Comment parentComment) { | ||
| this.parentComment = parentComment; | ||
| return this; | ||
| } | ||
|
|
||
| public Comment createParent() { | ||
| Comment comment = new Comment(content); | ||
| comment.setPostAndSiteUser(post, siteUser); | ||
| return commentRepository.save(comment); | ||
| } | ||
|
|
||
| public Comment createChild() { | ||
| Comment comment = new Comment(content); | ||
| comment.setPostAndSiteUser(post, siteUser); | ||
| comment.setParentCommentAndPostAndSiteUser(parentComment, post, siteUser); | ||
| return commentRepository.save(comment); | ||
| } | ||
Gyuhyeok99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.