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

@@ -16,11 +16,13 @@
package org.springframework.cloud.stream.test.binder;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.cloud.stream.binder.Binder;
import org.springframework.cloud.stream.binder.BinderFactory;
import org.springframework.cloud.stream.binder.ConsumerProperties;
import org.springframework.cloud.stream.binder.ProducerProperties;
import org.springframework.cloud.stream.config.BindingServiceConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -43,6 +45,7 @@ import org.springframework.messaging.MessageChannel;
@Configuration
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
@Import(TestSupportBinderConfiguration.class)
@AutoConfigureBefore(BindingServiceConfiguration.class)
public class TestSupportBinderAutoConfiguration {
@Bean

View File

@@ -22,6 +22,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.stream.aggregate.AggregateApplication;
@@ -43,8 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = AggregateWithBeanTest.ChainedProcessors.class, properties = { "server.port=-1","--spring.cloud.stream.bindings.input.contentType=text/plain",
"--spring.cloud.stream.bindings.output.contentType=text/plain",
"--spring.main.allow-bean-definition-overriding=true"})
"--spring.cloud.stream.bindings.output.contentType=text/plain"})
public class AggregateWithBeanTest {
@Autowired
@@ -77,6 +77,7 @@ public class AggregateWithBeanTest {
@Configuration
@EnableBinding(Processor.class)
@EnableAutoConfiguration
public static class UppercaseProcessor {
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
@@ -87,6 +88,7 @@ public class AggregateWithBeanTest {
@Configuration
@EnableBinding(Processor.class)
@EnableAutoConfiguration
public static class SuffixProcessor {
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)

View File

@@ -18,7 +18,6 @@ package org.springframework.cloud.stream.test.aggregate.main;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,12 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class AggregateWithMainTest {
@Before
public void before() {
System.setProperty("server.port", "0");
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}
@SuppressWarnings("unchecked")
@Test
public void testAggregateApplication() throws InterruptedException {
@@ -77,6 +70,7 @@ public class AggregateWithMainTest {
@Configuration
@EnableBinding(Processor.class)
@EnableAutoConfiguration
static class UppercaseProcessor {
@Autowired
@@ -91,6 +85,7 @@ public class AggregateWithMainTest {
@Configuration
@EnableBinding(Processor.class)
@EnableAutoConfiguration
static class SuffixProcessor {
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)

View File

@@ -39,8 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
* correctly.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ExampleTest.MyProcessor.class, properties = { "server.port=-1", "--spring.cloud.stream.bindings.input.contentType=text/plain", "--spring.cloud.stream.bindings.output.contentType=text/plain",
"--spring.main.allow-bean-definition-overriding=true"})
@SpringBootTest(classes = ExampleTest.MyProcessor.class, properties = { "server.port=-1",
"--spring.cloud.stream.bindings.input.contentType=text/plain",
"--spring.cloud.stream.bindings.output.contentType=text/plain"})
@DirtiesContext
public class ExampleTest {