|
| 1 | +package com.example.solidconnection.database; |
| 2 | + |
| 3 | +import com.example.solidconnection.support.RedisTestContainer; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.springframework.boot.test.context.SpringBootTest; |
| 6 | +import org.springframework.boot.test.util.TestPropertyValues; |
| 7 | +import org.springframework.context.ApplicationContextInitializer; |
| 8 | +import org.springframework.context.ConfigurableApplicationContext; |
| 9 | +import org.springframework.test.context.ContextConfiguration; |
| 10 | +import org.springframework.test.context.TestPropertySource; |
| 11 | +import org.testcontainers.containers.MySQLContainer; |
| 12 | + |
| 13 | +@SpringBootTest |
| 14 | +@ContextConfiguration(initializers = {RedisTestContainer.class, FlywayMigrationTest.FlywayMySQLInitializer.class}) |
| 15 | +@TestPropertySource(properties = { |
| 16 | + "spring.flyway.enabled=true", |
| 17 | + "spring.flyway.baseline-on-migrate=true", |
| 18 | + "spring.jpa.hibernate.ddl-auto=validate" |
| 19 | +}) |
| 20 | +class FlywayMigrationTest { |
| 21 | + |
| 22 | + private static final MySQLContainer<?> CONTAINER = new MySQLContainer<>("mysql:8.0") |
| 23 | + .withDatabaseName("flyway_test") |
| 24 | + .withUsername("flyway_user") |
| 25 | + .withPassword("flyway_password"); |
| 26 | + |
| 27 | + static { |
| 28 | + CONTAINER.start(); |
| 29 | + } |
| 30 | + |
| 31 | + static class FlywayMySQLInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { |
| 32 | + @Override |
| 33 | + public void initialize(ConfigurableApplicationContext applicationContext) { |
| 34 | + TestPropertyValues.of( |
| 35 | + "spring.datasource.url=" + CONTAINER.getJdbcUrl(), |
| 36 | + "spring.datasource.username=" + CONTAINER.getUsername(), |
| 37 | + "spring.datasource.password=" + CONTAINER.getPassword() |
| 38 | + ).applyTo(applicationContext.getEnvironment()); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void flyway_스크립트가_정상적으로_수행되는지_확인한다() { |
| 44 | + // Spring Boot 컨텍스트가 정상적으로 시작되면 |
| 45 | + // Flyway 마이그레이션과 ddl-auto=validate 검증이 성공한 것 |
| 46 | + } |
| 47 | +} |
0 commit comments