DatabaseKontainer
annotation class DatabaseKontainer(value: KClass<out JdbcKontainer>, propertySuppliers: Array<KClass<out PropertySupplier>>, useDefaultPropertySuppliers: Boolean)
Content copied to clipboard
Annotation indicating the JUnit test suite should be extended with the DatabaseKontainerExtension JUnit Jupiter Extension.
Author
Scott Rossillo
Samples
import io.microkt.example.app.KontainersDemoApplication
import io.microkt.example.app.domain.Animal
import io.microkt.example.app.repository.ReactiveAnimalRepository
import io.microkt.kontainers.junit5.annotation.DatabaseKontainer
import io.microkt.kontainers.junit5.annotation.Kontainer
import io.microkt.kontainers.postgresql.PostgresKontainer
import io.microkt.kontainers.redis.RedisKontainer
import io.microkt.kontainers.redis.spring.SpringBootRedisPropertySupplier
import kotlinx.coroutines.reactive.awaitFirst
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Tags
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate
import org.springframework.data.r2dbc.core.awaitFirst
import org.springframework.data.r2dbc.core.select
import org.springframework.data.relational.core.query.Criteria.where
import org.springframework.data.relational.core.query.Query.query
fun main() {
//sampleStart
@Tags(
Tag("docker"),
Tag("kubernetes")
)
@SpringBootTest(classes = [KontainersDemoApplication::class])
@DatabaseKontainer(PostgresKontainer::class)
@Kontainer(RedisKontainer::class, propertySuppliers = [SpringBootRedisPropertySupplier::class])
class KontainersDemoApplicationTests {
@Autowired
private lateinit var template: R2dbcEntityTemplate
@Autowired
private lateinit var animalRepository: ReactiveAnimalRepository
@Test
fun contextLoads() {
runBlocking {
val animal = template.select<Animal>()
.matching(query(where("name").`is`("cat")))
.awaitFirst()
assertEquals("cat", animal.name)
assertEquals("dog", animalRepository.findByName("dog").awaitFirst().name)
}
}
}
//sampleEnd
}See also
Constructors
Link copied to clipboard
fun DatabaseKontainer(value: KClass<out JdbcKontainer>, propertySuppliers: Array<KClass<out PropertySupplier>> = [], useDefaultPropertySuppliers: Boolean = true)
Content copied to clipboard
Properties
Link copied to clipboard
Custom PropertySuppliers to configure the integration test environment.
Link copied to clipboard
True to register properties from any PropertySuppliers on the classpath; false otherwise.
Link copied to clipboard
The JdbcKontainer to make available for integration testing.