add kafka and postgres test container
This commit is contained in:
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
In the forge of software development, where annotations ignite, A crucible of testing, common classes to excite. Each annotation examined, with attention to detail and might, Their effects on code behavior, tested through day and night. From mockk objects to test doubles, a toolkit to refine, Developers and testers, their skills to redefine. The Annotation Validator, a sentinel of code integrity true, A library of verification, where testing wisdom shines anew.
|
In the forge of software development, where annotations ignite, A crucible of testing, common classes to excite. Each annotation examined, with attention to detail and might, Their effects on code behavior, tested through day and night. From mockk objects to test doubles, a toolkit to refine, Developers and testers, their skills to redefine. The Annotation Validator, a sentinel of code integrity true, A library of verification, where testing wisdom shines anew.
|
||||||
|
|
||||||
|
## Kafka and Postgres Test Container
|
||||||
|
|
||||||
|
`@KafkaPostgresTestContainer` Annotation for integration tests.
|
||||||
|
|
||||||
|
This combined `@KafkaTestContainer` and `@PostgresTestContainer`
|
||||||
|
|
||||||
## Kafka Test Container
|
## Kafka Test Container
|
||||||
|
|
||||||
`@KafkaTestContainer` Annotation for integration tests.
|
`@KafkaTestContainer` Annotation for integration tests.
|
||||||
|
|||||||
@@ -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