Skip to content
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

Add @EnableTestBinder annotation #2947

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 Down Expand Up @@ -518,7 +517,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 +530,7 @@ public Function<List<Employee<Person>>, List<Employee<Person>>> echo() {
}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

}

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

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

@Import(TestChannelBinderConfiguration.class)
@EnableTestBinder
@EnableAutoConfiguration
public static class ListInputConfiguration {
@Bean
Expand All @@ -818,7 +817,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
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 @@ -591,13 +590,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 +607,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
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 Down Expand Up @@ -76,7 +75,7 @@ void validatedConfigProperties() {
.run("--spring.jmx.enabled=false"));
}

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

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

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

Expand Down Expand Up @@ -136,7 +135,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
Expand Up @@ -29,10 +29,9 @@
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;
Expand Down Expand Up @@ -82,7 +81,7 @@ void specificCustomRetryTemplate() throws Exception {
assertThat(retryTemplate).isEqualTo(retryTemplateTwo);
}

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

Expand All @@ -107,7 +106,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,36 @@
/*
* 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?

/**
* @author Kotaro Matsumoto
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import(TestChannelBinderConfiguration.class)
public @interface EnableTestBinder {

}
Loading