use of org.springframework.core.convert.support.DefaultConversionService 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.core.convert.support.DefaultConversionService 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)));
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-integration by spring-projects.
the class MethodInvokingMessageGroupProcessorTests method shouldFindSimpleAggregatorMethodWithIterator.
@Test
public void shouldFindSimpleAggregatorMethodWithIterator() throws Exception {
@SuppressWarnings("unused")
class SimpleAggregator {
public Integer and(Iterator<Integer> flags) {
int result = 0;
while (flags.hasNext()) {
result = result | flags.next();
}
return result;
}
}
MethodInvokingMessageGroupProcessor processor = new MethodInvokingMessageGroupProcessor(new SimpleAggregator());
GenericConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<ArrayList<?>, Iterator<?>>() {
@Override
public Iterator<?> convert(ArrayList<?> source) {
return source.iterator();
}
});
processor.setConversionService(conversionService);
when(messageGroupMock.getMessages()).thenReturn(messagesUpForProcessing);
Object result = processor.processMessageGroup(messageGroupMock);
assertThat(((Message<?>) result).getPayload(), is(7));
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-integration by spring-projects.
the class GatewayProxyFactoryBeanTests method testRequestReplyWithAnonymousChannelConvertedTypeViaConversionService.
@Test
public void testRequestReplyWithAnonymousChannelConvertedTypeViaConversionService() throws Exception {
QueueChannel requestChannel = new QueueChannel();
startResponder(requestChannel);
GenericConversionService cs = new DefaultConversionService();
Converter<String, byte[]> stringToByteConverter = new Converter<String, byte[]>() {
@Override
public byte[] convert(String source) {
return source.getBytes();
}
};
stringToByteConverter = spy(stringToByteConverter);
cs.addConverter(stringToByteConverter);
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, cs);
proxyFactory.setBeanFactory(bf);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
byte[] result = service.requestReplyInBytes("foo");
assertEquals(6, result.length);
Mockito.verify(stringToByteConverter, Mockito.times(1)).convert(Mockito.any(String.class));
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-integration by spring-projects.
the class DefaultHttpHeaderMapperFromMessageInboundTests method validateCustomHeadersWithNonStringValuesAndDefaultConverterWithCustomConverter.
@Test
public void validateCustomHeadersWithNonStringValuesAndDefaultConverterWithCustomConverter() throws Exception {
DefaultHttpHeaderMapper mapper = new DefaultHttpHeaderMapper();
mapper.setOutboundHeaderNames(new String[] { "customHeader*" });
GenericConversionService cs = new DefaultConversionService();
cs.addConverter(new TestClassConverter());
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("integrationConversionService", cs);
mapper.setBeanFactory(beanFactory);
mapper.afterPropertiesSet();
HttpHeaders headers = new HttpHeaders();
Map<String, Object> messageHeaders = new HashMap<String, Object>();
messageHeaders.put("customHeaderA", 123);
messageHeaders.put("customHeaderB", new TestClass());
mapper.fromHeaders(new MessageHeaders(messageHeaders), headers);
assertNotNull(headers.get("customHeaderA"));
assertEquals("123", headers.get("customHeaderA").get(0));
assertNotNull(headers.get("customHeaderB"));
assertEquals("TestClass.class", headers.get("customHeaderB").get(0));
}
Aggregations