From 95b3c4e47b13487c9a2d56e3242739106f19399e Mon Sep 17 00:00:00 2001 From: Marius Bogoevici Date: Wed, 9 Dec 2015 14:21:09 -0500 Subject: [PATCH] Change test binder to always override existing binders --- spring-cloud-stream-test-support/pom.xml | 5 ++++ .../TestSupportBinderAutoConfiguration.java | 26 ++++++++++++++----- .../main/resources/META-INF/spring.factories | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories diff --git a/spring-cloud-stream-test-support/pom.xml b/spring-cloud-stream-test-support/pom.xml index 97d478e43..152f811ed 100644 --- a/spring-cloud-stream-test-support/pom.xml +++ b/spring-cloud-stream-test-support/pom.xml @@ -22,6 +22,11 @@ org.springframework.cloud spring-cloud-stream + + org.springframework.cloud + spring-cloud-stream-binder-redis + test + org.springframework.boot spring-boot-autoconfigure diff --git a/spring-cloud-stream-test-support/src/main/java/org/springframework/cloud/stream/test/binder/TestSupportBinderAutoConfiguration.java b/spring-cloud-stream-test-support/src/main/java/org/springframework/cloud/stream/test/binder/TestSupportBinderAutoConfiguration.java index b6033e1c3..617c28f77 100644 --- a/spring-cloud-stream-test-support/src/main/java/org/springframework/cloud/stream/test/binder/TestSupportBinderAutoConfiguration.java +++ b/spring-cloud-stream-test-support/src/main/java/org/springframework/cloud/stream/test/binder/TestSupportBinderAutoConfiguration.java @@ -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 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 binderFactory) { + return ((TestSupportBinder) binderFactory.getBinder(null)).messageCollector(); } } diff --git a/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories b/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..5ce24e778 --- /dev/null +++ b/spring-cloud-stream-test-support/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration:\ +org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration \ No newline at end of file