Search in sources :

Example 6 with StubTextMessage

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

the class JmsListenerContainerFactoryIntegrationTests method parameterAnnotationWithCglibProxy.

@Test
public void parameterAnnotationWithCglibProxy() throws JMSException {
    ProxyFactory pf = new ProxyFactory(sample);
    pf.setProxyTargetClass(true);
    listener = (JmsEndpointSampleBean) pf.getProxy();
    containerFactory.setMessageConverter(new UpperCaseMessageConverter());
    MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(JmsEndpointSampleBean.class, "handleIt", String.class, String.class);
    Message message = new StubTextMessage("foo-bar");
    message.setStringProperty("my-header", "my-value");
    invokeListener(endpoint, message);
    assertListenerMethodInvocation("handleIt");
}
Also used : Message(jakarta.jms.Message) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) ProxyFactory(org.springframework.aop.framework.ProxyFactory) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.jupiter.api.Test)

Example 7 with StubTextMessage

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

the class JmsListenerContainerFactoryIntegrationTests method parameterAnnotationWithJdkProxy.

@Test
public void parameterAnnotationWithJdkProxy() throws JMSException {
    ProxyFactory pf = new ProxyFactory(sample);
    listener = (JmsEndpointSampleInterface) pf.getProxy();
    containerFactory.setMessageConverter(new UpperCaseMessageConverter());
    MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(JmsEndpointSampleInterface.class, "handleIt", String.class, String.class);
    Message message = new StubTextMessage("foo-bar");
    message.setStringProperty("my-header", "my-value");
    invokeListener(endpoint, message);
    assertListenerMethodInvocation("handleIt");
}
Also used : Message(jakarta.jms.Message) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) ProxyFactory(org.springframework.aop.framework.ProxyFactory) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.jupiter.api.Test)

Example 8 with StubTextMessage

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

the class MessagingMessageListenerAdapterTests method exceptionInListener.

@Test
public void exceptionInListener() {
    jakarta.jms.Message message = new StubTextMessage("foo");
    Session session = mock(Session.class);
    MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class);
    assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(message, session)).havingCause().isExactlyInstanceOf(IllegalArgumentException.class).withMessage("Expected test exception");
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 9 with StubTextMessage

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

the class MessagingMessageListenerAdapterTests method exceptionInInvocation.

@Test
public void exceptionInInvocation() {
    jakarta.jms.Message message = new StubTextMessage("foo");
    Session session = mock(Session.class);
    MessagingMessageListenerAdapter listener = getSimpleInstance("wrongParam", Integer.class);
    assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(message, session)).withCauseExactlyInstanceOf(MessageConversionException.class);
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) Session(jakarta.jms.Session) Test(org.junit.jupiter.api.Test)

Example 10 with StubTextMessage

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

the class MessagingMessageListenerAdapterTests method replyUsesMessageConverterForPayload.

@Test
public void replyUsesMessageConverterForPayload() throws JMSException {
    Session session = mock(Session.class);
    MessageConverter messageConverter = mock(MessageConverter.class);
    given(messageConverter.toMessage("Response", session)).willReturn(new StubTextMessage("Response"));
    Message<String> result = MessageBuilder.withPayload("Response").build();
    MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
    listener.setMessageConverter(messageConverter);
    jakarta.jms.Message replyMessage = listener.buildMessage(session, result);
    verify(messageConverter, times(1)).toMessage("Response", session);
    assertThat(replyMessage).as("reply should never be null").isNotNull();
    assertThat(((TextMessage) replyMessage).getText()).isEqualTo("Response");
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) 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