Spring Boot 2.1 upgrade related changes

* Instead of redefining `BinderTypeRegistry` as a bean in several tests, properly use spring.binders
  to define mock binders and then choose a default binder in tests in case of multiple binders in
  same spring.binders file.
* Remove `BindingServiceConfiguration` in `EnableBinding` and introduce it as a proper
  Spring Boot autoconfiguration class. Added `BindingServiceConfiguration` to spring.factories.
* Move `BinderFactory` bean into `BindingServiceConfiguration` and add `ConditionalOnMissingBean`
  on it so that downstream users can define new `BinderFactory` beans as part of autoconfiguration.
* Remove `ConditionalOnMissingBean` from the `BinderTypeRegistry` bean in `BinderFactoryConfiguration`
  as we don't expect this bean to be overridden.
* Remove previously added property `spring.main.allow-bean-definition-overriding` in several tests.
* Since web/actuator is optional now, remove unncecessarily setting server.port to `0` in tests
* Ensure that `BindersHealthIndicatorAutoConfiguration` is autoconfigured after `BindingServiceConfiguration`
  so that it has a `BinderFactory` available.
* Remove redefining `ServerController` bean in `SchemaServerConfiguration` as this is already created through
  component scanning and causing the bean overriding exceptions.
* Tests cleanup and polishing.

Resolves #1429, #1430
This commit is contained in:
Soby Chacko
2018-08-08 19:05:26 -04:00
parent 85b34be733
commit ae445e73ac
77 changed files with 242 additions and 413 deletions

View File

