Search in sources :

Example 1 with GenericMessageConverter

use of org.springframework.messaging.converter.GenericMessageConverter in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method receiveAndConvertWithConversion.

@Test
public void receiveAndConvertWithConversion() {
    javax.jms.Message jmsMessage = createJmsTextMessage("123");
    given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);
    messagingTemplate.setMessageConverter(new GenericMessageConverter());
    Integer payload = messagingTemplate.receiveAndConvert("myQueue", Integer.class);
    assertEquals(Integer.valueOf(123), payload);
    verify(jmsTemplate).receive("myQueue");
}
Also used : GenericMessageConverter(org.springframework.messaging.converter.GenericMessageConverter) Test(org.junit.Test)

Example 2 with GenericMessageConverter

use of org.springframework.messaging.converter.GenericMessageConverter in project spring-framework by spring-projects.

the class MessageReceivingTemplateTests method receiveAndConvertNoConverter.

@Test
public void receiveAndConvertNoConverter() {
    Message<?> expected = new GenericMessage<Object>("payload");
    this.template.setDefaultDestination("home");
    this.template.setReceiveMessage(expected);
    this.template.setMessageConverter(new GenericMessageConverter());
    try {
        this.template.receiveAndConvert(Writer.class);
    } catch (MessageConversionException ex) {
        assertTrue("Invalid exception message '" + ex.getMessage() + "'", ex.getMessage().contains("payload"));
        assertSame(expected, ex.getFailedMessage());
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) GenericMessageConverter(org.springframework.messaging.converter.GenericMessageConverter) MessageConversionException(org.springframework.messaging.converter.MessageConversionException) Test(org.junit.Test)

Example 3 with GenericMessageConverter

use of org.springframework.messaging.converter.GenericMessageConverter in project spring-framework by spring-projects.

the class MessageReceivingTemplateTests method receiveAndConvertFailed.

@Test
public void receiveAndConvertFailed() {
    Message<?> expected = new GenericMessage<Object>("not a number test");
    this.template.setReceiveMessage(expected);
    this.template.setMessageConverter(new GenericMessageConverter());
    thrown.expect(MessageConversionException.class);
    thrown.expectCause(isA(ConversionFailedException.class));
    this.template.receiveAndConvert("somewhere", Integer.class);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) GenericMessageConverter(org.springframework.messaging.converter.GenericMessageConverter) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 GenericMessageConverter (org.springframework.messaging.converter.GenericMessageConverter)3 GenericMessage (org.springframework.messaging.support.GenericMessage)2 ConversionFailedException (org.springframework.core.convert.ConversionFailedException)1 MessageConversionException (org.springframework.messaging.converter.MessageConversionException)1