Search in sources :

Example 11 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class JmsMessageHeaderAccessorTests method validateJmsHeaders.

@Test
public void validateJmsHeaders() throws JMSException {
    Destination destination = new Destination() {
    };
    Destination replyTo = new Destination() {
    };
    StubTextMessage jmsMessage = new StubTextMessage("test");
    jmsMessage.setJMSCorrelationID("correlation-1234");
    jmsMessage.setJMSPriority(9);
    jmsMessage.setJMSDestination(destination);
    jmsMessage.setJMSDeliveryMode(1);
    jmsMessage.setJMSExpiration(1234L);
    jmsMessage.setJMSMessageID("abcd-1234");
    jmsMessage.setJMSPriority(9);
    jmsMessage.setJMSReplyTo(replyTo);
    jmsMessage.setJMSRedelivered(true);
    jmsMessage.setJMSType("type");
    jmsMessage.setJMSTimestamp(4567L);
    Map<String, Object> mappedHeaders = new SimpleJmsHeaderMapper().toHeaders(jmsMessage);
    Message<String> message = MessageBuilder.withPayload("test").copyHeaders(mappedHeaders).build();
    JmsMessageHeaderAccessor headerAccessor = JmsMessageHeaderAccessor.wrap(message);
    assertThat(headerAccessor.getCorrelationId()).isEqualTo("correlation-1234");
    assertThat(headerAccessor.getDestination()).isEqualTo(destination);
    assertThat(headerAccessor.getDeliveryMode()).isEqualTo(Integer.valueOf(1));
    assertThat(headerAccessor.getExpiration()).isEqualTo(1234);
    assertThat(headerAccessor.getMessageId()).isEqualTo("abcd-1234");
    assertThat(headerAccessor.getPriority()).isEqualTo(Integer.valueOf(9));
    assertThat(headerAccessor.getReplyTo()).isEqualTo(replyTo);
    assertThat(headerAccessor.getRedelivered()).isTrue();
    assertThat(headerAccessor.getType()).isEqualTo("type");
    assertThat(headerAccessor.getTimestamp()).isEqualTo(4567);
    // Making sure replyChannel is not mixed with replyTo
    assertThat(headerAccessor.getReplyChannel()).isNull();
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.jupiter.api.Test)

Example 12 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MessagingMessageConverterTests method customPayloadConverter.

@Test
public void customPayloadConverter() throws JMSException {
    TextMessage jmsMsg = new StubTextMessage("1224");
    this.converter.setPayloadConverter(new TestMessageConverter());
    Message<?> msg = (Message<?>) this.converter.fromMessage(jmsMsg);
    assertThat(msg.getPayload()).isEqualTo(1224L);
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Message(org.springframework.messaging.Message) ObjectMessage(jakarta.jms.ObjectMessage) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Test(org.junit.jupiter.api.Test)

Example 13 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class SimpleJmsHeaderMapperTests method attemptToWriteDisallowedReplyToPropertyIsNotFatal.

@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
    Message<String> message = initBuilder().setHeader(JmsHeaders.REPLY_TO, new Destination() {
    }).setHeader("foo", "bar").build();
    jakarta.jms.Message jmsMessage = new StubTextMessage() {

        @Override
        public void setJMSReplyTo(Destination replyTo) throws JMSException {
            throw new JMSException("illegal property");
        }
    };
    mapper.fromHeaders(message.getHeaders(), jmsMessage);
    assertThat(jmsMessage.getJMSReplyTo()).isNull();
    assertThat(jmsMessage.getStringProperty("foo")).isNotNull();
    assertThat(jmsMessage.getStringProperty("foo")).isEqualTo("bar");
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) JMSException(jakarta.jms.JMSException) Test(org.junit.jupiter.api.Test)

Example 14 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class SimpleJmsHeaderMapperTests method jmsReplyToMappedFromHeader.

// Outbound mapping
@Test
public void jmsReplyToMappedFromHeader() throws JMSException {
    Destination replyTo = new Destination() {
    };
    Message<String> message = initBuilder().setHeader(JmsHeaders.REPLY_TO, replyTo).build();
    jakarta.jms.Message jmsMessage = new StubTextMessage();
    mapper.fromHeaders(message.getHeaders(), jmsMessage);
    assertThat(jmsMessage.getJMSReplyTo()).isNotNull();
    assertThat(jmsMessage.getJMSReplyTo()).isSameAs(replyTo);
}
Also used : Destination(jakarta.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.jupiter.api.Test)

Example 15 with StubTextMessage

use of org.springframework.jms.StubTextMessage in project spring-framework by spring-projects.

the class MethodJmsListenerEndpointTests method resolveHeaderAndPayload.

@Test
void resolveHeaderAndPayload() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setIntProperty("myCounter", 55);
    listener.onMessage(message, session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Aggregations

StubTextMessage (org.springframework.jms.StubTextMessage)26 Test (org.junit.jupiter.api.Test)21 Session (jakarta.jms.Session)14 Destination (jakarta.jms.Destination)10 TextMessage (jakarta.jms.TextMessage)9 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)8 JMSException (jakarta.jms.JMSException)3 Message (jakarta.jms.Message)3 QueueSender (jakarta.jms.QueueSender)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ProxyFactory (org.springframework.aop.framework.ProxyFactory)2 MessageConverter (org.springframework.jms.support.converter.MessageConverter)2 Message (org.springframework.messaging.Message)2 MessageFormatException (jakarta.jms.MessageFormatException)1 MessageNotWriteableException (jakarta.jms.MessageNotWriteableException)1 ObjectMessage (jakarta.jms.ObjectMessage)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1