Change test binder to always override existing binders

This commit is contained in:
Marius Bogoevici
2015-12-09 14:21:09 -05:00
parent 96f96f7621
commit 95b3c4e47b
3 changed files with 26 additions and 7 deletions

View File

@@ -22,6 +22,11 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-redis</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>

View File

@@ -18,30 +18,42 @@ package org.springframework.cloud.stream.test.binder;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.cloud.stream.binder.BinderFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.messaging.MessageChannel;
/**
* Installs the {@link TestSupportBinder} and exposes {@link TestSupportBinder.MessageCollectorImpl} to be injected in tests.
* Installs the {@link TestSupportBinder} and exposes {@link TestSupportBinder.MessageCollectorImpl} to be injected in
* tests.
*
* Note that this auto-configuration has higher priority than regular binders, so adding
* this on the classpath in test scope is sufficient to have support kick in.
* Note that this auto-configuration has higher priority than regular binder configuration, so adding
* this on the classpath in test scope is sufficient to have support kick in and replace all binders
* with the test binder.
*
* @author Eric Bottard
* @author Marius Bogoevici
*/
@Configuration
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
public class TestSupportBinderAutoConfiguration {
private Binder<MessageChannel> messageChannelBinder = new TestSupportBinder();
@Bean
public MessageCollector messageCollector() {
return testSupportBinder().messageCollector();
public BinderFactory binderFactory() {
return new BinderFactory() {
@Override
public Binder getBinder(String configurationName) {
return messageChannelBinder;
}
};
}
@Bean
public TestSupportBinder testSupportBinder() {
return new TestSupportBinder();
public MessageCollector messageCollector(BinderFactory<MessageChannel> binderFactory) {
return ((TestSupportBinder) binderFactory.getBinder(null)).messageCollector();
}
}

View File

@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration:\
org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration