Search in sources :

Example 11 with Destination

use of jakarta.jms.Destination 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 Destination

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

the class JndiDestinationResolverTests method testDoesNotUseCacheIfCachingIsTurnedOff.

@Test
public void testDoesNotUseCacheIfCachingIsTurnedOff() throws Exception {
    Session session = mock(Session.class);
    CountingCannedJndiDestinationResolver resolver = new CountingCannedJndiDestinationResolver();
    resolver.setCache(false);
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
    assertThat(resolver.getCallCount()).isEqualTo(1);
    destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
    assertThat(resolver.getCallCount()).isEqualTo(2);
}
Also used : Destination(jakarta.jms.Destination) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 13 with Destination

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

the class JndiDestinationResolverTests method testHitsCacheSecondTimeThrough.

@Test
public void testHitsCacheSecondTimeThrough() throws Exception {
    Session session = mock(Session.class);
    JndiDestinationResolver resolver = new OneTimeLookupJndiDestinationResolver();
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertThat(destination).isNotNull();
    assertThat(destination).isSameAs(DESTINATION);
}
Also used : Destination(jakarta.jms.Destination) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 14 with Destination

use of jakarta.jms.Destination 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 15 with Destination

use of jakarta.jms.Destination 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)

Aggregations

Destination (jakarta.jms.Destination)41 Test (org.junit.jupiter.api.Test)31 StubTextMessage (org.springframework.jms.StubTextMessage)11 Session (jakarta.jms.Session)8 TextMessage (jakarta.jms.TextMessage)5 JMSException (jakarta.jms.JMSException)3 HashMap (java.util.HashMap)3 DestinationResolutionException (org.springframework.jms.support.destination.DestinationResolutionException)3 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)3 MessageProducer (jakarta.jms.MessageProducer)2 QueueSender (jakarta.jms.QueueSender)2 NamingException (javax.naming.NamingException)2 StubQueue (org.springframework.jms.StubQueue)2 Connection (jakarta.jms.Connection)1 ConnectionFactory (jakarta.jms.ConnectionFactory)1 Message (jakarta.jms.Message)1 MessageConsumer (jakarta.jms.MessageConsumer)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 JmsTemplate (org.springframework.jms.core.JmsTemplate)1