Spring Boot 2.1 upgrade
* Removed MockBinderRegistryConfiguration * Move necessary beans from `BindingServiceConfiguration` which is now auto configurable into `BinderFactoryConfiguration` that is invoked by `EnableBinding` in order to avoid certain cyclic dependency issues. The beans moved are binding target factories of type `MessageSourceBindingTargetFactory` and `SubscribableChannelBindingTargetFactory` and their dependencies. As a side effect, `ContentTypeConfiguration` is also brought back at the `EnableBinding` level through `BinderFactoryConfiguration`. * Restore `ServerController` bean in SchemaServerConfiguation as the removal of it earlier introduced some connectivity issues with the schema registry server. * Update copyrights
This commit is contained in:
committed by
Oleg Zhurakousky
parent
776fe5da77
commit
c85660fba2
@@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder;
|
||||
@@ -32,8 +31,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@@ -41,15 +38,13 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
* @author Ilayaperumal Gopinathan
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext
|
||||
public class AggregateApplicationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAggregateApplication() throws Exception {
|
||||
ConfigurableApplicationContext context = new AggregateApplicationBuilder(
|
||||
FooConfig.class).web(false).from(TestSource.class).to(TestProcessor.class).run();
|
||||
AggregateApplicationTestConfig.class).web(false).from(TestSource.class).to(TestProcessor.class).run();
|
||||
TestSupportBinder testSupportBinder = (TestSupportBinder) context.getBean(BinderFactory.class).getBinder(null,
|
||||
MessageChannel.class);
|
||||
MessageChannel processorOutput = testSupportBinder.getChannelForName("output");
|
||||
@@ -63,7 +58,7 @@ public class AggregateApplicationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class FooConfig{
|
||||
static class AggregateApplicationTestConfig {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.stream.schema.server.controllers.ServerController;
|
||||
import org.springframework.cloud.stream.schema.server.model.Schema;
|
||||
import org.springframework.cloud.stream.schema.server.repository.SchemaRepository;
|
||||
import org.springframework.cloud.stream.schema.server.support.AvroSchemaValidator;
|
||||
@@ -57,6 +58,12 @@ public class SchemaServerConfiguration {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServerController serverController(SchemaRepository repository,
|
||||
SchemaServerProperties schemeServerProperties) {
|
||||
return new ServerController(repository, schemaValidators(), schemeServerProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Map<String, SchemaValidator> schemaValidators() {
|
||||
Map<String, SchemaValidator> validatorMap = new HashMap<>();
|
||||
|
||||
@@ -44,7 +44,8 @@ import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
|
||||
properties = "spring.main.allow-bean-definition-overriding=true")
|
||||
@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD)
|
||||
public class SchemaRegistryServerAvroTests {
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ public class AvroMessageConverterSerializationTests {
|
||||
@Before
|
||||
public void setup() {
|
||||
schemaRegistryServerContext = SpringApplication
|
||||
.run(SchemaRegistryServerApplication.class);
|
||||
.run(SchemaRegistryServerApplication.class, "--spring.main.allow-bean-definition-overriding=true");
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -60,7 +60,7 @@ public class AvroSchemaRegistryClientMessageConverterTests {
|
||||
public void testSendMessage() throws Exception {
|
||||
|
||||
ConfigurableApplicationContext schemaRegistryServerContext = SpringApplication.run(
|
||||
SchemaRegistryServerApplication.class);
|
||||
SchemaRegistryServerApplication.class, "--spring.main.allow-bean-definition-overriding=true");
|
||||
|
||||
ConfigurableApplicationContext sourceContext = SpringApplication.run(AvroSourceApplication.class,
|
||||
"--server.port=0",
|
||||
|
||||
@@ -39,7 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* correctly.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = ExampleTest.MyProcessor.class, properties = { "server.port=-1",
|
||||
@SpringBootTest(classes = ExampleTest.MyProcessor.class, webEnvironment = SpringBootTest.WebEnvironment.NONE,
|
||||
properties = {
|
||||
"--spring.cloud.stream.bindings.input.contentType=text/plain",
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain"})
|
||||
@DirtiesContext
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
* Copyright 2015-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.
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -30,19 +31,32 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.stream.binder.BinderType;
|
||||
import org.springframework.cloud.stream.binder.BinderTypeRegistry;
|
||||
import org.springframework.cloud.stream.binder.DefaultBinderFactory;
|
||||
import org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry;
|
||||
import org.springframework.cloud.stream.binding.CompositeMessageChannelConfigurer;
|
||||
import org.springframework.cloud.stream.binding.MessageChannelConfigurer;
|
||||
import org.springframework.cloud.stream.binding.MessageConverterConfigurer;
|
||||
import org.springframework.cloud.stream.binding.MessageSourceBindingTargetFactory;
|
||||
import org.springframework.cloud.stream.binding.SubscribableChannelBindingTargetFactory;
|
||||
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.Import;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.handler.support.HandlerMethodArgumentResolversHolder;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -54,6 +68,8 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
@Configuration
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@EnableConfigurationProperties({ BindingServiceProperties.class })
|
||||
@Import({ContentTypeConfiguration.class})
|
||||
public class BinderFactoryConfiguration {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
@@ -114,4 +130,40 @@ public class BinderFactoryConfiguration {
|
||||
}
|
||||
return new DefaultBinderTypeRegistry(binderTypes);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageConverterConfigurer messageConverterConfigurer(BindingServiceProperties bindingServiceProperties,
|
||||
CompositeMessageConverterFactory compositeMessageConverterFactory) {
|
||||
return new MessageConverterConfigurer(bindingServiceProperties, compositeMessageConverterFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SubscribableChannelBindingTargetFactory channelFactory(
|
||||
CompositeMessageChannelConfigurer compositeMessageChannelConfigurer) {
|
||||
return new SubscribableChannelBindingTargetFactory(compositeMessageChannelConfigurer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSourceBindingTargetFactory messageSourceFactory(CompositeMessageConverterFactory compositeMessageConverterFactory,
|
||||
CompositeMessageChannelConfigurer compositeMessageChannelConfigurer) {
|
||||
return new MessageSourceBindingTargetFactory(compositeMessageConverterFactory.getMessageConverterForAllRegistered(), compositeMessageChannelConfigurer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CompositeMessageChannelConfigurer compositeMessageChannelConfigurer(
|
||||
MessageConverterConfigurer messageConverterConfigurer) {
|
||||
List<MessageChannelConfigurer> configurerList = new ArrayList<>();
|
||||
configurerList.add(messageConverterConfigurer);
|
||||
return new CompositeMessageChannelConfigurer(configurerList);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static MessageHandlerMethodFactory messageHandlerMethodFactory(CompositeMessageConverterFactory compositeMessageConverterFactory,
|
||||
@Qualifier(IntegrationContextUtils.ARGUMENT_RESOLVERS_BEAN_NAME) HandlerMethodArgumentResolversHolder ahmar) {
|
||||
DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory();
|
||||
messageHandlerMethodFactory.setMessageConverter(compositeMessageConverterFactory.getMessageConverterForAllRegistered());
|
||||
messageHandlerMethodFactory.setCustomArgumentResolvers(ahmar.getResolvers());
|
||||
return messageHandlerMethodFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@@ -39,18 +38,12 @@ import org.springframework.cloud.stream.binding.AbstractBindingTargetFactory;
|
||||
import org.springframework.cloud.stream.binding.Bindable;
|
||||
import org.springframework.cloud.stream.binding.BinderAwareChannelResolver;
|
||||
import org.springframework.cloud.stream.binding.BindingService;
|
||||
import org.springframework.cloud.stream.binding.CompositeMessageChannelConfigurer;
|
||||
import org.springframework.cloud.stream.binding.ContextStartAfterRefreshListener;
|
||||
import org.springframework.cloud.stream.binding.DynamicDestinationsBindable;
|
||||
import org.springframework.cloud.stream.binding.InputBindingLifecycle;
|
||||
import org.springframework.cloud.stream.binding.MessageChannelConfigurer;
|
||||
import org.springframework.cloud.stream.binding.MessageChannelStreamListenerResultAdapter;
|
||||
import org.springframework.cloud.stream.binding.MessageConverterConfigurer;
|
||||
import org.springframework.cloud.stream.binding.MessageSourceBindingTargetFactory;
|
||||
import org.springframework.cloud.stream.binding.OutputBindingLifecycle;
|
||||
import org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor;
|
||||
import org.springframework.cloud.stream.binding.SubscribableChannelBindingTargetFactory;
|
||||
import org.springframework.cloud.stream.converter.CompositeMessageConverterFactory;
|
||||
import org.springframework.cloud.stream.micrometer.DestinationPublishingMetricsAutoConfiguration;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -60,15 +53,11 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Role;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.integration.config.GlobalChannelInterceptorProcessor;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.support.HandlerMethodArgumentResolversHolder;
|
||||
import org.springframework.integration.router.AbstractMappingMessageRouter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.core.DestinationResolver;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -88,7 +77,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({ BindingServiceProperties.class, SpringIntegrationProperties.class })
|
||||
@Import({ContentTypeConfiguration.class, DestinationPublishingMetricsAutoConfiguration.class, SpelExpressionConverterConfiguration.class})
|
||||
@Import({DestinationPublishingMetricsAutoConfiguration.class, SpelExpressionConverterConfiguration.class})
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnBean(value = BinderTypeRegistry.class, search = SearchStrategy.CURRENT)
|
||||
public class BindingServiceConfiguration {
|
||||
@@ -159,15 +148,6 @@ public class BindingServiceConfiguration {
|
||||
return new MessageChannelStreamListenerResultAdapter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static MessageHandlerMethodFactory messageHandlerMethodFactory(CompositeMessageConverterFactory compositeMessageConverterFactory,
|
||||
@Qualifier(IntegrationContextUtils.ARGUMENT_RESOLVERS_BEAN_NAME) HandlerMethodArgumentResolversHolder ahmar) {
|
||||
DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory();
|
||||
messageHandlerMethodFactory.setMessageConverter(compositeMessageConverterFactory.getMessageConverterForAllRegistered());
|
||||
messageHandlerMethodFactory.setCustomArgumentResolvers(ahmar.getResolvers());
|
||||
return messageHandlerMethodFactory;
|
||||
}
|
||||
|
||||
@Bean(name = STREAM_LISTENER_ANNOTATION_BEAN_POST_PROCESSOR_NAME)
|
||||
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
|
||||
public static StreamListenerAnnotationBeanPostProcessor streamListenerAnnotationBeanPostProcessor() {
|
||||
@@ -184,33 +164,6 @@ public class BindingServiceConfiguration {
|
||||
return new BindingService(bindingServiceProperties, binderFactory, taskScheduler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageConverterConfigurer messageConverterConfigurer(BindingServiceProperties bindingServiceProperties,
|
||||
CompositeMessageConverterFactory compositeMessageConverterFactory) {
|
||||
return new MessageConverterConfigurer(bindingServiceProperties, compositeMessageConverterFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SubscribableChannelBindingTargetFactory channelFactory(
|
||||
CompositeMessageChannelConfigurer compositeMessageChannelConfigurer) {
|
||||
return new SubscribableChannelBindingTargetFactory(compositeMessageChannelConfigurer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageSourceBindingTargetFactory messageSourceFactory(CompositeMessageConverterFactory compositeMessageConverterFactory,
|
||||
CompositeMessageChannelConfigurer compositeMessageChannelConfigurer) {
|
||||
return new MessageSourceBindingTargetFactory(compositeMessageConverterFactory.getMessageConverterForAllRegistered(), compositeMessageChannelConfigurer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public CompositeMessageChannelConfigurer compositeMessageChannelConfigurer(
|
||||
MessageConverterConfigurer messageConverterConfigurer) {
|
||||
List<MessageChannelConfigurer> configurerList = new ArrayList<>();
|
||||
configurerList.add(messageConverterConfigurer);
|
||||
return new CompositeMessageChannelConfigurer(configurerList);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@DependsOn("bindingService")
|
||||
public OutputBindingLifecycle outputBindingLifecycle(BindingService bindingService, Map<String, Bindable> bindables) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-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.
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.springframework.cloud.stream.binding.BindingTargetFactory;
|
||||
import org.springframework.cloud.stream.binding.SubscribableChannelBindingTargetFactory;
|
||||
import org.springframework.cloud.stream.messaging.Processor;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -77,9 +76,9 @@ public class AggregationTest {
|
||||
@Test
|
||||
public void aggregation() {
|
||||
aggregatedApplicationContext = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--server.port=0", "--debug=true",
|
||||
AggregationAppConfig.class,
|
||||
"--spring.cloud.stream.default-binder=mock")
|
||||
.web(false).from(TestSource.class).to(TestProcessor.class).run();
|
||||
.web(false).from(TestSource.class).to(TestProcessor.class).run();
|
||||
SharedBindingTargetRegistry sharedBindingTargetRegistry = aggregatedApplicationContext
|
||||
.getBean(SharedBindingTargetRegistry.class);
|
||||
BindingTargetFactory channelFactory = aggregatedApplicationContext
|
||||
@@ -93,9 +92,9 @@ public class AggregationTest {
|
||||
public void testModuleAggregationUsingSharedChannelRegistry() {
|
||||
// test backward compatibility
|
||||
aggregatedApplicationContext = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--server.port=0",
|
||||
AggregationAppConfig.class,
|
||||
"--spring.cloud.stream.default-binder=mock").web(false)
|
||||
.from(TestSource.class).to(TestProcessor.class).run();
|
||||
.from(TestSource.class).to(TestProcessor.class).run();
|
||||
SharedBindingTargetRegistry sharedChannelRegistry = aggregatedApplicationContext
|
||||
.getBean(SharedBindingTargetRegistry.class);
|
||||
BindingTargetFactory channelFactory = aggregatedApplicationContext
|
||||
@@ -113,14 +112,13 @@ public class AggregationTest {
|
||||
argsToVerify.add("--foo1=bar1");
|
||||
argsToVerify.add("--foo2=bar2");
|
||||
argsToVerify.add("--foo3=bar3");
|
||||
argsToVerify.add("--server.port=0");
|
||||
argsToVerify.add("--spring.cloud.stream.default-binder=mock");
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
MockBinderRegistryConfiguration.class, "--foo1=bar1");
|
||||
AggregationAppConfig.class, "--foo1=bar1");
|
||||
final ConfigurableApplicationContext context = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class, "--foo2=bar2").web(false)
|
||||
.from(TestSource.class).namespace("foo").to(TestProcessor.class)
|
||||
.namespace("bar").run("--foo3=bar3", "--server.port=0",
|
||||
.namespace("bar").run("--foo3=bar3",
|
||||
"--spring.cloud.stream.default-binder=mock");
|
||||
DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(
|
||||
aggregateApplicationBuilder);
|
||||
@@ -135,11 +133,11 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testParentArgsAndSourcesWithWebDisabled() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
MockBinderRegistryConfiguration.class, "--foo1=bar1");
|
||||
AggregationAppConfig.class, "--foo1=bar1");
|
||||
final ConfigurableApplicationContext context = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class, "--foo2=bar2").web(false)
|
||||
.from(TestSource.class).namespace("foo").to(TestProcessor.class)
|
||||
.namespace("bar").run("--server.port=0", "--spring.cloud.stream.default-binder=mock");
|
||||
.namespace("bar").run("--spring.cloud.stream.default-binder=mock");
|
||||
DirectFieldAccessor aggregateApplicationBuilderAccessor = new DirectFieldAccessor(
|
||||
aggregateApplicationBuilder);
|
||||
List<Object> sources = (List<Object>) aggregateApplicationBuilderAccessor
|
||||
@@ -147,7 +145,7 @@ public class AggregationTest {
|
||||
assertThat(sources).containsExactlyInAnyOrder(
|
||||
AggregateApplicationBuilder.ParentConfiguration.class,
|
||||
AggregateApplicationBuilder.ParentActuatorConfiguration.class,
|
||||
MockBinderRegistryConfiguration.class, DummyConfig.class);
|
||||
AggregationAppConfig.class, DummyConfig.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -155,7 +153,7 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNamespacePrefixesFromCmdLine() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
aggregatedApplicationContext = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class).web(false).from(TestSource.class)
|
||||
.namespace("a").via(TestProcessor.class).namespace("b")
|
||||
@@ -166,17 +164,17 @@ public class AggregationTest {
|
||||
assertTrue(Arrays.equals(
|
||||
((SourceConfigurer) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("sourceConfigurer")).getArgs(),
|
||||
new String[] { "--foo1=bar1" }));
|
||||
new String[]{"--foo1=bar1"}));
|
||||
final List<AggregateApplicationBuilder.ProcessorConfigurer> processorConfigurers = (List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("processorConfigurers");
|
||||
for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) {
|
||||
if (processorConfigurer.getNamespace().equals("b")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--foo1=bar2" }));
|
||||
new String[]{"--foo1=bar2"}));
|
||||
}
|
||||
if (processorConfigurer.getNamespace().equals("c")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--foo1=bar3" }));
|
||||
new String[]{"--foo1=bar3"}));
|
||||
}
|
||||
}
|
||||
aggregatedApplicationContext.close();
|
||||
@@ -186,7 +184,7 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNamespacePrefixesFromCmdLineVsArgs() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
aggregatedApplicationContext = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class).web(false).from(TestSource.class)
|
||||
.namespace("a").args("--fooValue=bar").via(TestProcessor.class)
|
||||
@@ -197,17 +195,17 @@ public class AggregationTest {
|
||||
assertTrue(Arrays.equals(
|
||||
((SourceConfigurer) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("sourceConfigurer")).getArgs(),
|
||||
new String[] { "--fooValue=bara" }));
|
||||
new String[]{"--fooValue=bara"}));
|
||||
final List<AggregateApplicationBuilder.ProcessorConfigurer> processorConfigurers = (List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("processorConfigurers");
|
||||
for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) {
|
||||
if (processorConfigurer.getNamespace().equals("b")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--foo1=argbarb" }));
|
||||
new String[]{"--foo1=argbarb"}));
|
||||
}
|
||||
if (processorConfigurer.getNamespace().equals("c")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--foo1=barc" }));
|
||||
new String[]{"--foo1=barc"}));
|
||||
}
|
||||
}
|
||||
aggregatedApplicationContext.close();
|
||||
@@ -217,7 +215,7 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNamespacePrefixesFromCmdLineWithRelaxedNames() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
aggregatedApplicationContext = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class).web(false).from(TestSource.class)
|
||||
.namespace("a").args("--foo-value=bar").via(TestProcessor.class)
|
||||
@@ -229,17 +227,17 @@ public class AggregationTest {
|
||||
assertTrue(Arrays.equals(
|
||||
((SourceConfigurer) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("sourceConfigurer")).getArgs(),
|
||||
new String[] { "--fooValue=bara" }));
|
||||
new String[]{"--fooValue=bara"}));
|
||||
final List<AggregateApplicationBuilder.ProcessorConfigurer> processorConfigurers = (List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("processorConfigurers");
|
||||
for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) {
|
||||
if (processorConfigurer.getNamespace().equals("b")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--foo-value=barb" }));
|
||||
new String[]{"--foo-value=barb"}));
|
||||
}
|
||||
if (processorConfigurer.getNamespace().equals("c")) {
|
||||
assertThat(processorConfigurer.getArgs(),
|
||||
is(new String[] { "--foo1=barc" }));
|
||||
is(new String[]{"--foo1=barc"}));
|
||||
}
|
||||
}
|
||||
aggregatedApplicationContext.close();
|
||||
@@ -249,10 +247,9 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNamespacePrefixesFromCmdLineWithRelaxedNamesAndMorePropertySources() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
System.setProperty("a.foo-value", "sysbara");
|
||||
System.setProperty("c.fooValue", "sysbarc");
|
||||
System.setProperty("server.port", "0");
|
||||
aggregatedApplicationContext = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class).web(false).from(TestSource.class)
|
||||
.namespace("a").args("--foo-value=bar").via(TestProcessor.class)
|
||||
@@ -263,17 +260,17 @@ public class AggregationTest {
|
||||
assertTrue(Arrays.equals(
|
||||
((SourceConfigurer) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("sourceConfigurer")).getArgs(),
|
||||
new String[] { "--fooValue=bara", "--foo-value=bara" }));
|
||||
new String[]{"--fooValue=bara", "--foo-value=bara"}));
|
||||
final List<AggregateApplicationBuilder.ProcessorConfigurer> processorConfigurers = (List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("processorConfigurers");
|
||||
for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) {
|
||||
if (processorConfigurer.getNamespace().equals("b")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--fooValue=argbarb" }));
|
||||
new String[]{"--fooValue=argbarb"}));
|
||||
}
|
||||
if (processorConfigurer.getNamespace().equals("c")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--fooValue=sysbarc" }));
|
||||
new String[]{"--fooValue=sysbarc"}));
|
||||
}
|
||||
}
|
||||
aggregatedApplicationContext.close();
|
||||
@@ -283,10 +280,9 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNamespacePrefixesWithoutCmdLinePropertySource() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
System.setProperty("a.foo-value", "sysbara");
|
||||
System.setProperty("c.fooValue", "sysbarc");
|
||||
System.setProperty("server.port", "0");
|
||||
aggregatedApplicationContext = aggregateApplicationBuilder
|
||||
.parent(DummyConfig.class).web(false).from(TestSource.class)
|
||||
.namespace("a").args("--foo-value=bar").via(TestProcessor.class)
|
||||
@@ -297,16 +293,16 @@ public class AggregationTest {
|
||||
assertTrue(Arrays.equals(
|
||||
((SourceConfigurer) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("sourceConfigurer")).getArgs(),
|
||||
new String[] { "--foo-value=sysbara" }));
|
||||
new String[]{"--foo-value=sysbara"}));
|
||||
for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : ((List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("processorConfigurers"))) {
|
||||
if (processorConfigurer.getNamespace().equals("b")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--fooValue=argbarb" }));
|
||||
new String[]{"--fooValue=argbarb"}));
|
||||
}
|
||||
if (processorConfigurer.getNamespace().equals("c")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--fooValue=sysbarc" }));
|
||||
new String[]{"--fooValue=sysbarc"}));
|
||||
}
|
||||
}
|
||||
aggregatedApplicationContext.close();
|
||||
@@ -316,7 +312,7 @@ public class AggregationTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNamespacePrefixesWithCAPSProperties() {
|
||||
AggregateApplicationBuilder aggregateApplicationBuilder = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock");
|
||||
System.setProperty("a.fooValue", "sysbara");
|
||||
System.setProperty("c.fooValue", "sysbarc");
|
||||
aggregatedApplicationContext = aggregateApplicationBuilder
|
||||
@@ -328,17 +324,17 @@ public class AggregationTest {
|
||||
aggregateApplicationBuilder);
|
||||
assertThat(((SourceConfigurer) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("sourceConfigurer")).getArgs())
|
||||
.containsExactly(new String[] { "--fooValue=highest" });
|
||||
.containsExactly(new String[]{"--fooValue=highest"});
|
||||
final List<AggregateApplicationBuilder.ProcessorConfigurer> processorConfigurers = (List<AggregateApplicationBuilder.ProcessorConfigurer>) aggregateApplicationBuilderAccessor
|
||||
.getPropertyValue("processorConfigurers");
|
||||
for (AggregateApplicationBuilder.ProcessorConfigurer processorConfigurer : processorConfigurers) {
|
||||
if (processorConfigurer.getNamespace().equals("b")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--fooValue=argbarb" }));
|
||||
new String[]{"--fooValue=argbarb"}));
|
||||
}
|
||||
if (processorConfigurer.getNamespace().equals("c")) {
|
||||
assertTrue(Arrays.equals(processorConfigurer.getArgs(),
|
||||
new String[] { "--fooValue=sysbarc" }));
|
||||
new String[]{"--fooValue=sysbarc"}));
|
||||
}
|
||||
}
|
||||
aggregatedApplicationContext.close();
|
||||
@@ -347,9 +343,9 @@ public class AggregationTest {
|
||||
@Test
|
||||
public void testNamespaces() {
|
||||
aggregatedApplicationContext = new AggregateApplicationBuilder(
|
||||
FooConfig.class, "--server.port=0", "--spring.cloud.stream.default-binder=mock").web(false)
|
||||
.from(TestSource.class).namespace("foo").to(TestProcessor.class)
|
||||
.namespace("bar").run();
|
||||
AggregationAppConfig.class, "--spring.cloud.stream.default-binder=mock").web(false)
|
||||
.from(TestSource.class).namespace("foo").to(TestProcessor.class)
|
||||
.namespace("bar").run();
|
||||
SharedBindingTargetRegistry sharedChannelRegistry = aggregatedApplicationContext
|
||||
.getBean(SharedBindingTargetRegistry.class);
|
||||
BindingTargetFactory channelFactory = aggregatedApplicationContext
|
||||
@@ -404,11 +400,9 @@ public class AggregationTest {
|
||||
}
|
||||
if (factory.getObjectType() == FooSource.class) {
|
||||
assertThat(targetCache).hasSize(1);
|
||||
}
|
||||
else if (factory.getObjectType() == Processor.class) {
|
||||
} else if (factory.getObjectType() == Processor.class) {
|
||||
assertThat(targetCache).hasSize(2);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Assert.fail("Found unexpected type");
|
||||
}
|
||||
}
|
||||
@@ -447,7 +441,7 @@ public class AggregationTest {
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
public static class FooConfig {
|
||||
public static class AggregationAppConfig {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class InputOutputBindingOrderTest {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Test
|
||||
public void testInputOutputBindingOrder() {
|
||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(TestSource.class, "--server.port=-1",
|
||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(TestSource.class,
|
||||
"--spring.cloud.stream.defaultBinder=mock");
|
||||
@SuppressWarnings("rawtypes")
|
||||
Binder binder = applicationContext.getBean(BinderFactory.class).getBinder(null, MessageChannel.class);
|
||||
|
||||
@@ -30,10 +30,8 @@ import org.springframework.cloud.stream.binder.PartitionSelectorStrategy;
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.cloud.stream.partitioning.CustomPartitionKeyExtractorClass;
|
||||
import org.springframework.cloud.stream.partitioning.CustomPartitionSelectorClass;
|
||||
import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||
import org.springframework.integration.annotation.Poller;
|
||||
@@ -56,7 +54,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.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) {
|
||||
@@ -87,7 +86,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.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) {
|
||||
@@ -115,7 +115,8 @@ 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.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) {
|
||||
@@ -145,7 +146,8 @@ public class CustomPartitionedProducerTest {
|
||||
"--spring.jmx.enabled=false",
|
||||
"--spring.main.web-application-type=none",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionKeyExtractorName=customPartitionKeyExtractorOne",
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelectorTwo");
|
||||
"--spring.cloud.stream.bindings.output.producer.partitionSelectorName=customPartitionSelectorTwo",
|
||||
"--spring.cloud.stream.default-binder=mock");
|
||||
Source testSource = context.getBean(Source.class);
|
||||
DirectChannel messageChannel = (DirectChannel) testSource.output();
|
||||
for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) {
|
||||
@@ -180,7 +182,6 @@ public class CustomPartitionedProducerTest {
|
||||
|
||||
@EnableBinding(Source.class)
|
||||
@EnableAutoConfiguration
|
||||
@Import(MockBinderRegistryConfiguration.class)
|
||||
@PropertySource("classpath:/org/springframework/cloud/stream/binder/custom-partitioned-producer-test.properties")
|
||||
public static class TestSource {
|
||||
|
||||
@@ -208,7 +209,6 @@ public class CustomPartitionedProducerTest {
|
||||
|
||||
@EnableBinding(Source.class)
|
||||
@EnableAutoConfiguration
|
||||
@Import(MockBinderRegistryConfiguration.class)
|
||||
@PropertySource("classpath:/org/springframework/cloud/stream/binder/custom-partitioned-producer-test.properties")
|
||||
public static class TestSourceMultipleStrategies {
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Input;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
|
||||
@@ -50,7 +48,6 @@ public class InvalidBindingConfigurationTests {
|
||||
|
||||
@EnableBinding(TestInvalidBinding.class)
|
||||
@EnableAutoConfiguration
|
||||
@Import(MockBinderRegistryConfiguration.class)
|
||||
public static class TestBindingConfig {
|
||||
|
||||
}
|
||||
|
||||
@@ -32,10 +32,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.PropertyAccessor;
|
||||
@@ -101,7 +99,6 @@ public class SpelExpressionConverterConfigurationTests {
|
||||
@Configuration
|
||||
@EnableBinding
|
||||
@EnableAutoConfiguration
|
||||
@Import(MockBinderRegistryConfiguration.class)
|
||||
@EnableConfigurationProperties(Pojo.class)
|
||||
public static class Config implements BeanFactoryAware {
|
||||
|
||||
|
||||
@@ -25,9 +25,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.config.GlobalChannelInterceptor;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -48,7 +46,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = BoundChannelsInterceptedTest.Foo.class)
|
||||
@SpringBootTest(classes = BoundChannelsInterceptedTest.Foo.class, properties = "spring.cloud.stream.default-binder=mock")
|
||||
public class BoundChannelsInterceptedTest {
|
||||
|
||||
public static final Message<?> TEST_MESSAGE = MessageBuilder.withPayload("bar").setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON).build();
|
||||
@@ -68,7 +66,6 @@ public class BoundChannelsInterceptedTest {
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableBinding(Sink.class)
|
||||
@Import(MockBinderRegistryConfiguration.class)
|
||||
public static class Foo {
|
||||
|
||||
@ServiceActivator(inputChannel = Sink.INPUT)
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.stream.partitioning;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
@@ -31,7 +32,6 @@ import org.springframework.cloud.stream.binder.BinderFactory;
|
||||
import org.springframework.cloud.stream.binder.ConsumerProperties;
|
||||
import org.springframework.cloud.stream.config.BinderFactoryConfiguration;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.stream.utils.MockBinderRegistryConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -49,7 +49,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = PartitionedConsumerTest.TestSink.class)
|
||||
@SpringBootTest(classes = PartitionedConsumerTest.TestSink.class, properties = "spring.cloud.stream.default-binder=mock")
|
||||
public class PartitionedConsumerTest {
|
||||
|
||||
@Autowired
|
||||
@@ -72,7 +72,7 @@ public class PartitionedConsumerTest {
|
||||
|
||||
@EnableBinding(Sink.class)
|
||||
@EnableAutoConfiguration
|
||||
@Import({ MockBinderRegistryConfiguration.class, BinderFactoryConfiguration.class })
|
||||
@Import({ BinderFactoryConfiguration.class })
|
||||
@PropertySource("classpath:/org/springframework/cloud/stream/binder/partitioned-consumer-test.properties")
|
||||
public static class TestSink {
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.stream.utils;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.cloud.stream.binder.BinderType;
|
||||
import org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry;
|
||||
import org.springframework.cloud.stream.config.SpelExpressionConverterConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* A simple configuration that creates mock
|
||||
* {@link org.springframework.cloud.stream.binder.Binder}s.
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@Configuration
|
||||
@Import(SpelExpressionConverterConfiguration.class)
|
||||
public class MockBinderRegistryConfiguration {
|
||||
|
||||
@Bean
|
||||
public static MockBinderRegistryFactoryPostProcessor mockBinderRegistryFactoryPostProcessor() {
|
||||
return new MockBinderRegistryFactoryPostProcessor();
|
||||
}
|
||||
|
||||
static class MockBinderRegistryFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
if (beanFactory.containsBean("binderTypeRegistry")) {
|
||||
|
||||
BeanDefinitionRegistry beanDefinitionRegistry =
|
||||
(BeanDefinitionRegistry) beanFactory;
|
||||
beanDefinitionRegistry.removeBeanDefinition("binderTypeRegistry");
|
||||
|
||||
DefaultBinderTypeRegistry mock = new DefaultBinderTypeRegistry(
|
||||
Collections.singletonMap("mock", new BinderType("", new Class[]{MockBinderConfiguration.class})));
|
||||
BeanDefinition mockDefn =
|
||||
BeanDefinitionBuilder.genericBeanDefinition((Class<DefaultBinderTypeRegistry>) mock.getClass(),
|
||||
() -> mock)
|
||||
.getRawBeanDefinition();
|
||||
|
||||
beanDefinitionRegistry.registerBeanDefinition("binderTypeRegistry", mockDefn);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user