Skip to content

Add @EnableTestBinder annotation #2947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 the original author or authors.
* Copyright 2017-2024 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.
Expand Down Expand Up @@ -29,14 +29,13 @@
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.function.json.JsonMapper;
import org.springframework.cloud.stream.binder.test.EnableTestBinder;
import org.springframework.cloud.stream.binder.test.InputDestination;
import org.springframework.cloud.stream.binder.test.OutputDestination;
import org.springframework.cloud.stream.binder.test.TestChannelBinder;
import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
Expand All @@ -58,6 +57,7 @@
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Byungjun You
* @author Kotaro Matsumoto
*
*/
class ContentTypeTckTests {
Expand Down Expand Up @@ -518,7 +518,7 @@ void withMessageHeadersInputParameter() {
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need copyright updates, author tag.

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class CollectionWithParameterizedTypes {

Expand All @@ -531,7 +531,7 @@ public Function<List<Employee<Person>>, List<Employee<Person>>> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class PojoToPojoConfiguration {

Expand All @@ -541,7 +541,7 @@ public Function<Person, Person> ecgo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class PojoToStringConfiguration {

Expand All @@ -551,7 +551,7 @@ public Function<Person, String> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class PojoToByteArrayConfiguration {

Expand All @@ -561,7 +561,7 @@ public Function<Person, byte[]> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class ByteArrayToPojoConfiguration {

Expand All @@ -571,7 +571,7 @@ public Function<byte[], Person> echo(JsonMapper mapper) {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class StringToPojoConfiguration {

Expand All @@ -581,7 +581,7 @@ public Function<String, Person> echo(JsonMapper mapper) {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class TypelessToPojoConfiguration {

Expand All @@ -593,7 +593,7 @@ public Function<Object, Person> echo(JsonMapper mapper) {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class TypelessMessageToPojoConfiguration {

Expand All @@ -605,7 +605,7 @@ public Function<Message<?>, Person> echo(JsonMapper mapper) {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class TypelessToMessageConfiguration {

Expand All @@ -616,7 +616,7 @@ public Function<Object, Message<?>> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class TypelessToMessageTextOnlyContentTypeConfiguration {

Expand All @@ -630,7 +630,7 @@ public Function<?, Message<?>> echo() {
}


@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class ByteArrayToByteArrayConfiguration {

Expand All @@ -640,7 +640,7 @@ public Function<byte[], byte[]> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class StringToStringConfiguration {

Expand All @@ -650,7 +650,7 @@ public Function<String, String> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class StringToMapMessageConfiguration {

Expand All @@ -663,7 +663,7 @@ public static class StringToMapMessageConfiguration {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class PojoMessageToStringMessageConfiguration {

Expand Down Expand Up @@ -799,7 +799,7 @@ protected Object convertToInternal(Object payload,

}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class MapInputConfiguration {

Expand All @@ -809,7 +809,7 @@ public static class MapInputConfiguration {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class ListInputConfiguration {
@Bean
Expand All @@ -818,7 +818,7 @@ public Function<List<?>, List<?>> echo() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class MessageHeadersInputConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 the original author or authors.
* Copyright 2015-2024 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.
Expand Down Expand Up @@ -52,7 +52,7 @@
import org.springframework.cloud.stream.binder.DefaultBinderFactory;
import org.springframework.cloud.stream.binder.DefaultBinderTypeRegistry;
import org.springframework.cloud.stream.binder.ProducerProperties;
import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
import org.springframework.cloud.stream.binder.test.EnableTestBinder;
import org.springframework.cloud.stream.config.BindingProperties;
import org.springframework.cloud.stream.config.BindingServiceConfiguration;
import org.springframework.cloud.stream.config.BindingServiceProperties;
Expand All @@ -61,7 +61,6 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
Expand Down Expand Up @@ -90,6 +89,7 @@
* @author Michael Michailidis
* @author Chris Bono
* @author Artem Bilan
* @author Kotaro Matsumoto
*/
class BindingServiceTests {

Expand Down Expand Up @@ -591,13 +591,13 @@ private BindingServiceProperties createBindingServiceProperties(
return bindingServiceProperties;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need copyright updates, author tag.

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class DefaultConsumerPropertiesTestSink {

}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class FooConfiguration {

Expand All @@ -608,7 +608,7 @@ public Consumer<Message<?>> log() {

}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class BarConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 the original author or authors.
* Copyright 2018-2024 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.
Expand Down Expand Up @@ -29,9 +29,8 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindException;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
import org.springframework.cloud.stream.binder.test.EnableTestBinder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.validation.annotation.Validated;

import static org.assertj.core.api.Assertions.assertThat;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need copyright updates, author tag.

Expand All @@ -41,6 +40,7 @@
/**
* @author Oleg Zhurakousky
* @author Soby Chacko
* @author Kotaro Matsumoto
*
*/
class BindingHandlerAdviseTests {
Expand Down Expand Up @@ -76,7 +76,7 @@ void validatedConfigProperties() {
.run("--spring.jmx.enabled=false"));
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class NonValidatedConfiguration {

Expand Down Expand Up @@ -105,7 +105,7 @@ public void setId(String id) {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class ValidatedConfiguration {

Expand Down Expand Up @@ -136,7 +136,7 @@ public void setId(String id) {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
@EnableConfigurationProperties(ValidatedProps.class)
class SampleConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 the original author or authors.
* Copyright 2018-2024 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.
Expand Down Expand Up @@ -29,17 +29,17 @@
import org.springframework.cloud.stream.annotation.StreamRetryTemplate;
import org.springframework.cloud.stream.binder.AbstractBinder;
import org.springframework.cloud.stream.binder.ConsumerProperties;
import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration;
import org.springframework.cloud.stream.binder.test.EnableTestBinder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.retry.support.RetryTemplate;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need copyright updates, author tag.

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Oleg Zhurakousky
* @author Soby Chacko
* @author Kotaro Matsumoto
*/
class RetryTemplateTests {

Expand Down Expand Up @@ -82,7 +82,7 @@ void specificCustomRetryTemplate() throws Exception {
assertThat(retryTemplate).isEqualTo(retryTemplateTwo);
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class SpecificCustomRetryTemplateConfiguration {

Expand All @@ -107,7 +107,7 @@ public Function<String, String> processor() {
}
}

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class SingleCustomRetryTemplateConfiguration {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024-2024 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
*
* https://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.binder.test;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.annotation.Import;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some class level javadoc to this?

/**
* This annotation enables the Spring Integration Test Binder when applied to a class.
*
* Please see {@link TestChannelBinderConfiguration} and {@link TestChannelBinder} for more details.
*
* @author Kotaro Matsumoto
* @see TestChannelBinderConfiguration
* @see TestChannelBinder
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(TestChannelBinderConfiguration.class)
public @interface EnableTestBinder {

}
3 changes: 1 addition & 2 deletions docs/modules/ROOT/pages/spring-cloud-stream.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following listing shows the corresponding test:
[source,java]
----
@SpringBootTest(classes = SampleApplication.class)
@Import({TestChannelBinderConfiguration.class})
@EnableTestBinder
class BootTestStreamApplicationTests {

@Autowired
Expand All @@ -70,4 +70,3 @@ class BootTestStreamApplicationTests {

Spring Cloud Stream provides a number of abstractions and primitives that simplify the writing of message-driven microservice applications.
The rest of this reference manual provides additional details.

Loading
Loading