refactor: 테스트 GWT로 통일해서 사용할 수 있도록 구성 및 서브에이전트 파일 수정
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.study.course_registration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
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.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.postgresql.PostgreSQLContainer;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import com.study.course_registration.support.Scenario;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("prod")
|
||||
@Testcontainers
|
||||
class ProdProfileContextTest {
|
||||
private static final PostgreSQLContainer POSTGRES =
|
||||
new PostgreSQLContainer(DockerImageName.parse("postgres:16-alpine"));
|
||||
|
||||
static {
|
||||
POSTGRES.start();
|
||||
}
|
||||
|
||||
@DynamicPropertySource
|
||||
static void database(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.datasource.url", POSTGRES::getJdbcUrl);
|
||||
registry.add("spring.datasource.username", POSTGRES::getUsername);
|
||||
registry.add("spring.datasource.password", POSTGRES::getPassword);
|
||||
registry.add("server.address", () -> "127.0.0.1");
|
||||
}
|
||||
|
||||
@Autowired DataSource dataSource;
|
||||
|
||||
@Test
|
||||
@DisplayName("prod profile → 빈 PostgreSQL에 Flyway 적용 후 context 기동")
|
||||
void prodBootsWithFlyway() throws Exception {
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
Scenario.given(connection)
|
||||
.when(ProdProfileContextTest::isValid)
|
||||
.then(valid -> assertThat(valid).isTrue());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValid(Connection connection) {
|
||||
try {
|
||||
return connection.isValid(1);
|
||||
} catch (SQLException exception) {
|
||||
throw new IllegalStateException("PostgreSQL connection validation failed", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user