review fixes
This commit is contained in:
parent
d85b540132
commit
1dba5f72a0
|
|
@ -9,5 +9,5 @@ import ru.touchin.common.spring.test.annotations.SlowTest
|
|||
@ActiveProfiles("test", "test-slow")
|
||||
@SlowTest
|
||||
@DataJpaTest
|
||||
@Import(RepositoryTestConfig::class)
|
||||
@Import(RepositoryTestConfiguration::class)
|
||||
annotation class RepositoryTest
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ru.touchin.common.spring.test.jpa.repository
|
|||
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.boot.test.context.TestConfiguration
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
|
|
@ -15,12 +16,14 @@ import javax.sql.DataSource
|
|||
@TestConfiguration
|
||||
@EnableJpaAuditingExtra
|
||||
@ComponentScan
|
||||
class RepositoryTestConfig {
|
||||
class RepositoryTestConfiguration {
|
||||
|
||||
// запуск и остановка контейнера по lifecycle-событиями компонента (1)
|
||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||
fun jdbcDatabaseContainer(): JdbcDatabaseContainer<*> {
|
||||
return PostgreSQLContainer<Nothing>("postgres:12").apply {
|
||||
fun jdbcDatabaseContainer(
|
||||
@Value("\${tests.slow.db.container}") containerName: String,
|
||||
): JdbcDatabaseContainer<*> {
|
||||
return PostgreSQLContainer<Nothing>(containerName).apply {
|
||||
waitingFor(Wait.forListeningPort())
|
||||
}
|
||||
}
|
||||
|
|
@ -28,9 +31,13 @@ class RepositoryTestConfig {
|
|||
@Bean
|
||||
fun dataSource(jdbcDatabaseContainer: JdbcDatabaseContainer<*>): DataSource {
|
||||
val hikariConfig = HikariConfig()
|
||||
hikariConfig.jdbcUrl = jdbcDatabaseContainer.jdbcUrl
|
||||
hikariConfig.username = jdbcDatabaseContainer.username
|
||||
hikariConfig.password = jdbcDatabaseContainer.password
|
||||
.apply {
|
||||
jdbcUrl = jdbcDatabaseContainer.jdbcUrl
|
||||
username = jdbcDatabaseContainer.username
|
||||
password = jdbcDatabaseContainer.password
|
||||
}
|
||||
|
||||
return HikariDataSource(hikariConfig)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,5 +12,7 @@ spring:
|
|||
test:
|
||||
database:
|
||||
replace: none
|
||||
|
||||
|
||||
tests:
|
||||
slow:
|
||||
db:
|
||||
container: "postgres:12"
|
||||
|
|
|
|||
Loading…
Reference in New Issue