fix(test): H2 수명과 컨텍스트 격리를 정리해 테스트 자원 누적을 줄인다

This commit is contained in:
2026-11-19 14:20:21 +09:00
parent 6e14c38915
commit 1c270048a1
36 changed files with 192 additions and 39 deletions
@@ -25,7 +25,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:admin-chat-banner-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -47,7 +47,7 @@ import javax.persistence.EntityManager
"cloud.aws.cloud-front.host=https://cdn.test",
"cloud.aws.s3.bucket=test-bucket",
"spring.datasource.url=jdbc:h2:mem:admin-content-banner-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -26,7 +26,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:admin-series-banner-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -38,7 +38,7 @@ import java.time.LocalDateTime
"cloud.aws.cloud-front.host=https://cdn.test",
"cloud.aws.s3.bucket=test-bucket",
"spring.datasource.url=jdbc:h2:mem:admin-event-banner-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -25,7 +25,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:admin-live-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -21,7 +21,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:admin-live-service-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -58,7 +58,7 @@ import javax.persistence.EntityManager
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:charge-controller-http;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE",
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE",
"jwt.secret=MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1Njc4OWFiY2RlZg==",
"apple.iap-verify-url=https://apple.invalid/verifyReceipt",
"apple.iap-verify-sandbox-url=https://apple-sandbox.invalid/verifyReceipt",
@@ -58,7 +58,7 @@ import javax.persistence.EntityManager
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:charge-service-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE",
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE",
"apple.iap-verify-url=https://apple.invalid/verifyReceipt",
"apple.iap-verify-sandbox-url=https://apple-sandbox.invalid/verifyReceipt",
"payverse.host=https://payverse.invalid",
@@ -21,7 +21,7 @@ import javax.persistence.EntityManager
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:can-coupon-service-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -23,7 +23,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:chat-banner-service-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -31,7 +31,7 @@ import java.time.LocalDateTime
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = [
"spring.datasource.url=jdbc:h2:mem:notice-home-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@Import(AudioContentMainTabHomeServiceIntegrationTest.TimeConfiguration::class)
@@ -6,13 +6,13 @@ import kr.co.vividnext.sodalive.i18n.Lang
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.MemberRole
import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.domain.PageRequest
import org.springframework.test.annotation.DirtiesContext
import org.springframework.test.context.ContextConfiguration
import org.springframework.transaction.support.TransactionTemplate
import javax.persistence.EntityManager
@@ -21,16 +21,24 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:series-banner-service-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class ContentSeriesBannerServiceIntegrationTest @Autowired constructor(
private val service: ContentSeriesBannerService,
private val entityManager: EntityManager,
private val transactionTemplate: TransactionTemplate
) {
@AfterEach
fun removeFixtures() {
transactionTemplate.executeWithoutResult {
listOf("series_banner", "series", "series_genre", "member").forEach { table ->
entityManager.createNativeQuery("delete from $table").executeUpdate()
}
}
}
@Test
@DisplayName("OSIV off 환경에서 관리자 시리즈 배너 목록 응답 생성 시 lazy 초기화 예외가 발생하지 않는다")
fun shouldCreateAdminSeriesBannerListResponseWhenOpenInViewIsDisabled() {
@@ -19,7 +19,7 @@ import org.springframework.test.context.ContextConfiguration
"deployment.artifact-version=1.2.3-20260914",
"deployment.config-commit=1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d",
"spring.datasource.url=jdbc:h2:mem:deployment-endpoint-injected-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -20,7 +20,7 @@ import org.springframework.test.context.ContextConfiguration
properties = [
"management.server.port=0",
"spring.datasource.url=jdbc:h2:mem:deployment-endpoint-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -35,7 +35,7 @@ import java.time.LocalDateTime
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:event-banner-language-http;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -33,7 +33,7 @@ import java.time.LocalDateTime
"cloud.aws.cloud-front.host=https://cdn.test",
"cloud.aws.s3.bucket=test-bucket",
"spring.datasource.url=jdbc:h2:mem:event-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -0,0 +1,41 @@
package kr.co.vividnext.sodalive.i18n.translation
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.springframework.test.annotation.DirtiesContext.HierarchyMode
import org.springframework.test.context.TestContextManager
class MetadataReadRetryContextIsolationTest {
@Test
@DisplayName("커뮤니티 테스트 context 생성과 종료는 원작 테스트 DB의 작업을 지우지 않는다")
fun shouldPreserveOriginalWorkJobsWhenCommunityContextCloses() {
val original = TestContextManager(OriginalWorkReadRetryTest::class.java).testContext
val community = TestContextManager(CreatorCommunityReadRetryTest::class.java).testContext
try {
val jobs = original.applicationContext.getBean(TranslationJobRepository::class.java)
val job = jobs.saveAndFlush(
TranslationJob(
resourceType = LanguageTranslationTargetType.ORIGINAL_WORK,
resourceId = 10L,
fieldKey = "title",
sourceHash = SourceTextNormalizer.hash("격리된 원작 제목"),
sourceText = "격리된 원작 제목",
sourceLanguage = "ko",
targetLanguage = "en"
)
)
try {
community.applicationContext.getBean(TranslationJobRepository::class.java)
} finally {
community.markApplicationContextDirty(HierarchyMode.CURRENT_LEVEL)
}
val preserved = jobs.findById(requireNotNull(job.id)).orElseThrow()
assertEquals("격리된 원작 제목", preserved.sourceText)
assertEquals(TranslationJobStatus.PENDING, preserved.status)
} finally {
original.markApplicationContextDirty(HierarchyMode.CURRENT_LEVEL)
}
}
}
@@ -23,7 +23,8 @@ import javax.persistence.EntityManager
@DataJpaTest(
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:metadata-read-retry;MODE=MySQL;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE"
"spring.datasource.url=jdbc:h2:mem:metadata-read-retry-\${random.uuid};" +
"MODE=MySQL;NON_KEYWORDS=VALUE;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@@ -36,7 +36,7 @@ import javax.persistence.EntityManager
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:live-reservation-service-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -36,7 +36,7 @@ import javax.persistence.LockModeType
properties = [
"spring.datasource.url=jdbc:h2:mem:notice-concurrency;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;" +
"DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=15000"
"DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=15000"
]
)
@Import(ServiceNoticeConcurrencyIntegrationTest.TimeConfiguration::class)
@@ -29,7 +29,7 @@ import javax.persistence.EntityManager
@SpringBootTest(
properties = [
"spring.datasource.url=jdbc:h2:mem:notice-query-repository;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@Import(ServiceNoticeQueryRepositoryTest.TimeConfiguration::class)
@@ -0,0 +1,61 @@
package kr.co.vividnext.sodalive.support
import com.zaxxer.hikari.HikariDataSource
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.springframework.boot.autoconfigure.AutoConfigurations
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.env.RandomValuePropertySource
import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer
import org.springframework.boot.test.context.runner.ApplicationContextRunner
import java.sql.DriverManager
import java.sql.SQLException
class H2DatabaseLifecycleTest {
@Test
@DisplayName("공용 테스트 H2는 풀 연결 사이에서 데이터를 공유하고 컨텍스트 종료 시 제거된다")
fun shouldShareDataAcrossPooledConnectionsAndRemoveDatabaseWhenContextCloses() {
lateinit var dataSource: HikariDataSource
ApplicationContextRunner()
.withInitializer { context ->
RandomValuePropertySource.addToEnvironment(context.environment)
ConfigDataApplicationContextInitializer().initialize(context)
}
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration::class.java))
.run { context ->
assertNull(context.startupFailure)
dataSource = context.getBean(HikariDataSource::class.java)
dataSource.connection.use { first ->
first.createStatement().use { statement ->
statement.execute("CREATE TABLE lifecycle_marker (id INTEGER PRIMARY KEY)")
statement.executeUpdate("INSERT INTO lifecycle_marker (id) VALUES (1)")
}
dataSource.connection.use { second ->
second.createStatement().use { statement ->
statement.executeQuery("SELECT id FROM lifecycle_marker").use { rows ->
assertTrue(rows.next())
assertEquals(1, rows.getInt(1))
}
}
}
}
}
assertTrue(dataSource.isClosed)
val failure = assertThrows(SQLException::class.java) {
DriverManager.getConnection(
"${dataSource.jdbcUrl};IFEXISTS=TRUE",
dataSource.username,
dataSource.password
).use { connection ->
// Release a surviving database before the lifecycle assertion fails.
connection.createStatement().use { it.execute("SHUTDOWN") }
}
}
assertEquals(90146, failure.errorCode)
}
}
@@ -112,7 +112,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:gift-admin-controller;MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;" +
"DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -53,7 +53,7 @@ import javax.persistence.EntityManager
properties = [
"jwt.secret=MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWYwMTIzNDU2Nzg5YWJjZGVmMDEyMzQ1Njc4OWFiY2RlZg==",
"spring.datasource.url=jdbc:h2:mem:admin-notice-http;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@Import(AdminNoticeControllerIntegrationTest.TimeConfiguration::class)
@@ -13,6 +13,7 @@ import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer
import org.hamcrest.Matchers.contains
import org.hamcrest.Matchers.nullValue
import org.hibernate.SessionFactory
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
@@ -20,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.test.annotation.DirtiesContext
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -40,13 +40,28 @@ import javax.persistence.EntityManager
)
@AutoConfigureMockMvc
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class MainContentAllEndToEndTest @Autowired constructor(
private val mockMvc: MockMvc,
private val entityManager: EntityManager,
private val transactionTemplate: TransactionTemplate,
private val jdbcTemplate: JdbcTemplate
) {
@AfterEach
fun removeFixtures() {
transactionTemplate.executeWithoutResult {
listOf(
"orders",
"creator_localized_name",
"series_published_days_of_week",
"series",
"content",
"series_genre",
"content_theme",
"member"
).forEach { table -> jdbcTemplate.update("delete from $table") }
}
}
@Test
@DisplayName("전체 콘텐츠 API는 JA 별칭을 우선하고 KO 별칭 미등록 시 일본어 원본을, 별칭 없는 작성자는 현재 원본을 반환한다")
fun shouldSelectLocalizedCreatorNamesWithoutChangingAudioTitles() {
@@ -10,13 +10,13 @@ import kr.co.vividnext.sodalive.member.MemberRole
import kr.co.vividnext.sodalive.support.EmbeddedRedisInitializer
import kr.co.vividnext.sodalive.v2.recommendation.adapter.out.persistence.RecommendationSnapshot
import kr.co.vividnext.sodalive.v2.recommendation.domain.RecommendedSectionType
import org.junit.jupiter.api.AfterEach
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.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user
import org.springframework.test.annotation.DirtiesContext
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -35,12 +35,27 @@ import javax.persistence.EntityManager
)
@AutoConfigureMockMvc
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class ContentOverviewEndToEndTest @Autowired constructor(
private val mockMvc: MockMvc,
private val entityManager: EntityManager,
private val transactionTemplate: TransactionTemplate
) {
@AfterEach
fun removeFixtures() {
transactionTemplate.executeWithoutResult {
listOf(
"content_translation",
"recommendation_snapshot",
"content",
"content_theme",
"member_content_preference",
"member"
).forEach { table ->
entityManager.createNativeQuery("delete from $table").executeUpdate()
}
}
}
@Test
@DisplayName("콘텐츠 전체보기 API는 비회원 요청을 거부한다")
fun shouldRejectAnonymousContentOverviewRequest() {
@@ -63,6 +78,7 @@ class ContentOverviewEndToEndTest @Autowired constructor(
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.data.type").value("NEW_AND_HOT_AUDIO"))
.andExpect(jsonPath("$.data.items.length()").value(1))
.andExpect(jsonPath("$.data.items[0].contentId").value(fixture.audioContentId))
.andExpect(jsonPath("$.data.items[0].title").value("content-overview-new-hot-audio"))
.andExpect(jsonPath("$.data.items[0].coverImage").value("https://cdn.test/content-overview-new-hot.png"))
@@ -86,6 +102,7 @@ class ContentOverviewEndToEndTest @Autowired constructor(
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.data.type").value("FIRST_AUDIO_CONTENT"))
.andExpect(jsonPath("$.data.items.length()").value(1))
.andExpect(jsonPath("$.data.items[0].contentId").value(fixture.audioContentId))
.andExpect(jsonPath("$.data.items[0].title").value("content-overview-first-audio"))
.andExpect(jsonPath("$.data.items[0].coverImage").value("https://cdn.test/content-overview-first.png"))
@@ -129,6 +146,7 @@ class ContentOverviewEndToEndTest @Autowired constructor(
.with(user(MemberAdapter(fixture.viewer)))
)
.andExpect(status().isOk)
.andExpect(jsonPath("$.data.items.length()").value(1))
.andExpect(jsonPath("$.data.items[0].contentId").value(fixture.audioContentId))
.andExpect(jsonPath("$.data.items[0].title").value(title))
}
@@ -148,6 +166,7 @@ class ContentOverviewEndToEndTest @Autowired constructor(
.andExpect(status().isOk)
.andExpect(jsonPath("$.success").value(true))
.andExpect(jsonPath("$.data.type").value("NEW_AND_HOT_AUDIO"))
.andExpect(jsonPath("$.data.items.length()").value(1))
.andExpect(jsonPath("$.data.items[0].contentId").value(fixture.audioContentId))
.andExpect(jsonPath("$.data.page").value(0))
.andExpect(jsonPath("$.data.size").value(20))
@@ -46,7 +46,7 @@ import java.time.LocalDateTime
"cloud.aws.cloud-front.host=https://cdn.test",
"cloud.aws.s3.bucket=test-bucket",
"spring.datasource.url=jdbc:h2:mem:event-detail-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -53,7 +53,7 @@ import java.time.LocalDateTime
@SpringBootTest(
properties = [
"spring.datasource.url=" +
"jdbc:h2:mem:gift-controller;MODE=MySQL;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE",
"jdbc:h2:mem:gift-controller;MODE=MySQL;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE",
"cloud.aws.cloud-front.host=https://cdn.test"
]
)
@@ -30,7 +30,7 @@ import javax.persistence.EntityManager
properties = [
"cloud.aws.cloud-front.host=https://cdn.test",
"spring.datasource.url=jdbc:h2:mem:creator-ranking-controller;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@AutoConfigureMockMvc
@@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicInteger
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = [
"spring.datasource.url=jdbc:h2:mem:latest-notice-controller-integration;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -31,7 +31,7 @@ import javax.persistence.EntityManager
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:creator-ranking-aggregation;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@Import(QueryDslConfig::class, DefaultCreatorRankingAggregationRepository::class)
@@ -17,7 +17,7 @@ import java.time.LocalDateTime
properties = [
"spring.cache.type=none",
"spring.datasource.url=jdbc:h2:mem:creator-ranking-snapshot;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@Import(QueryDslConfig::class, DefaultCreatorRankingSnapshotRepository::class)
@@ -58,7 +58,7 @@ import javax.persistence.EntityManager
"cloud.aws.cloud-front.host=https://cdn.test",
"cloud.aws.s3.bucket=test-bucket",
"spring.datasource.url=jdbc:h2:mem:admin-sub-banner-http;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])
@@ -62,7 +62,7 @@ import javax.persistence.EntityManager
"cloud.aws.cloud-front.host=https://cdn.test",
"cloud.aws.s3.bucket=test-bucket",
"spring.datasource.url=jdbc:h2:mem:public-sub-banner-http;" +
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"
"MODE=MySQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=VALUE;DB_CLOSE_DELAY=0;DB_CLOSE_ON_EXIT=FALSE"
]
)
@ContextConfiguration(initializers = [EmbeddedRedisInitializer::class])