Search in sources :

Example 1 with MessageConverter

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);
}
Also used : SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) GenericMessageConverter(org.springframework.messaging.converter.GenericMessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Test(org.junit.Test)

Example 2 with MessageConverter

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);
}
Also used : SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) GenericMessageConverter(org.springframework.messaging.converter.GenericMessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Test(org.junit.Test)

Example 3 with MessageConverter

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"));
}
Also used : DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) MessagingMessageListenerAdapter(org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Test(org.junit.Test)

Example 4 with MessageConverter

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());
}
Also used : StubTextMessage(org.springframework.jms.StubTextMessage) MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Session(javax.jms.Session) Test(org.junit.Test)

Example 5 with MessageConverter

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);
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) MessageConverter(org.springframework.jms.support.converter.MessageConverter) Test(org.junit.Test)

Aggregations

MessageConverter (org.springframework.jms.support.converter.MessageConverter)10 Test (org.junit.Test)8 SimpleMessageConverter (org.springframework.jms.support.converter.SimpleMessageConverter)5 GenericMessageConverter (org.springframework.messaging.converter.GenericMessageConverter)4 MappingJackson2MessageConverter (org.springframework.jms.support.converter.MappingJackson2MessageConverter)3 Session (javax.jms.Session)2 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)2 DestinationResolver (org.springframework.jms.support.destination.DestinationResolver)2 BytesMessage (javax.jms.BytesMessage)1 Message (javax.jms.Message)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 StubTextMessage (org.springframework.jms.StubTextMessage)1 MessageConversionException (org.springframework.jms.support.converter.MessageConversionException)1 MessagingMessageConverter (org.springframework.jms.support.converter.MessagingMessageConverter)1 SmartMessageConverter (org.springframework.jms.support.converter.SmartMessageConverter)1 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)1