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