From 470319220f7b92a263036f74736efcd4f6bd9a43 Mon Sep 17 00:00:00 2001 From: BaeJunho Date: Fri, 15 Nov 2024 16:34:05 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8E=99?= =?UTF-8?q?=ED=84=B0=EB=A7=81=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=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../video/application/VideoServiceTest.java | 19 +++++++++++++++++++ .../persistence/VideoRepositoryTest.java | 14 ++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/test/java/team7/inplace/video/application/VideoServiceTest.java b/src/test/java/team7/inplace/video/application/VideoServiceTest.java index 9d844d2c..84acfda7 100644 --- a/src/test/java/team7/inplace/video/application/VideoServiceTest.java +++ b/src/test/java/team7/inplace/video/application/VideoServiceTest.java @@ -1,6 +1,7 @@ package team7.inplace.video.application; import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -12,9 +13,14 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import team7.inplace.influencer.domain.Influencer; import team7.inplace.place.domain.Place; import team7.inplace.place.persistence.PlaceRepository; +import team7.inplace.security.application.dto.CustomOAuth2User; +import team7.inplace.user.domain.Role; import team7.inplace.util.TestUtil; import team7.inplace.video.application.dto.VideoInfo; import team7.inplace.video.domain.Video; @@ -38,10 +44,16 @@ public class VideoServiceTest { @InjectMocks private VideoService videoService; + @AfterEach + void tearDown() { + SecurityContextHolder.clearContext(); + } + @Test @DisplayName("getVideosBySurround Test") void test1() { // given + setUser(); // 매개변수 VideoSearchParams videoSearchParams = new VideoSearchParams( "10.0", @@ -296,4 +308,11 @@ void test5() { Assertions.assertThat(videoInfos.get(0).videoId()).isEqualTo(2L); Assertions.assertThat(videoInfos.get(1).videoId()).isEqualTo(1L); } + + private void setUser() { + CustomOAuth2User customOAuth2User = new CustomOAuth2User("test", 1L, Role.USER.getRoles()); + Authentication authentication = new UsernamePasswordAuthenticationToken(customOAuth2User, + null); + SecurityContextHolder.getContext().setAuthentication(authentication); + } } diff --git a/src/test/java/team7/inplace/video/persistence/VideoRepositoryTest.java b/src/test/java/team7/inplace/video/persistence/VideoRepositoryTest.java index e3c9e507..fedb2d7b 100644 --- a/src/test/java/team7/inplace/video/persistence/VideoRepositoryTest.java +++ b/src/test/java/team7/inplace/video/persistence/VideoRepositoryTest.java @@ -126,10 +126,10 @@ void test1() { ); // then Assertions.assertThat(savedVideos.size()).isEqualTo(5); - Long count = 1L; + Long count = 5L; for (Video savedVideo : savedVideos) { Assertions.assertThat(savedVideo.getId()).isEqualTo(count); - count = count + 1L; + count = count - 1L; } } @@ -148,10 +148,10 @@ void test1_1() { ); // then Assertions.assertThat(savedVideos.size()).isEqualTo(10); - Long count = 1L; + Long count = 11L; for (Video savedVideo : savedVideos) { Assertions.assertThat(savedVideo.getId()).isEqualTo(count); - count = count + 1L; + count = count - 1L; } } @@ -283,6 +283,12 @@ void test7() { // given // when + for (int i = 1; i <= 11; i++) { + Video video = videoRepository.findById((long) i) + .orElseThrow(() -> InplaceException.of(VideoErrorCode.NOT_FOUND)); + video.updateViewCount(1L); + } + for (int i = 1; i <= 11; i++) { Video video = videoRepository.findById((long) i) .orElseThrow(() -> InplaceException.of(VideoErrorCode.NOT_FOUND));