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();
}
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);
}
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");
}
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);
}
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();
}
Aggregations