GH-1191: Add test support for pollable sources

This commit is contained in:
Gary Russell
2018-01-24 11:12:08 -05:00
parent d5bfddc7fc
commit b12480c487

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -415,8 +415,7 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
protected abstract PP createProducerProperties();
protected final BindingProperties createConsumerBindingProperties(
CP consumerProperties) {
protected final BindingProperties createConsumerBindingProperties(CP consumerProperties) {
BindingProperties bindingProperties = new BindingProperties();
bindingProperties.setConsumer(consumerProperties);
return bindingProperties;
@@ -436,19 +435,10 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
protected DirectChannel createBindableChannel(String channelName,
BindingProperties bindingProperties, boolean inputChannel) throws Exception {
BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
bindingServiceProperties.getBindings().put(channelName, bindingProperties);
ConfigurableApplicationContext applicationContext = new GenericApplicationContext();
applicationContext.refresh();
bindingServiceProperties.setApplicationContext(applicationContext);
bindingServiceProperties.setConversionService(new DefaultConversionService());
bindingServiceProperties.afterPropertiesSet();
MessageConverterConfigurer messageConverterConfigurer = createConverterConfigurer(channelName,
bindingProperties);
DirectChannel channel = new DirectChannel();
channel.setBeanName(channelName);
MessageConverterConfigurer messageConverterConfigurer = new MessageConverterConfigurer(
bindingServiceProperties,
new CompositeMessageConverterFactory(null, null));
messageConverterConfigurer.setBeanFactory(applicationContext.getBeanFactory());
if (inputChannel) {
messageConverterConfigurer.configureInputChannel(channel, channelName);
}
@@ -458,6 +448,29 @@ public abstract class AbstractBinderTests<B extends AbstractTestBinder<? extends
return channel;
}
protected DefaultPollableMessageSource createBindableMessageSource(String bindingName,
BindingProperties bindingProperties) throws Exception {
DefaultPollableMessageSource source = new DefaultPollableMessageSource();
createConverterConfigurer(bindingName, bindingProperties).configurePolledMessageSource(source, bindingName);
return source;
}
private MessageConverterConfigurer createConverterConfigurer(String channelName,
BindingProperties bindingProperties) throws Exception {
BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
bindingServiceProperties.getBindings().put(channelName, bindingProperties);
ConfigurableApplicationContext applicationContext = new GenericApplicationContext();
applicationContext.refresh();
bindingServiceProperties.setApplicationContext(applicationContext);
bindingServiceProperties.setConversionService(new DefaultConversionService());
bindingServiceProperties.afterPropertiesSet();
MessageConverterConfigurer messageConverterConfigurer = new MessageConverterConfigurer(
bindingServiceProperties,
new CompositeMessageConverterFactory(null, null));
messageConverterConfigurer.setBeanFactory(applicationContext.getBeanFactory());
return messageConverterConfigurer;
}
@After
public void cleanup() {
if (testBinder != null) {