-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] native query count가 제대로 동작하는지 확인(#40)
- Loading branch information
Showing
5 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/main/java/hyundai/softeer/orange/comment/dto/WriteCommentCountDto.java
This file contains 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,6 @@ | ||
package hyundai.softeer.orange.comment.dto; | ||
|
||
public interface WriteCommentCountDto { | ||
Long getEventUserId(); | ||
Long getCount(); | ||
} |
This file contains 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
This file contains 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,26 @@ | ||
INSERT INTO event_frame(name) VALUES ('test1'); | ||
INSERT INTO event_frame(name) VALUES ('test2'); | ||
|
||
INSERT INTO event_metadata(event_type, event_frame_id, event_id) VALUES (1, 1, 'HD_240808_001'); | ||
INSERT INTO event_metadata(event_type, event_frame_id, event_id) VALUES (0, 2, 'HD_240808_002'); | ||
|
||
INSERT INTO event_user(score, event_frame_id, user_id) VALUES (0, 1, 'user1'); | ||
INSERT INTO event_user(score, event_frame_id, user_id) VALUES (0, 1, 'user2'); | ||
INSERT INTO event_user(score, event_frame_id, user_id) VALUES (0, 1, 'user3'); | ||
|
||
-- 3 comments for user1 | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 1); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 1); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 1); | ||
|
||
-- 6 comments for user2 | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 2); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 2); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 2); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 2); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 2); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 2); | ||
|
||
-- 2 comments for user3 | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 3); | ||
INSERT INTO comment(event_frame_id, event_user_id) VALUES (1, 3); |
52 changes: 52 additions & 0 deletions
52
src/test/java/hyundai/softeer/orange/comment/repository/CommentRepositoryTest.java
This file contains 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,52 @@ | ||
package hyundai.softeer.orange.comment.repository; | ||
|
||
import hyundai.softeer.orange.comment.dto.WriteCommentCountDto; | ||
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.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
// 매 테스트마다 초기화하는 코드 찾아봐야 할듯? | ||
@Sql(value = "classpath:sql/CommentRepositoryTest.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) | ||
@DataJpaTest(showSql = false) | ||
@TestPropertySource(locations = "classpath:application-test.yml") | ||
class CommentRepositoryTest { | ||
@Autowired | ||
JdbcTemplate jdbcTemplate; | ||
|
||
@Autowired | ||
CommentRepository commentRepository; | ||
|
||
|
||
@DisplayName("존재하는 대상 이벤트에 대해 작성된 댓글이 있다면 유저 별로 개수를 구해 반환") | ||
@Test | ||
void getCountOfCommentPerUserIfCommentExist() { | ||
List<WriteCommentCountDto> counts = commentRepository.countPerEventUserByEventId(1L); | ||
|
||
assertThat(counts).hasSize(3); | ||
assertThat(counts.get(0).getCount()).isEqualTo(3); | ||
assertThat(counts.get(1).getCount()).isEqualTo(6); | ||
assertThat(counts.get(2).getCount()).isEqualTo(2); | ||
} | ||
|
||
@DisplayName("존재하지 않는 대상 이벤트는 빈 배열 반환") | ||
@Test | ||
void getCountOfCommentPerUserIfEventNotExist() { | ||
List<WriteCommentCountDto> counts = commentRepository.countPerEventUserByEventId(3L); | ||
assertThat(counts).hasSize(0); | ||
} | ||
|
||
@DisplayName("존재해도 댓글 없으면 빈 배열 반환") | ||
@Test | ||
void getCountOfCommentPerUserIfEventExistButNoComment() { | ||
List<WriteCommentCountDto> counts = commentRepository.countPerEventUserByEventId(2L); | ||
assertThat(counts).hasSize(0); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
.../java/hyundai/softeer/orange/event/draw/component/picker/AccSumBasedWinnerPickerTest.java
This file contains 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