add kafka and postgres test container
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package ltd.hlaeja.test.container
|
||||
|
||||
import ltd.hlaeja.test.container.extension.KafkaPostgresTestExtension
|
||||
import ltd.hlaeja.test.container.postgres.PostgresTestListener
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.springframework.test.context.ContextConfiguration
|
||||
import org.springframework.test.context.TestExecutionListeners
|
||||
import org.springframework.test.context.TestExecutionListeners.MergeMode
|
||||
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@ExtendWith(KafkaPostgresTestExtension::class)
|
||||
@ContextConfiguration(initializers = [KafkaPostgresTestExtension::class])
|
||||
@TestExecutionListeners(
|
||||
listeners = [PostgresTestListener::class],
|
||||
mergeMode = MergeMode.MERGE_WITH_DEFAULTS,
|
||||
)
|
||||
annotation class KafkaPostgresTestContainer
|
||||
@@ -0,0 +1,27 @@
|
||||
package ltd.hlaeja.test.container.extension
|
||||
|
||||
import ltd.hlaeja.test.container.kafka.TestContainerKafka
|
||||
import ltd.hlaeja.test.container.postgres.TestContainerPostgres
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.springframework.boot.test.util.TestPropertyValues
|
||||
import org.springframework.context.ApplicationContextInitializer
|
||||
import org.springframework.context.ConfigurableApplicationContext
|
||||
|
||||
class KafkaPostgresTestExtension : BeforeAllCallback, ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
override fun initialize(applicationContext: ConfigurableApplicationContext) {
|
||||
TestPropertyValues
|
||||
.of(TestContainerPostgres.props() + TestContainerKafka.props())
|
||||
.applyTo(applicationContext.environment)
|
||||
}
|
||||
|
||||
override fun beforeAll(context: ExtensionContext) {
|
||||
if (!TestContainerPostgres.postgres.isRunning) {
|
||||
TestContainerPostgres.postgres.start()
|
||||
}
|
||||
if (!TestContainerKafka.kafka.isRunning) {
|
||||
TestContainerKafka.kafka.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user