Search in sources :

Example 46 with Session

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

the class MethodJmsListenerEndpointTests method resolveCustomHeaderNameAndPayloadWithHeaderNameSet.

@Test
void resolveCustomHeaderNameAndPayloadWithHeaderNameSet() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setIntProperty("myCounter", 24);
    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)

Example 47 with Session

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

the class MethodJmsListenerEndpointTests method emptySendTo.

@Test
void emptySendTo() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
    TextMessage reply = mock(TextMessage.class);
    Session session = mock(Session.class);
    given(session.createTextMessage("content")).willReturn(reply);
    assertThatExceptionOfType(ReplyFailureException.class).isThrownBy(() -> listener.onMessage(createSimpleJmsTextMessage("content"), session)).withCauseInstanceOf(InvalidDestinationException.class);
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 48 with Session

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

the class MethodJmsListenerEndpointTests method resolveGenericMessage.

@Test
void resolveGenericMessage() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(Message.class);
    Session session = mock(Session.class);
    listener.onMessage(createSimpleJmsTextMessage("test"), session);
    assertDefaultListenerMethodInvocation();
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 49 with Session

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

the class MethodJmsListenerEndpointTests method processAndReply.

@Test
void processAndReply() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
    String body = "echo text";
    String correlationId = "link-1234";
    Destination replyDestination = new Destination() {
    };
    TextMessage reply = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(session.createTextMessage(body)).willReturn(reply);
    given(session.createProducer(replyDestination)).willReturn(queueSender);
    listener.setDefaultResponseDestination(replyDestination);
    StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
    inputMessage.setJMSCorrelationID(correlationId);
    listener.onMessage(inputMessage, session);
    assertDefaultListenerMethodInvocation();
    verify(reply).setJMSCorrelationID(correlationId);
    verify(queueSender).send(reply);
    verify(queueSender).close();
}
Also used : Destination(jakarta.jms.Destination) MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) QueueSender(jakarta.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 50 with Session

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

the class MethodJmsListenerEndpointTests method processAndReplyWithSendTo.

private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, String replyDestinationName, boolean pubSubDomain, QosSettings replyQosSettings) throws JMSException {
    String body = "echo text";
    String correlationId = "link-1234";
    Destination replyDestination = new Destination() {
    };
    DestinationResolver destinationResolver = mock(DestinationResolver.class);
    TextMessage reply = mock(TextMessage.class);
    QueueSender queueSender = mock(QueueSender.class);
    Session session = mock(Session.class);
    given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain)).willReturn(replyDestination);
    given(session.createTextMessage(body)).willReturn(reply);
    given(session.createProducer(replyDestination)).willReturn(queueSender);
    listener.setDestinationResolver(destinationResolver);
    StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
    inputMessage.setJMSCorrelationID(correlationId);
    listener.onMessage(inputMessage, session);
    verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
    verify(reply).setJMSCorrelationID(correlationId);
    if (replyQosSettings != null) {
        verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(), replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
    } else {
        verify(queueSender).send(reply);
    }
    verify(queueSender).close();
}
Also used : Destination(jakarta.jms.Destination) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) QueueSender(jakarta.jms.QueueSender) StubTextMessage(org.springframework.jms.StubTextMessage) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session)

Aggregations

Session (jakarta.jms.Session)84 Test (org.junit.jupiter.api.Test)71 Connection (jakarta.jms.Connection)30 Message (jakarta.jms.Message)27 TextMessage (jakarta.jms.TextMessage)26 StubTextMessage (org.springframework.jms.StubTextMessage)22 ConnectionFactory (jakarta.jms.ConnectionFactory)21 JMSException (jakarta.jms.JMSException)20 MessageProducer (jakarta.jms.MessageProducer)19 Destination (jakarta.jms.Destination)18 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)16 Queue (jakarta.jms.Queue)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 BDDMockito.given (org.mockito.BDDMockito.given)12 Mockito.mock (org.mockito.Mockito.mock)12 Mockito.verify (org.mockito.Mockito.verify)12 StubQueue (org.springframework.jms.StubQueue)12 ObjectMessage (jakarta.jms.ObjectMessage)11 QueueSession (jakarta.jms.QueueSession)11 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)11