use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertMessageNotWritableException.
@Test
public void convertMessageNotWritableException() throws JMSException {
Message<String> message = createTextMessage();
MessageConverter messageConverter = mock(MessageConverter.class);
willThrow(MessageNotWriteableException.class).given(messageConverter).toMessage(eq(message), any());
messagingTemplate.setJmsMessageConverter(messageConverter);
invokeMessageCreator("myQueue");
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
messagingTemplate.send("myQueue", message);
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method convertMessageConversionExceptionOnSend.
@Test
public void convertMessageConversionExceptionOnSend() throws JMSException {
Message<String> message = createTextMessage();
MessageConverter messageConverter = mock(MessageConverter.class);
willThrow(org.springframework.jms.support.converter.MessageConversionException.class).given(messageConverter).toMessage(eq(message), any());
messagingTemplate.setJmsMessageConverter(messageConverter);
invokeMessageCreator("myQueue");
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
messagingTemplate.send("myQueue", message);
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method setExtraCollaborators.
@Test
public void setExtraCollaborators() {
MessageConverter messageConverter = mock(MessageConverter.class);
DestinationResolver destinationResolver = mock(DestinationResolver.class);
this.container.setMessageConverter(messageConverter);
this.container.setDestinationResolver(destinationResolver);
MessagingMessageListenerAdapter listener = createInstance(this.factory, getListenerMethod("resolveObjectPayload", MyBean.class), container);
DirectFieldAccessor accessor = new DirectFieldAccessor(listener);
assertSame(messageConverter, accessor.getPropertyValue("messageConverter"));
assertSame(destinationResolver, accessor.getPropertyValue("destinationResolver"));
}
use of org.springframework.jms.support.converter.MessageConverter 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);
javax.jms.Message replyMessage = listener.buildMessage(session, result);
verify(messageConverter, times(1)).toMessage("Response", session);
assertNotNull("reply should never be null", replyMessage);
assertEquals("Response", ((TextMessage) replyMessage).getText());
}
use of org.springframework.jms.support.converter.MessageConverter in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method payloadConversionLazilyInvoked.
@Test
public void payloadConversionLazilyInvoked() throws JMSException {
javax.jms.Message jmsMessage = mock(javax.jms.Message.class);
MessageConverter messageConverter = mock(MessageConverter.class);
given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
listener.setMessageConverter(messageConverter);
Message<?> message = listener.toMessagingMessage(jmsMessage);
verify(messageConverter, never()).fromMessage(jmsMessage);
assertEquals("FooBar", message.getPayload());
verify(messageConverter, times(1)).fromMessage(jmsMessage);
}
Aggregations