https://kotlinlang.org logo
#spring
Title
# spring
a

Alexandre A Barbosa

01/16/2023, 8:02 PM
Hi team. please: is it possible to disable Kafka during my unit tests? I’ve created a class with a method using
@KafkaListener
annotation and when I run the functional tests, I produce a protobuf topic message and the listener works properly to consume that message. But my unit test need to test this method, and I am using this:
Copy code
@Autowired
lateinit var ingestionListener: IngestionConsumerListener
to inject my listener and I want to test this method but without the Kafka in memory. But the test is trying to load the Kafka because I am getting this:
Copy code
Could not resolve placeholder 'ingestion.config.topic.name' in value "#{'${ingestion.config.topic.name}'}"
that is used in my implementation:
Copy code
@KafkaListener(
    id = "ingestionListener",
    topics = ["#{'\${ingestion.config.topic.name}'}"],
    groupId = "#{'\${ingestion.consumer.group.id}'}",
    concurrency = "#{'\${ingestion.config.consumer.concurrency}'}"
)
fun consumeIngestion(ingestionHttpRequest: ConsumerRecord<String, IngestionHttpRequest.HttpRequest>)
I am trying to use this kind of solution for my first unit test using Kotlin and Kafka:
Copy code
@EnableAutoConfiguration(exclude = [KafkaAutoConfiguration::class])
but I am still struggling with the error above… Please any suggestion to fix that? How to test a kafka listener using Java/Kotlin without Kafka in memory? Issue: FIXED! I only needed to add all properties necessary for the UT and Kafka is not necessary at memory
14 Views