Search in sources :

Example 16 with Session

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

the class MethodJmsListenerEndpointTests method invalidPayloadType.

// failure scenario
@Test
void invalidPayloadType() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(Integer.class);
    Session session = mock(Session.class);
    // test is not a valid integer
    assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(createSimpleJmsTextMessage("test"), session)).withCauseInstanceOf(MessageConversionException.class).withMessageContaining(// ref to method
    getDefaultListenerMethod(Integer.class).toGenericString());
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) ListenerExecutionFailedException(org.springframework.jms.listener.adapter.ListenerExecutionFailedException) MessageConversionException(org.springframework.messaging.converter.MessageConversionException) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 17 with Session

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

the class MethodJmsListenerEndpointTests method resolveConvertedPayload.

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

Example 18 with Session

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

the class MethodJmsListenerEndpointTests method resolveMessageHeaders.

@Test
void resolveMessageHeaders() throws JMSException {
    MessagingMessageListenerAdapter listener = createDefaultInstance(MessageHeaders.class);
    Session session = mock(Session.class);
    StubTextMessage message = createSimpleJmsTextMessage("my payload");
    message.setLongProperty("customLong", 4567L);
    message.setJMSType("myMessageType");
    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 19 with Session

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

the class MethodJmsListenerEndpointTests method resolveCustomHeaderNameAndPayload.

@Test
void resolveCustomHeaderNameAndPayload() 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 20 with Session

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

the class MethodJmsListenerEndpointTests method validatePayloadValid.

@Test
void validatePayloadValid() throws JMSException {
    String methodName = "validatePayload";
    DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
    customFactory.setValidator(testValidator("invalid value"));
    initializeFactory(customFactory);
    Method method = getListenerMethod(methodName, String.class);
    MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
    Session session = mock(Session.class);
    // test is a valid value
    listener.onMessage(createSimpleJmsTextMessage("test"), session);
    assertListenerMethodInvocation(this.sample, methodName);
}
Also used : MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) DefaultMessageHandlerMethodFactory(org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory) Method(java.lang.reflect.Method) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

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