@@ -41,8 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Oleg Zhurakousky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { ContentTypeOutboundSourceTests.TestSource.class },
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = { ContentTypeOutboundSourceTests.TestSource.class })
public class ContentTypeOutboundSourceTests {
@Autowired

View File

@@ -44,8 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = CustomHeaderPropagationTests.HeaderPropagationProcessor.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {"spring.cloud.stream.integration.messageHandlerNotPropagatedHeaders=bar,contentType",
"--spring.main.allow-bean-definition-overriding=true"})
properties = {"spring.cloud.stream.integration.messageHandlerNotPropagatedHeaders=bar,contentType"})
public class CustomHeaderPropagationTests {
@Autowired

View File

@@ -51,8 +51,7 @@ import static org.hamcrest.Matchers.notNullValue;
* @author Janne Valkealahti
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = CustomMessageConverterTests.TestSource.class,
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = CustomMessageConverterTests.TestSource.class)
public class CustomMessageConverterTests {
@Autowired

View File

@@ -43,8 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DefaultHeaderPropagationTests.HeaderPropagationProcessor.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {"--spring.main.allow-bean-definition-overriding=true"})
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class DefaultHeaderPropagationTests {
@Autowired

View File

@@ -37,15 +37,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
/**
* @author Marius Bogoevici
* @author Oleg Zhurakousky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DefaultHeaderPropagationWithApplicationProvidedHeaderTests.HeaderPropagationProcessor.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {"--spring.main.allow-bean-definition-overriding=true"})
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class DefaultHeaderPropagationWithApplicationProvidedHeaderTests {
@Autowired

View File

@@ -43,8 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Oleg Zhurakousky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DeserializeJSONToJavaTypeTests.FooProcessor.class,
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = DeserializeJSONToJavaTypeTests.FooProcessor.class)
public class DeserializeJSONToJavaTypeTests {
@Autowired

View File

@@ -45,8 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Oleg Zhurakousky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = InboundJsonToTupleConversionTest.FooProcessor.class,
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = InboundJsonToTupleConversionTest.FooProcessor.class)
public class InboundJsonToTupleConversionTest {
@Autowired

View File

@@ -43,8 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Oleg Zhurakousky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { LegacyContentTypeTests.LegacyTestSink.class},
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = { LegacyContentTypeTests.LegacyTestSink.class})
public class LegacyContentTypeTests {
@Autowired

View File

@@ -53,8 +53,7 @@ import static org.junit.Assert.assertNull;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { MessageChannelConfigurerTests.TestSink.class,
MessageChannelConfigurerTests.TestSource.class, SpelExpressionConverterConfiguration.class},
properties = {"--spring.main.allow-bean-definition-overriding=true"})
MessageChannelConfigurerTests.TestSource.class, SpelExpressionConverterConfiguration.class})
public class MessageChannelConfigurerTests {
@Autowired

View File

@@ -41,8 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Soby Chacko
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { MessageChannelWithNativeDecodingTests.NativeDecodingSink.class},
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = { MessageChannelWithNativeDecodingTests.NativeDecodingSink.class})
public class MessageChannelWithNativeDecodingTests {
@Autowired

View File

@@ -39,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Soby Chacko
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { MessageChannelWithNativeEncodingTests.NativeEncodingSource.class},
properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = { MessageChannelWithNativeEncodingTests.NativeEncodingSource.class})
public class MessageChannelWithNativeEncodingTests {
@Autowired

View File

@@ -21,7 +21,6 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -50,11 +49,6 @@ import static org.springframework.cloud.stream.binding.StreamListenerErrorMessag
*/
public class StreamListenerAnnotatedMethodArgumentsTests {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
@SuppressWarnings("unchecked")
public void testAnnotatedArguments() throws Exception {

View File

@@ -23,10 +23,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.stream.annotation.EnableBinding;
@@ -35,6 +33,7 @@ import org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPost
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.handler.annotation.Payload;
@@ -47,11 +46,6 @@ import static org.springframework.cloud.stream.config.BindingServiceConfiguratio
*/
public class StreamListenerAnnotationBeanPostProcessorOverrideTest {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
@SuppressWarnings("unchecked")
public void testOverrideStreamListenerAnnotationBeanPostProcessor() throws Exception {
@@ -74,6 +68,7 @@ public class StreamListenerAnnotationBeanPostProcessorOverrideTest {
context.close();
}
@Configuration
@EnableBinding(Sink.class)
@EnableAutoConfiguration
public static class TestPojoWithAnnotatedArguments {
@@ -84,7 +79,7 @@ public class StreamListenerAnnotationBeanPostProcessorOverrideTest {
* Overrides the default {@link StreamListenerAnnotationBeanPostProcessor}.
*/
@Bean(name = STREAM_LISTENER_ANNOTATION_BEAN_POST_PROCESSOR_NAME)
public static BeanPostProcessor streamListenerAnnotationBeanPostProcessor() {
public static StreamListenerAnnotationBeanPostProcessor streamListenerAnnotationBeanPostProcessor() {
return new StreamListenerAnnotationBeanPostProcessor() {
@Override
protected StreamListener postProcessAnnotation(StreamListener originalAnnotation,

View File

@@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -75,11 +74,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class StreamListenerAsMetaAnnotationTests {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
public void testCustomAnnotation() {
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithCustomAnnotatedArguments.class,

View File

@@ -22,7 +22,6 @@ import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -41,11 +40,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class StreamListenerContentTypeConversionTests {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
public void testContentTypeConversion() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestSinkWithContentTypeConversion.class,

View File

@@ -16,7 +16,6 @@
package org.springframework.cloud.stream.config;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
@@ -40,11 +39,6 @@ import static org.junit.Assert.fail;
*/
public class StreamListenerDuplicateMappingTests {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
@SuppressWarnings("unchecked")
public void testMultipleMappingsWithReturnValue() {

View File

@@ -24,7 +24,6 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -58,11 +57,6 @@ public class StreamListenerHandlerBeanTests {
private Class<?> configClass;
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
public StreamListenerHandlerBeanTests(Class<?> configClass) {
this.configClass = configClass;
}

View File

@@ -19,7 +19,6 @@ package org.springframework.cloud.stream.config;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -68,11 +67,6 @@ import static org.springframework.cloud.stream.binding.StreamListenerErrorMessag
*/
public class StreamListenerHandlerMethodTests {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
public void testInvalidInputOnMethod() throws Exception {
try {

View File

@@ -23,7 +23,6 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -57,11 +56,6 @@ public class StreamListenerMessageArgumentTests {
this.configClass = configClass;
}
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Parameterized.Parameters
public static Collection<?> InputConfigs() {
return Arrays.asList(new Class[] { TestPojoWithMessageArgument1.class, TestPojoWithMessageArgument2.class });

View File

@@ -41,7 +41,7 @@ import static org.mockito.Mockito.verify;
* @author Soby Chacko
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest
public class StreamListenerMethodRegisteredOnlyOnceTest {
@Autowired

View File

@@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -67,11 +66,6 @@ public class StreamListenerMethodReturnWithConversionTests extends Suite {
super(klass, builder);
}
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@RunWith(Parameterized.class)
public static class TestReturnConversion {

View File

@@ -55,7 +55,7 @@ import static org.mockito.Mockito.verify;
* @author Soby Chacko
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(properties = {"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest
public class StreamListenerMethodSetupOrchestratorTests {
@SpyBean

View File

@@ -24,7 +24,6 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -58,11 +57,6 @@ public class StreamListenerMethodWithReturnMessageTests {
this.configClass = configClass;
}
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Parameterized.Parameters
public static Collection<?> InputConfigs() {
return Arrays.asList(new Class[] { TestPojoWithMessageReturn1.class, TestPojoWithMessageReturn2.class });

View File

@@ -24,7 +24,6 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -57,11 +56,6 @@ public class StreamListenerMethodWithReturnValueTests {
this.configClass = configClass;
}
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Parameterized.Parameters
public static Collection<?> InputConfigs() {
return Arrays.asList(new Class[] { TestStringProcessor1.class, TestStringProcessor2.class });

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.config;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -50,11 +49,6 @@ import static org.springframework.cloud.stream.binding.StreamListenerErrorMessag
*/
public class StreamListenerWithAnnotatedInputOutputArgsTests {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
public void testInputOutputArgs() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestInputOutputArgs.class, "--server.port=0", "--spring.cloud.stream.bindings.output.contentType=text/plain", "--spring.jmx.enabled=false");

View File

@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -43,11 +42,6 @@ import static org.assertj.core.api.Assertions.fail;
*/
public class StreamListenerWithConditionsTest {
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
public void testAnnotatedArgumentsWithConditionalClass() throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(TestPojoWithAnnotatedArguments.class,

View File

@@ -45,8 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = TextPlainConversionTest.FooProcessor.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {"--spring.main.allow-bean-definition-overriding=true"})
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class TextPlainConversionTest {
@Autowired

View File

@@ -48,8 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = TextPlainToJsonConversionTest.FooProcessor.class,
webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = {"--spring.main.allow-bean-definition-overriding=true"}
webEnvironment = SpringBootTest.WebEnvironment.NONE
)
public class TextPlainToJsonConversionTest {

View File

@@ -19,19 +19,20 @@ package org.springframework.cloud.stream.config.aggregate;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.stream.aggregate.AggregateApplicationBuilder;
import org.springframework.cloud.stream.binder.BinderFactory;
import org.springframework.cloud.stream.config.aggregate.processor.TestProcessor;
import org.springframework.cloud.stream.config.aggregate.source.TestSource;
import org.springframework.cloud.stream.test.binder.TestSupportBinder;
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
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,19 +42,14 @@ import static org.hamcrest.Matchers.notNullValue;
* @author Oleg Zhurakousky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class AggregateApplicationTests {
@Before
public void before() {
System.setProperty("server.port", "0");
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
@SuppressWarnings("unchecked")
public void testAggregateApplication() throws Exception {
ConfigurableApplicationContext context = new AggregateApplicationBuilder(
TestSupportBinderAutoConfiguration.class).web(false).from(TestSource.class).to(TestProcessor.class).run();
FooConfig.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");
@@ -62,4 +58,10 @@ public class AggregateApplicationTests {
Assert.assertThat(received, notNullValue());
Assert.assertTrue(received.getPayload().endsWith("processed"));
}
@Configuration
@EnableAutoConfiguration
static class FooConfig{
}
}

View File

@@ -25,8 +25,6 @@ import java.util.concurrent.TimeUnit;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -60,11 +58,6 @@ public class ContentTypeTests {
private ObjectMapper mapper = new ObjectMapper();
@Before
public void before() {
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@Test
public void testSendWithDefaultContentType() throws Exception {
try (ConfigurableApplicationContext context = SpringApplication.run(