36 lines
868 B
Kotlin
36 lines
868 B
Kotlin
package be.simplenotes.persistence
|
|
|
|
import be.simplenotes.config.DataSourceConfig
|
|
import io.micronaut.context.BeanContext
|
|
import org.flywaydb.core.Flyway
|
|
import org.junit.jupiter.api.BeforeAll
|
|
import org.junit.jupiter.api.BeforeEach
|
|
import javax.sql.DataSource
|
|
|
|
abstract class DbTest {
|
|
|
|
abstract fun dataSourceConfig(): DataSourceConfig
|
|
|
|
val beanContext = BeanContext.build()
|
|
|
|
inline fun <reified T> BeanContext.getBean(): T = getBean(T::class.java)
|
|
|
|
@BeforeAll
|
|
fun setComponent() {
|
|
beanContext.registerSingleton(dataSourceConfig())
|
|
}
|
|
|
|
@BeforeEach
|
|
fun beforeEach() {
|
|
val migration = beanContext.getBean<DbMigrations>()
|
|
val dataSource = beanContext.getBean<DataSource>()
|
|
|
|
Flyway.configure()
|
|
.dataSource(dataSource)
|
|
.load()
|
|
.clean()
|
|
|
|
migration.migrate()
|
|
}
|
|
}
|