From 85b34be7336e3d320caf016aa1965d09940c18d4 Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Tue, 7 Aug 2018 17:17:22 -0400 Subject: [PATCH] Spring Boot 2.1 - further updates Update more tests with bean overriding errors where they try to override the `BinderTypeRegistry` bean. This is not very common in end user applications unless they are trying to define a new binder type. If that is indeed the case, then they have to set `spring.main.allow-bean-definition-overriding` to `true`. Remove where we define the bean `integrationArgumentResolverMessageConverter` in `ContentTypeConfiguration` as this causes a conflict with the same bean from Spring Integration and thus causing bean overriding exception. Insted of creating this through `@Bean`, manually register the bean after removing it from `BeanDefinitionRegistry`. --- .../config/ContentTypeConfiguration.java | 44 ++++++++++++++++--- ...traryInterfaceWithBindingTargetsTests.java | 3 +- .../ArbitraryInterfaceWithDefaultsTests.java | 3 +- .../BinderAwareChannelResolverTests.java | 2 +- .../stream/binder/ErrorBindingTests.java | 6 +++ .../binder/InputOutputBindingOrderTest.java | 6 +++ .../stream/binder/LifecycleBinderTests.java | 6 +++ .../stream/binder/PollableConsumerTests.java | 1 + ...ocessorBindingWithBindingTargetsTests.java | 3 +- .../ProcessorBindingsWithDefaultsTests.java | 3 +- .../SinkBindingWithDefaultTargetsTests.java | 3 +- .../binder/SinkBindingWithDefaultsTests.java | 3 +- .../SourceBindingWithBindingTargetsTests.java | 3 +- .../SourceBindingWithDefaultsTests.java | 9 +++- ...ceBindingWithGlobalPropertiesOnlyTest.java | 2 +- ...SourceBindingWithGlobalPropertiesTest.java | 3 +- .../binder/tck/ContentTypeTckTests.java | 6 +++ .../CustomPartitionedProducerTest.java | 8 ++-- .../InvalidBindingConfigurationTests.java | 16 +++---- ...ExpressionConverterConfigurationTests.java | 3 +- .../BoundChannelsInterceptedTest.java | 3 +- .../partitioning/PartitionedConsumerTest.java | 3 +- 22 files changed, 107 insertions(+), 32 deletions(-) diff --git a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java index d1fb4dce9..872d57991 100644 --- a/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java +++ b/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/ContentTypeConfiguration.java @@ -22,10 +22,14 @@ import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.cloud.stream.annotation.StreamMessageConverter; import org.springframework.cloud.stream.converter.CompositeMessageConverterFactory; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Role; @@ -39,11 +43,14 @@ import org.springframework.util.CollectionUtils; */ @Configuration @Role(BeanDefinition.ROLE_INFRASTRUCTURE) -public class ContentTypeConfiguration { +public class ContentTypeConfiguration implements InitializingBean { @Autowired(required = false) private ObjectMapper objectMapper; + @Autowired + private ConfigurableApplicationContext context; + /** * User defined custom message converters */ @@ -51,17 +58,42 @@ public class ContentTypeConfiguration { @StreamMessageConverter private List customMessageConverters; + @Override + public void afterPropertiesSet() throws Exception { + if (context.getBeanFactory().containsBean(IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME)) { + BeanDefinitionRegistry beanDefinitionRegistry = + (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory(); + beanDefinitionRegistry.removeBeanDefinition(IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME); + } + } + @Bean + @SuppressWarnings("unchecked") public CompositeMessageConverterFactory compositeMessageConverterFactory() { List messageConverters = new ArrayList<>(); if (!CollectionUtils.isEmpty(this.customMessageConverters)) { messageConverters.addAll(Collections.unmodifiableCollection(this.customMessageConverters)); } - return new CompositeMessageConverterFactory(messageConverters, this.objectMapper); + CompositeMessageConverterFactory compositeMessageConverterFactory = new CompositeMessageConverterFactory(messageConverters, this.objectMapper); + + // Manually register a bean named as `integrationArgumentResolverMessageConverter` + // in order to avoid bean name overriding exceptions. This name exists in Spring Integration. + // The afterProperties method should have removed the bean from the registry and then + // we are re-registering it again through a different bean definition. + BeanDefinitionRegistry beanDefinitionRegistry = + (BeanDefinitionRegistry) context.getAutowireCapableBeanFactory(); + + ConfigurableCompositeMessageConverter configurableCompositeMessageConverter = + new ConfigurableCompositeMessageConverter(compositeMessageConverterFactory.getMessageConverterForAllRegistered().getConverters()); + + BeanDefinition configurableCompositeMessageConverterDefn = + BeanDefinitionBuilder.genericBeanDefinition((Class) configurableCompositeMessageConverter.getClass(), + () -> configurableCompositeMessageConverter) + .getRawBeanDefinition(); + + beanDefinitionRegistry.registerBeanDefinition(IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME, configurableCompositeMessageConverterDefn); + + return compositeMessageConverterFactory; } - @Bean(name = IntegrationContextUtils.ARGUMENT_RESOLVER_MESSAGE_CONVERTER_BEAN_NAME) - public ConfigurableCompositeMessageConverter configurableCompositeMessageConverter(CompositeMessageConverterFactory factory){ - return new ConfigurableCompositeMessageConverter(factory.getMessageConverterForAllRegistered().getConverters()); - } } diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithBindingTargetsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithBindingTargetsTests.java index 66623ac1a..31ba9896d 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithBindingTargetsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithBindingTargetsTests.java @@ -40,7 +40,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ArbitraryInterfaceWithBindingTargetsTests.TestFooChannels.class) +@SpringBootTest(classes = ArbitraryInterfaceWithBindingTargetsTests.TestFooChannels.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class ArbitraryInterfaceWithBindingTargetsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithDefaultsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithDefaultsTests.java index 43d2f579f..6606887a1 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithDefaultsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ArbitraryInterfaceWithDefaultsTests.java @@ -39,7 +39,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ArbitraryInterfaceWithDefaultsTests.TestFooChannels.class) +@SpringBootTest(classes = ArbitraryInterfaceWithDefaultsTests.TestFooChannels.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class ArbitraryInterfaceWithDefaultsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/BinderAwareChannelResolverTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/BinderAwareChannelResolverTests.java index 2005bc387..58ebd7c43 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/BinderAwareChannelResolverTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/BinderAwareChannelResolverTests.java @@ -94,7 +94,7 @@ public class BinderAwareChannelResolverTests { @SuppressWarnings("unchecked") @Before public void setupContext() throws Exception { - //System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); this.context = new SpringApplicationBuilder(TestChannelBinderConfiguration.getCompleteConfiguration(BinderAwareChannelResolverTests.InterceptorConfiguration.class)) .web(WebApplicationType.NONE).run(); diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ErrorBindingTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ErrorBindingTests.java index d99075413..cc862f0fb 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ErrorBindingTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ErrorBindingTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.stream.binder; +import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -37,6 +38,11 @@ import static org.mockito.ArgumentMatchers.isNull; */ public class ErrorBindingTests { + @Before + public void before() { + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + } + @SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testErrorChannelNotBoundByDefault() { diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java index 79a1ccf65..7ebcd5efd 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/InputOutputBindingOrderTest.java @@ -16,6 +16,7 @@ package org.springframework.cloud.stream.binder; +import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -45,6 +46,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; */ public class InputOutputBindingOrderTest { + @Before + public void before() { + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + } + @SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testInputOutputBindingOrder() { diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/LifecycleBinderTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/LifecycleBinderTests.java index 309a54ee7..dbfaf575e 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/LifecycleBinderTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/LifecycleBinderTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.stream.binder; +import org.junit.Before; import org.junit.Test; import org.springframework.boot.SpringApplication; @@ -36,6 +37,11 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class LifecycleBinderTests { + @Before + public void before() { + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + } + @Test public void testOnlySmartLifecyclesStarted() { ConfigurableApplicationContext applicationContext = SpringApplication.run(TestSource.class, "--server.port=-1"); diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/PollableConsumerTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/PollableConsumerTests.java index fa2de2ea3..5f1805041 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/PollableConsumerTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/PollableConsumerTests.java @@ -63,6 +63,7 @@ public class PollableConsumerTests { @Before public void before() { + //System.setProperty("spring.main.allow-bean-definition-overriding", "true"); this.messageConverter = new CompositeMessageConverterFactory().getMessageConverterForAllRegistered(); } diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingWithBindingTargetsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingWithBindingTargetsTests.java index 1f68f591a..fdfcfb482 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingWithBindingTargetsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingWithBindingTargetsTests.java @@ -40,7 +40,8 @@ import static org.mockito.Mockito.verify; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ProcessorBindingWithBindingTargetsTests.TestProcessor.class) +@SpringBootTest(classes = ProcessorBindingWithBindingTargetsTests.TestProcessor.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class ProcessorBindingWithBindingTargetsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingsWithDefaultsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingsWithDefaultsTests.java index 35687664c..3913405f5 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingsWithDefaultsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/ProcessorBindingsWithDefaultsTests.java @@ -39,7 +39,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = ProcessorBindingsWithDefaultsTests.TestProcessor.class) +@SpringBootTest(classes = ProcessorBindingsWithDefaultsTests.TestProcessor.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class ProcessorBindingsWithDefaultsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultTargetsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultTargetsTests.java index 1376b21a1..f47a79b70 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultTargetsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultTargetsTests.java @@ -42,7 +42,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = SinkBindingWithDefaultTargetsTests.TestSink.class) +@SpringBootTest(classes = SinkBindingWithDefaultTargetsTests.TestSink.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class SinkBindingWithDefaultTargetsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultsTests.java index 9d1f74c6a..3d092c6aa 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SinkBindingWithDefaultsTests.java @@ -40,7 +40,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = SinkBindingWithDefaultsTests.TestSink.class) +@SpringBootTest(classes = SinkBindingWithDefaultsTests.TestSink.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class SinkBindingWithDefaultsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithBindingTargetsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithBindingTargetsTests.java index b4b3cd23f..7c4cae9a9 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithBindingTargetsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithBindingTargetsTests.java @@ -43,7 +43,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Ilayaperumal Gopinathan */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = SourceBindingWithBindingTargetsTests.TestSource.class) +@SpringBootTest(classes = SourceBindingWithBindingTargetsTests.TestSource.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class SourceBindingWithBindingTargetsTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithDefaultsTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithDefaultsTests.java index b3ead9720..6f37df4bb 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithDefaultsTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithDefaultsTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.stream.binder; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -38,7 +39,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Marius Bogoevici */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = SourceBindingWithDefaultsTests.TestSource.class) +@SpringBootTest(classes = SourceBindingWithDefaultsTests.TestSource.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class SourceBindingWithDefaultsTests { @Autowired @@ -47,6 +49,11 @@ public class SourceBindingWithDefaultsTests { @Autowired private Source testSource; + @Before + public void before() { + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + } + @SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testSourceOutputChannelBound() { diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesOnlyTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesOnlyTest.java index a774b4519..cce522c42 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesOnlyTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesOnlyTest.java @@ -38,7 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = {TestChannelBinderConfiguration.class, SourceBindingWithGlobalPropertiesOnlyTest.TestSource.class, SpelExpressionConverterConfiguration.class}, properties = {"spring.cloud.stream.default.contentType=application/json", - "spring.cloud.stream.default.producer.partitionKeyExpression=key" }) + "spring.cloud.stream.default.producer.partitionKeyExpression=key"}) public class SourceBindingWithGlobalPropertiesOnlyTest { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesTest.java index b7a969fec..ecca0f50a 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/SourceBindingWithGlobalPropertiesTest.java @@ -44,7 +44,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; "spring.cloud.stream.default.producer.requiredGroups=someGroup", "spring.cloud.stream.default.producer.partitionCount=1", "spring.cloud.stream.bindings.output.producer.headerMode=none", - "spring.cloud.stream.bindings.output.producer.partitionCount=4"}) + "spring.cloud.stream.bindings.output.producer.partitionCount=4", + "spring.main.allow-bean-definition-overriding=true"}) public class SourceBindingWithGlobalPropertiesTest { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java index deb49369b..bf2a43210 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binder/tck/ContentTypeTckTests.java @@ -23,6 +23,7 @@ import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; import org.junit.Test; import org.springframework.boot.WebApplicationType; @@ -73,6 +74,11 @@ import static org.junit.Assert.assertTrue; */ public class ContentTypeTckTests { + @Before + public void before() { + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + } + @Test public void stringToMapStreamListener() { ApplicationContext context = new SpringApplicationBuilder(StringToMapStreamListener.class) diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java index ffbd9a4da..9755d9df0 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/CustomPartitionedProducerTest.java @@ -56,7 +56,8 @@ public class CustomPartitionedProducerTest { "--spring.jmx.enabled=false", "--spring.main.web-application-type=none", "--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorClass=org.springframework.cloud.stream.partitioning.CustomPartitionKeyExtractorClass", - "--spring.cloud.stream.bindings.output.producer.partitionSelectorClass=org.springframework.cloud.stream.partitioning.CustomPartitionSelectorClass"); + "--spring.cloud.stream.bindings.output.producer.partitionSelectorClass=org.springframework.cloud.stream.partitioning.CustomPartitionSelectorClass", + "--spring.main.allow-bean-definition-overriding=true"); Source testSource = context.getBean(Source.class); DirectChannel messageChannel = (DirectChannel) testSource.output(); for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) { @@ -87,7 +88,8 @@ public class CustomPartitionedProducerTest { "--spring.jmx.enabled=false", "--spring.main.web-application-type=none", "--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorName=customPartitionKeyExtractor", - "--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelector"); + "--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelector", + "--spring.main.allow-bean-definition-overriding=true"); Source testSource = context.getBean(Source.class); DirectChannel messageChannel = (DirectChannel) testSource.output(); for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) { @@ -115,7 +117,7 @@ public class CustomPartitionedProducerTest { @Test public void testCustomPartitionedProducerAsSingletons() { ApplicationContext context = SpringApplication.run(CustomPartitionedProducerTest.TestSource.class, - "--spring.jmx.enabled=false", "--spring.main.web-application-type=none"); + "--spring.jmx.enabled=false", "--spring.main.web-application-type=none", "--spring.main.allow-bean-definition-overriding=true"); Source testSource = context.getBean(Source.class); DirectChannel messageChannel = (DirectChannel) testSource.output(); for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) { diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/InvalidBindingConfigurationTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/InvalidBindingConfigurationTests.java index b21e441b2..006978bb9 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/InvalidBindingConfigurationTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/binding/InvalidBindingConfigurationTests.java @@ -16,7 +16,7 @@ package org.springframework.cloud.stream.binding; -import org.assertj.core.api.ThrowableAssert; +import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -39,17 +39,15 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; */ public class InvalidBindingConfigurationTests { + @Before + public void before() { + System.setProperty("spring.main.allow-bean-definition-overriding", "true"); + } + @Test public void testDuplicateBeanByBindingConfig() { assertThatThrownBy( - new ThrowableAssert.ThrowingCallable() { - - @Override - public void call() throws Throwable { - SpringApplication.run(TestBindingConfig.class); - } - - }) + () -> SpringApplication.run(TestBindingConfig.class)) .isInstanceOf(BeanDefinitionStoreException.class) .hasMessageContaining("bean definition with this name already exists") .hasMessageContaining(TestInvalidBinding.NAME) diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java index c00e2b629..1504a9244 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/config/SpelExpressionConverterConfigurationTests.java @@ -53,7 +53,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = SpelExpressionConverterConfigurationTests.Config.class, properties = "expression: a.b") +@SpringBootTest(classes = SpelExpressionConverterConfigurationTests.Config.class, + properties = {"expression: a.b", "spring.main.allow-bean-definition-overriding=true"}) public class SpelExpressionConverterConfigurationTests { @Autowired diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java index a54fb8a78..ffad8e22e 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/interceptor/BoundChannelsInterceptedTest.java @@ -48,7 +48,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Oleg Zhurakousky */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = BoundChannelsInterceptedTest.Foo.class) +@SpringBootTest(classes = BoundChannelsInterceptedTest.Foo.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class BoundChannelsInterceptedTest { public static final Message TEST_MESSAGE = MessageBuilder.withPayload("bar").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build(); diff --git a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java index bd08d563b..4974438d1 100644 --- a/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java +++ b/spring-cloud-stream/src/test/java/org/springframework/cloud/stream/partitioning/PartitionedConsumerTest.java @@ -49,7 +49,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; * @author Janne Valkealahti */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = PartitionedConsumerTest.TestSink.class) +@SpringBootTest(classes = PartitionedConsumerTest.TestSink.class, + properties = "spring.main.allow-bean-definition-overriding=true") public class PartitionedConsumerTest { @Autowired