Skip to content

Commit ed2e48c

Browse files
authored
Merge pull request #123 from navikt/chore/move-test-inside-emottak-utils-repo
Move test inside emottak utils repo
2 parents 63c12ae + 1f761b7 commit ed2e48c

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

emottak-utils/build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ publishing {
3434

3535
dependencies {
3636
testImplementation(kotlin("test"))
37+
testImplementation("org.testcontainers:kafka:1.19.0")
38+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.0")
39+
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.4.0")
3740
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
3841
implementation("io.github.nomisrev:kotlin-kafka:0.4.1")
3942
implementation("com.sksamuel.hoplite:hoplite-core:2.8.2")

ebms-async/src/test/kotlin/no/nav/emottak/ebms/async/kafka/KafkaPublisherClientTest.kt emottak-utils/src/test/kotlin/no/nav/emottak/utils/kafka/KafkaPublisherClientTest.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package no.nav.emottak.ebms.async.kafka
1+
package no.nav.emottak.utils.kafka
22

33
import com.sksamuel.hoplite.Masked
44
import kotlinx.coroutines.runBlocking
@@ -11,7 +11,6 @@ import no.nav.emottak.utils.config.TruststoreLocation
1111
import no.nav.emottak.utils.config.TruststoreType
1212
import no.nav.emottak.utils.events.model.Event
1313
import no.nav.emottak.utils.events.model.EventType
14-
import no.nav.emottak.utils.kafka.KafkaPublisherClient
1514
import org.apache.kafka.clients.consumer.ConsumerConfig
1615
import org.apache.kafka.clients.consumer.ConsumerRecord
1716
import org.apache.kafka.clients.consumer.KafkaConsumer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package no.nav.emottak.utils.kafka
2+
3+
import org.apache.kafka.clients.admin.AdminClient
4+
import org.apache.kafka.clients.admin.AdminClientConfig
5+
import org.apache.kafka.clients.admin.NewTopic
6+
import org.testcontainers.containers.KafkaContainer
7+
import org.testcontainers.utility.DockerImageName
8+
9+
object KafkaTestContainer {
10+
private val kafkaContainer: KafkaContainer = KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.5.0"))
11+
12+
val bootstrapServers: String
13+
get() = kafkaContainer.bootstrapServers
14+
15+
fun start() {
16+
kafkaContainer.start()
17+
}
18+
19+
fun stop() {
20+
kafkaContainer.stop()
21+
}
22+
23+
fun createTopic(topicName: String, partitions: Int = 1, replicationFactor: Short = 1) {
24+
val config = mapOf(
25+
AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers
26+
)
27+
28+
AdminClient.create(config).use { adminClient ->
29+
val newTopic = NewTopic(topicName, partitions, replicationFactor)
30+
adminClient.createTopics(listOf(newTopic)).all().get()
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)