0

I am writing a unit test that contains a component written inside the test class itself. But I get an error No qualifying bean of type 'com.my.app.KafkaProducerServiceTest$KafkaConsumerHelper' available: No resolvable resource object. I know it is an issue with the bean naming but I tried all the possible ways to fix it without luck.

Any clue how to fix this??

 @ActiveProfiles("test")
 @EmbeddedKafka(
    partitions = 1,
    bootstrapServersProperty = "spring.kafka.bootstrap-servers",
    topics = arrayOf("someTopic")
 )
 @SpringBootTest(
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
    properties = ["kafka.schema-registry.url=mock://mock"]
 )
 internal class KafkaProducerServiceTest {

    @Resource
    var kafkaConsumerHelper: KafkaConsumerHelper? = null

    @Test
    fun send() {
      val mockKey = mockk<EventKey>(relaxed = true)
      val mockValue = mockk<Event>(relaxed = true)

      producer.send(mockKey, mockValue)
    }


    @Component
    class KafkaConsumerHelper {
       val latch = CountDownLatch(1)
       lateinit var payload: String


       @KafkaListener(topics = ["someTopic"])
       fun receive(consumerRecord: ConsumerRecord<EventKey, Event>) {
          payload = consumerRecord.value().id.toString()
          latch.countDown()
       }
    }
}
ever alian
  • 1,028
  • 3
  • 15
  • 45

0 Answers0