I trying to write test for my springJmsListner, but it endlessly.I think its related with Context Caching but i'm not sure. I am using testContainers
@Autowired
private lateinit var jmsTemplate: JmsTemplate
@Autowired
private lateinit var jackson: ObjectMapper
@Autowired
private lateinit var jdbcTemplate: JdbcTemplate
@Test
fun testJmsListner() {
val message = "message"
val queue = "queue"
jmsTemplate.convertAndSend(queue, message)
val sentMessage: Message? = jmsTemplate.receive(queue)
if (sentMessage != null) {
assertTrue(sentMessage::class.java.isInstance(TextMessage::class.java))
}
assertEquals(message, (sentMessage as TextMessage).text)
in logs i see that last operation in another thread,but i dont know how fit this
2024-05-06T16:22:58.646+03:00 INFO 10455 --- [tasks] [ Test worker] .j.a.l.p.testJmsListner : Started testJmsListner in 1.746 seconds (process running for 6.678) 2024-05-06T16:22:58.909+03:00 INFO 10455 --- [tasks] [ntContainer#0-1] some logs about my message is recieved
You qualified what you really want in the comment above
I am trying to do test, which check that my message will be correctly deserialize
Depending on which JMS library is being used the message conversion may be handled in different ways. So you could use a different call to get access to the Message
before it gets sent.
Notice that convertAndSend(destination, message)
has an alternative convertAndSend(destination, message, messagePostProcessor)
You could call that in your test and in the callback you'll get access to the converted Message