Search in sources :

Example 6 with TextMessage

use of jakarta.jms.TextMessage in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertAndSendPayloadName.

@Test
public void convertAndSendPayloadName() throws JMSException {
    this.messagingTemplate.convertAndSend("myQueue", "my Payload");
    verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture());
    TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
    assertThat(textMessage.getText()).isEqualTo("my Payload");
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 7 with TextMessage

use of jakarta.jms.TextMessage in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertAndSendDefaultDestination.

@Test
public void convertAndSendDefaultDestination() throws JMSException {
    Destination destination = new Destination() {
    };
    this.messagingTemplate.setDefaultDestination(destination);
    this.messagingTemplate.convertAndSend("my Payload");
    verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture());
    TextMessage textMessage = createTextMessage(this.messageCreator.getValue());
    assertThat(textMessage.getText()).isEqualTo("my Payload");
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 8 with TextMessage

use of jakarta.jms.TextMessage in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testWithMessageDelegate.

@Test
void testWithMessageDelegate() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    MessageDelegate delegate = mock(MessageDelegate.class);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
    // we DON'T want the default SimpleMessageConversion happening...
    adapter.setMessageConverter(null);
    adapter.onMessage(textMessage);
    verify(delegate).handleMessage(textMessage);
}
Also used : TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 9 with TextMessage

use of jakarta.jms.TextMessage in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied.

@Test
void testWithResponsiveMessageDelegateWhenReturnTypeIsAJMSMessageAndNoMessageConverterIsSupplied() throws Exception {
    Queue destination = mock(Queue.class);
    final TextMessage sentTextMessage = mock(TextMessage.class);
    // correlation ID is queried when response is being created...
    given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
    // Reply-To is queried when response is being created...
    given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
    TextMessage responseMessage = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(session.createProducer(destination)).willReturn(queueSender);
    ResponsiveJmsTextMessageReturningMessageDelegate delegate = mock(ResponsiveJmsTextMessageReturningMessageDelegate.class);
    given(delegate.handleMessage(sentTextMessage)).willReturn(responseMessage);
    final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {

        @Override
        protected Object extractMessage(Message message) {
            return message;
        }
    };
    adapter.setMessageConverter(null);
    adapter.onMessage(sentTextMessage, session);
    verify(responseMessage).setJMSCorrelationID(CORRELATION_ID);
    verify(queueSender).send(responseMessage);
    verify(queueSender).close();
}
Also used : Message(jakarta.jms.Message) BytesMessage(jakarta.jms.BytesMessage) TextMessage(jakarta.jms.TextMessage) ObjectMessage(jakarta.jms.ObjectMessage) QueueSender(jakarta.jms.QueueSender) Queue(jakarta.jms.Queue) TextMessage(jakarta.jms.TextMessage) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 10 with TextMessage

use of jakarta.jms.TextMessage in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied.

@Test
void testWithResponsiveMessageDelegate_DoesNotSendReturnTextMessageIfNoSessionSupplied() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
    given(delegate.handleMessage(textMessage)).willReturn(TEXT);
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
    // we DON'T want the default SimpleMessageConversion happening...
    adapter.setMessageConverter(null);
    adapter.onMessage(textMessage);
}
Also used : TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Aggregations

TextMessage (jakarta.jms.TextMessage)54 Test (org.junit.jupiter.api.Test)47 StubTextMessage (org.springframework.jms.StubTextMessage)22 Session (jakarta.jms.Session)20 MessageProducer (jakarta.jms.MessageProducer)13 Message (jakarta.jms.Message)12 Queue (jakarta.jms.Queue)10 ObjectMessage (jakarta.jms.ObjectMessage)9 Message (org.springframework.messaging.Message)9 BytesMessage (jakarta.jms.BytesMessage)8 Destination (jakarta.jms.Destination)7 QueueSession (jakarta.jms.QueueSession)7 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)5 JMSException (jakarta.jms.JMSException)4 QueueSender (jakarta.jms.QueueSender)4 MessageConsumer (jakarta.jms.MessageConsumer)3 HashMap (java.util.HashMap)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 QosSettings (org.springframework.jms.support.QosSettings)3 ConnectionFactory (jakarta.jms.ConnectionFactory)2