use of org.springframework.integration.handler.MethodInvokingMessageProcessor in project spring-integration by spring-projects.
the class BeanFactoryTypeConverterTests method testMapOfMapOfCollectionIsConverted.
@SuppressWarnings("unchecked")
@Test
public void testMapOfMapOfCollectionIsConverted() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<Foo, Bar>() {
@Override
public Bar convert(Foo source) {
return new Bar();
}
});
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter(conversionService);
beanFactory.setConversionService(conversionService);
typeConverter.setBeanFactory(beanFactory);
Map<String, Map<String, Set<Foo>>> foos;
Map<String, Map<String, Set<Bar>>> bars;
TypeDescriptor sourceType = TypeDescriptor.map(Map.class, null, null);
TypeDescriptor targetType = TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class), TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class), TypeDescriptor.collection(Set.class, TypeDescriptor.valueOf(Bar.class))));
Set<Foo> fooSet = new HashSet<Foo>();
fooSet.add(new Foo());
Map<String, Set<Foo>> fooMap = new HashMap<String, Set<Foo>>();
fooMap.put("foo", fooSet);
foos = new HashMap<String, Map<String, Set<Foo>>>();
foos.put("foo", fooMap);
bars = (Map<String, Map<String, Set<Bar>>>) typeConverter.convertValue(foos, sourceType, targetType);
assertThat(bars.get("foo").get("foo").iterator().next(), instanceOf(Bar.class));
Service service = new Service();
MethodInvokingMessageProcessor<Service> processor = new MethodInvokingMessageProcessor<>(service, "handle");
processor.setConversionService(conversionService);
processor.setUseSpelInvoker(true);
ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
QueueChannel replyChannel = new QueueChannel();
handler.setOutputChannel(replyChannel);
handler.handleMessage(new GenericMessage<Map<String, Map<String, Set<Foo>>>>(foos));
Message<?> message = replyChannel.receive(0);
assertNotNull(message);
assertEquals("bar", message.getPayload());
}
use of org.springframework.integration.handler.MethodInvokingMessageProcessor in project spring-integration by spring-projects.
the class BeanFactoryTypeConverterTests method testCollectionIsConverted.
@Test
public void testCollectionIsConverted() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<Foo, Bar>() {
@Override
public Bar convert(Foo source) {
return new Bar();
}
});
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter(conversionService);
beanFactory.setConversionService(conversionService);
typeConverter.setBeanFactory(beanFactory);
Service service = new Service();
MethodInvokingMessageProcessor<Service> processor = new MethodInvokingMessageProcessor<>(service, "handle");
processor.setConversionService(conversionService);
processor.setUseSpelInvoker(true);
ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
QueueChannel replyChannel = new QueueChannel();
handler.setOutputChannel(replyChannel);
handler.handleMessage(new GenericMessage<Collection<Foo>>(Collections.singletonList(new Foo())));
Message<?> message = replyChannel.receive(10000);
assertNotNull(message);
assertEquals("baz", message.getPayload());
}
use of org.springframework.integration.handler.MethodInvokingMessageProcessor in project spring-integration by spring-projects.
the class MethodInvokingTransformerTests method headerEnricherConfiguredWithMethodName.
@SuppressWarnings({ "rawtypes", "unchecked" })
// this changed in 2.0 see INT-785 and INT-1130
@Test
public void headerEnricherConfiguredWithMethodName() throws Exception {
TestBean testBean = new TestBean();
HeaderEnricher transformer = new HeaderEnricher();
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testBean, "propertyEnricherTest");
transformer.setMessageProcessor(processor);
transformer.setDefaultOverwrite(true);
Message<String> message = MessageBuilder.withPayload("test").setHeader("prop1", "bad").setHeader("prop3", "baz").build();
Message<?> result = transformer.transform(message);
assertEquals("test", result.getPayload());
assertEquals("foo", result.getHeaders().get("prop1"));
assertEquals("bar", result.getHeaders().get("prop2"));
assertEquals("baz", result.getHeaders().get("prop3"));
}
use of org.springframework.integration.handler.MethodInvokingMessageProcessor in project spring-integration by spring-projects.
the class MethodInvokingTransformerTests method headerEnricherConfiguredWithMethodReference.
@SuppressWarnings({ "rawtypes", "unchecked" })
// this changed in 2.0 see INT-785 and INT-1130
@Test
public void headerEnricherConfiguredWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method testMethod = testBean.getClass().getMethod("propertyEnricherTest", String.class);
HeaderEnricher transformer = new HeaderEnricher();
transformer.setDefaultOverwrite(true);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testBean, testMethod);
transformer.setMessageProcessor(processor);
Message<String> message = MessageBuilder.withPayload("test").setHeader("prop1", "bad").setHeader("prop3", "baz").build();
Message<?> result = transformer.transform(message);
assertEquals("test", result.getPayload());
assertEquals("foo", result.getHeaders().get("prop1"));
assertEquals("bar", result.getHeaders().get("prop2"));
assertEquals("baz", result.getHeaders().get("prop3"));
}
Aggregations