Change test binder to always override existing binders
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration:\
|
||||
org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration
|
||||
Reference in New Issue
Block a user