From 7fa872b3f75298f06b2a9df54ba5a50e34888e92 Mon Sep 17 00:00:00 2001 From: shin-jisong <86762272+shin-jisong@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:29:21 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EC=BA=90=EC=8B=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A7=88=EB=8B=A4=20=EB=B9=84=EC=9A=B0=EA=B8=B0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: jinwoo22 <98975580+JINU-CHANG@users.noreply.github.com> --- .../com/bang_ggood/IntegrationTestSupport.java | 17 +++++++++++++++++ .../java/com/bang_ggood/JpaAuditingTest.java | 2 +- .../article/service/ArticleServiceTest.java | 6 +++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/IntegrationTestSupport.java b/backend/bang-ggood/src/test/java/com/bang_ggood/IntegrationTestSupport.java index 446b4a654..93dd76538 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/IntegrationTestSupport.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/IntegrationTestSupport.java @@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.jdbc.Sql; @@ -27,10 +29,25 @@ public abstract class IntegrationTestSupport { @Autowired UserRepository userRepository; + @Autowired + private CacheManager cacheManager; + @BeforeEach void init() { UserFixture.init(userRepository); QuestionFixture.init(categoryRepository, questionRepository); CustomChecklistFixture.init(); + clearCaches(); + } + + void clearCaches() { + if (cacheManager != null) { + cacheManager.getCacheNames().forEach(name -> { + Cache cache = cacheManager.getCache(name); + if (cache != null) { + cache.clear(); + } + }); + } } } diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/JpaAuditingTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/JpaAuditingTest.java index 0fa721a46..501852998 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/JpaAuditingTest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/JpaAuditingTest.java @@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -class JpaAuditingTest extends IntegrationTestSupport { +class JpaAuditingTest extends IntegrationTestSupport { @Autowired private TestRepository testRepository; diff --git a/backend/bang-ggood/src/test/java/com/bang_ggood/article/service/ArticleServiceTest.java b/backend/bang-ggood/src/test/java/com/bang_ggood/article/service/ArticleServiceTest.java index dd8122362..af645d2fa 100644 --- a/backend/bang-ggood/src/test/java/com/bang_ggood/article/service/ArticleServiceTest.java +++ b/backend/bang-ggood/src/test/java/com/bang_ggood/article/service/ArticleServiceTest.java @@ -84,13 +84,13 @@ void readArticles() { @Test void deleteArticle() { // given - articleRepository.save(ArticleFixture.ARTICLE()); + Article article = articleRepository.save(ArticleFixture.ARTICLE()); // when - articleService.deleteArticle(ArticleFixture.ARTICLE().getId()); + articleService.deleteArticle(article.getId()); //then - assertThatThrownBy(() -> articleService.readArticle(ArticleFixture.ARTICLE().getId())) + assertThatThrownBy(() -> articleService.readArticle(article.getId())) .isInstanceOf(BangggoodException.class) .hasMessage(ExceptionCode.ARTICLE_NOT_FOUND.getMessage()); }