Search in sources :

Example 1 with DefaultDatatypeChannelMessageConverter

use of org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter in project spring-integration by spring-projects.

the class DatatypeChannelTests method genericConverters.

@Test
public void genericConverters() {
    QueueChannel channel = createChannel(Foo.class);
    DefaultConversionService conversionService = new DefaultConversionService();
    conversionService.addConverter(new StringToBarConverter());
    conversionService.addConverter(new IntegerToBazConverter());
    DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
    converter.setConversionService(conversionService);
    channel.setMessageConverter(converter);
    assertTrue(channel.send(new GenericMessage<String>("foo")));
    Message<?> out = channel.receive(0);
    assertThat(out.getPayload(), instanceOf(Bar.class));
    assertTrue(channel.send(new GenericMessage<Integer>(42)));
    out = channel.receive(0);
    assertThat(out.getPayload(), instanceOf(Baz.class));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultDatatypeChannelMessageConverter(org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter) Test(org.junit.Test)

Example 2 with DefaultDatatypeChannelMessageConverter

use of org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter in project spring-integration by spring-projects.

the class DatatypeChannelTests method unsupportedTypeButConversionServiceSupports.

@Test
public void unsupportedTypeButConversionServiceSupports() {
    QueueChannel channel = createChannel(Integer.class);
    ConversionService conversionService = new DefaultConversionService();
    DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
    converter.setConversionService(conversionService);
    channel.setMessageConverter(converter);
    assertTrue(channel.send(new GenericMessage<String>("123")));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ConversionService(org.springframework.core.convert.ConversionService) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultDatatypeChannelMessageConverter(org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter) Test(org.junit.Test)

Example 3 with DefaultDatatypeChannelMessageConverter

use of org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter in project spring-integration by spring-projects.

the class DatatypeChannelTests method unsupportedTypeButCustomConversionServiceSupports.

@Test
public void unsupportedTypeButCustomConversionServiceSupports() {
    QueueChannel channel = createChannel(Integer.class);
    GenericConversionService conversionService = new DefaultConversionService();
    conversionService.addConverter(new Converter<Boolean, Integer>() {

        @Override
        public Integer convert(Boolean source) {
            return source ? 1 : 0;
        }
    });
    DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
    converter.setConversionService(conversionService);
    channel.setMessageConverter(converter);
    assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
    assertEquals(1, channel.receive().getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultDatatypeChannelMessageConverter(org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) Test(org.junit.Test)

Example 4 with DefaultDatatypeChannelMessageConverter

use of org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter in project spring-integration by spring-projects.

the class DatatypeChannelTests method unsupportedTypeAndConversionServiceDoesNotSupport.

@Test(expected = MessageDeliveryException.class)
public void unsupportedTypeAndConversionServiceDoesNotSupport() {
    QueueChannel channel = createChannel(Integer.class);
    ConversionService conversionService = new DefaultConversionService();
    DefaultDatatypeChannelMessageConverter converter = new DefaultDatatypeChannelMessageConverter();
    converter.setConversionService(conversionService);
    channel.setMessageConverter(converter);
    assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ConversionService(org.springframework.core.convert.ConversionService) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultDatatypeChannelMessageConverter(org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)4 DefaultDatatypeChannelMessageConverter (org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)3 ConversionService (org.springframework.core.convert.ConversionService)2