use of jakarta.jms.MessageProducer in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyPayloadToDestination.
@Test
public void replyPayloadToDestination() throws JMSException {
Session session = mock(Session.class);
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage responseMessage = mock(TextMessage.class);
given(session.createTextMessage("Response")).willReturn(responseMessage);
given(session.createProducer(sharedReplyDestination)).willReturn(messageProducer);
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToDestination", Message.class);
listener.onMessage(mock(jakarta.jms.Message.class), session);
verify(session, times(0)).createQueue(anyString());
verify(session).createTextMessage("Response");
verify(messageProducer).send(responseMessage);
verify(messageProducer).close();
}
use of jakarta.jms.MessageProducer in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method replyPayloadToTopic.
@Test
public void replyPayloadToTopic() throws JMSException {
Session session = mock(Session.class);
Topic replyDestination = mock(Topic.class);
given(session.createTopic("topicOut")).willReturn(replyDestination);
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage responseMessage = mock(TextMessage.class);
given(session.createTextMessage("Response")).willReturn(responseMessage);
given(session.createProducer(replyDestination)).willReturn(messageProducer);
MessagingMessageListenerAdapter listener = getPayloadInstance("Response", "replyPayloadToTopic", Message.class);
listener.onMessage(mock(jakarta.jms.Message.class), session);
verify(session).createTopic("topicOut");
verify(session).createTextMessage("Response");
verify(messageProducer).send(responseMessage);
verify(messageProducer).close();
}
use of jakarta.jms.MessageProducer in project spring-framework by spring-projects.
the class JmsTemplateTests method testConverter.
@Test
void testConverter() throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
given(this.session.createTextMessage("Hello world")).willReturn(textMessage);
template.convertAndSend(this.queue, s);
verify(messageProducer).send(textMessage);
verify(messageProducer).close();
if (useTransactedTemplate()) {
verify(this.session).commit();
}
verify(this.session).close();
verify(this.connection).close();
}
use of jakarta.jms.MessageProducer in project spring-framework by spring-projects.
the class JmsTemplateTests method doTestJmsException.
protected void doTestJmsException(JMSException original, Class<? extends JmsException> thrownExceptionClass) throws Exception {
JmsTemplate template = createTemplate();
template.setConnectionFactory(this.connectionFactory);
template.setMessageConverter(new SimpleMessageConverter());
String s = "Hello world";
MessageProducer messageProducer = mock(MessageProducer.class);
TextMessage textMessage = mock(TextMessage.class);
reset(this.session);
given(this.session.createProducer(this.queue)).willReturn(messageProducer);
given(this.session.createTextMessage("Hello world")).willReturn(textMessage);
willThrow(original).given(messageProducer).send(textMessage);
assertThatExceptionOfType(thrownExceptionClass).isThrownBy(() -> template.convertAndSend(this.queue, s)).withCause(original);
verify(messageProducer).close();
verify(this.session).close();
verify(this.connection).close();
}
Aggregations