From dae472e7045016b641ef429df814a542e9620419 Mon Sep 17 00:00:00 2001 From: KimChanJin97 Date: Sat, 12 Oct 2024 22:52:18 +0900 Subject: [PATCH] =?UTF-8?q?Test:=20=20=EC=B9=B4=ED=94=84=EC=B9=B4=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80(=ED=81=B4=EB=A6=AD)=EC=97=90=20uuid?= =?UTF-8?q?=20=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/click/KafkaMockTest.java | 30 +++++++++++++++---- .../service/click/MysqlIntegrationTest.java | 16 +++++----- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/test/java/cjkimhello97/toy/crashMyServer/service/click/KafkaMockTest.java b/src/test/java/cjkimhello97/toy/crashMyServer/service/click/KafkaMockTest.java index f702c68..a4b07e1 100644 --- a/src/test/java/cjkimhello97/toy/crashMyServer/service/click/KafkaMockTest.java +++ b/src/test/java/cjkimhello97/toy/crashMyServer/service/click/KafkaMockTest.java @@ -1,5 +1,7 @@ package cjkimhello97.toy.crashMyServer.service.click; +import static org.junit.jupiter.api.Assertions.*; + import cjkimhello97.toy.crashMyServer.IntegrationTest; import cjkimhello97.toy.crashMyServer.auth.infrastructure.JwtProvider; import cjkimhello97.toy.crashMyServer.auth.service.AuthService; @@ -14,6 +16,9 @@ import cjkimhello97.toy.crashMyServer.member.repository.MemberRepository; import cjkimhello97.toy.crashMyServer.service.auth.testdata.AuthServiceTestDataBuilder; import cjkimhello97.toy.crashMyServer.service.click.testdata.ClickServiceFixtureObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Assertions; @@ -107,8 +112,13 @@ void beforeEach() { Mockito.when(clickRepository.findByMemberMemberId(memberB.getMemberId())) .thenReturn(Optional.of(clickOfB)); + List clicks = new ArrayList<>(); + clicks.add(clickOfA); + clicks.add(clickOfB); + Collections.sort(clicks); + Mockito.when(clickRepository.findTop10ClicksByCountDesc(PageRequest.of(0, 10))) - .thenReturn(List.of(clickOfA, clickOfB)); + .thenReturn(clicks); } @Test @@ -125,8 +135,10 @@ void beforeEach() { ArgumentCaptor clickRequestCaptor = ArgumentCaptor.forClass(KafkaClickRequest.class); Mockito.verify(kafkaClickRequestKafkaTemplate).send(clickTopicCaptor.capture(), clickRequestCaptor.capture()); - Assertions.assertEquals("click", clickTopicCaptor.getValue()); - Assertions.assertEquals(kafkaClickRequest, clickRequestCaptor.getValue()); + assertEquals("click", clickTopicCaptor.getValue()); + + assertEquals(kafkaClickRequest.getNickname(), clickRequestCaptor.getValue().getNickname()); + assertEquals(kafkaClickRequest.getCount(), clickRequestCaptor.getValue().getCount()); } @Test @@ -143,7 +155,15 @@ void beforeEach() { ArgumentCaptor clickRankRequestCaptor = ArgumentCaptor.forClass(KafkaClickRankRequest.class); Mockito.verify(kafkaClickRankRequestKafkaTemplate).send(clickRankTopicCaptor.capture(), clickRankRequestCaptor.capture()); - Assertions.assertEquals("click-rank", clickRankTopicCaptor.getValue()); - Assertions.assertEquals(kafkaClickRankRequest, clickRankRequestCaptor.getValue()); + assertEquals("click-rank", clickRankTopicCaptor.getValue()); + + assertEquals( + kafkaClickRankRequest.getClickRank().get(memberA.getNickname()), + clickRankRequestCaptor.getValue().getClickRank().get(memberA.getNickname()) + ); + assertEquals( + kafkaClickRankRequest.getClickRank().get(memberB.getNickname()), + clickRankRequestCaptor.getValue().getClickRank().get(memberB.getNickname()) + ); } } \ No newline at end of file diff --git a/src/test/java/cjkimhello97/toy/crashMyServer/service/click/MysqlIntegrationTest.java b/src/test/java/cjkimhello97/toy/crashMyServer/service/click/MysqlIntegrationTest.java index e3cf7c1..0fba876 100644 --- a/src/test/java/cjkimhello97/toy/crashMyServer/service/click/MysqlIntegrationTest.java +++ b/src/test/java/cjkimhello97/toy/crashMyServer/service/click/MysqlIntegrationTest.java @@ -68,7 +68,7 @@ void beforeEach() { @Test @DisplayName("[ CLICK ] MYSQL TEST 2") void 클릭하면_그에_따라_클릭_랭킹이_업데이트된다() { - // given & when: A가 한번 클릭 + // given & when: A가 1번 클릭 clickService.click(memberA.getMemberId()); Click clickOfA = clickService.getTopTenClicks().get(0); // 내림차순 정렬이므로 A가 1등 @@ -79,13 +79,13 @@ void beforeEach() { Member memberB = clickOfB.getMember(); Double countOfB = clickOfB.getCount(); - // then: 총 클릭을 1번한 A가 1등, 총 클릭을 0번한 B가 2등이다 + // then: 총 클릭을 1번한 A가 클릭 횟수 2회로 1등, 총 클릭을 0번한 클릭 횟수 1회로 B가 2등이다 Assertions.assertEquals(this.memberA, memberA); - Assertions.assertEquals(countOfA, 1D); + Assertions.assertEquals(countOfA, 2D); Assertions.assertEquals(this.memberB, memberB); - Assertions.assertEquals(countOfB, 0D); + Assertions.assertEquals(countOfB, 1D); - // given & when: B가 두번 클릭 + // given & when: B가 2번 클릭 clickService.click(this.memberB.getMemberId()); clickService.click(this.memberB.getMemberId()); @@ -97,10 +97,10 @@ void beforeEach() { memberA = clickOfA.getMember(); countOfA = clickOfA.getCount(); - // then: 총 클릭을 2번한 B가 1등, 총 클릭을 1번한 A가 2등이다 + // then: 총 클릭을 2번한 B가 클릭 횟수 3회로 1등, 총 클릭을 1번한 클릭 횟수 2회로 A가 2등이다 Assertions.assertEquals(this.memberB, memberB); - Assertions.assertEquals(countOfB, 2D); + Assertions.assertEquals(countOfB, 3D); Assertions.assertEquals(this.memberA, memberA); - Assertions.assertEquals(countOfA, 1D); + Assertions.assertEquals(countOfA, 2D); } } \ No newline at end of file