-
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.
- Loading branch information
1 parent
29e4d83
commit 08cd837
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
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
21 changes: 21 additions & 0 deletions
21
...main/java/com/mallang/statistics/statistic/application/PostViewStatisticEventHandler.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,21 @@ | ||
package com.mallang.statistics.statistic.application; | ||
|
||
import com.mallang.post.domain.PostDeleteEvent; | ||
import com.mallang.statistics.statistic.PostViewStatisticRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class PostViewStatisticEventHandler { | ||
|
||
private final PostViewStatisticRepository postViewStatisticRepository; | ||
|
||
@EventListener(PostDeleteEvent.class) | ||
void deletePostViewStatistic(PostDeleteEvent event) { | ||
postViewStatisticRepository.deleteAllByPostId(event.postId()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../java/com/mallang/statistics/statistic/application/PostViewStatisticEventHandlerTest.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,39 @@ | ||
package com.mallang.statistics.statistic.application; | ||
|
||
import static org.mockito.BDDMockito.then; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
|
||
import com.mallang.post.domain.PostDeleteEvent; | ||
import com.mallang.post.domain.PostId; | ||
import com.mallang.statistics.statistic.PostViewStatisticRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayName("포스트 조회 통계 이벤트 핸들러 (PostViewStatisticEventHandler) 은(는)") | ||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
class PostViewStatisticEventHandlerTest { | ||
|
||
private final PostViewStatisticRepository postViewStatisticRepository = mock(PostViewStatisticRepository.class); | ||
private final PostViewStatisticEventHandler postViewStatisticEventHandler = new PostViewStatisticEventHandler( | ||
postViewStatisticRepository | ||
); | ||
|
||
@Test | ||
void 포스트_제거_이벤트를_받아_해당_포스트의_조회_이력을_제거한다() { | ||
// given | ||
PostId postId = new PostId(1L, 1L); | ||
PostDeleteEvent postDeleteEvent = new PostDeleteEvent(postId); | ||
|
||
// when | ||
postViewStatisticEventHandler.deletePostViewStatistic(postDeleteEvent); | ||
|
||
// then | ||
then(postViewStatisticRepository) | ||
.should(times(1)) | ||
.deleteAllByPostId(postId); | ||
} | ||
} |