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