From fd9fa80055aa931be59327eb16892f4dc49d676c Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Thu, 16 May 2024 15:28:48 -0400 Subject: [PATCH] Test cleanup * Use `EnableAutoConfiguration` instead of `SpringBootApplication` in tests --- .../rabbit/integration/RabbitBinderModuleTests.java | 8 +++++--- .../rabbit/stream/RabbitStreamBinderModuleTests.java | 9 ++++++--- .../RabbitStreamBinderModuleIntegrationTests.java | 10 +++++++--- .../cloud/stream/function/edgecases/GH1801Test.java | 7 ++++--- .../AvroMessageConverterSerializationTests.java | 9 ++++++--- .../AvroSchemaRegistryClientMessageConverterTests.java | 9 +++++---- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java index 90bc01924..3188b12e6 100644 --- a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java +++ b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/integration/RabbitBinderModuleTests.java @@ -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. @@ -46,7 +46,7 @@ import org.springframework.boot.actuate.amqp.RabbitHealthIndicator; import org.springframework.boot.actuate.health.CompositeHealthContributor; import org.springframework.boot.actuate.health.Status; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.Cloud; import org.springframework.cloud.stream.binder.Binder; @@ -69,6 +69,7 @@ import org.springframework.cloud.stream.config.ProducerMessageHandlerCustomizer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter; import org.springframework.integration.amqp.inbound.AmqpMessageSource; import org.springframework.integration.channel.DirectChannel; @@ -418,7 +419,8 @@ void extendedProperties() { assertThat(rabbitConsumerProperties.getMaxConcurrency()).isEqualTo(4); } - @SpringBootApplication + @EnableAutoConfiguration + @Configuration public static class SimpleProcessor { @Bean diff --git a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream/RabbitStreamBinderModuleTests.java b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream/RabbitStreamBinderModuleTests.java index 4dd8bba82..f57c4f5aa 100644 --- a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream/RabbitStreamBinderModuleTests.java +++ b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream/RabbitStreamBinderModuleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 the original author or authors. + * Copyright 2021-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. @@ -27,7 +27,7 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.listener.MessageListenerContainer; import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.stream.binder.BinderFactory; import org.springframework.cloud.stream.binder.Binding; @@ -43,6 +43,7 @@ import org.springframework.cloud.stream.config.ProducerMessageHandlerCustomizer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.integration.amqp.outbound.RabbitStreamMessageHandler; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; @@ -59,6 +60,7 @@ /** * @author Gary Russell + * @author Soby Chacko */ class RabbitStreamBinderModuleTests { @@ -131,7 +133,8 @@ void streamHandler() { } } - @SpringBootApplication(proxyBeanMethods = false) + @EnableAutoConfiguration + @Configuration public static class SimpleProcessor { @Bean diff --git a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream2/RabbitStreamBinderModuleIntegrationTests.java b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream2/RabbitStreamBinderModuleIntegrationTests.java index 3736cdbbb..a2aee9b0b 100644 --- a/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream2/RabbitStreamBinderModuleIntegrationTests.java +++ b/binders/rabbit-binder/spring-cloud-stream-binder-rabbit/src/test/java/org/springframework/cloud/stream/binder/rabbit/stream2/RabbitStreamBinderModuleIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 the original author or authors. + * Copyright 2021-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. @@ -16,6 +16,7 @@ package org.springframework.cloud.stream.binder.rabbit.stream2; + import java.util.Properties; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -30,7 +31,7 @@ import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.listener.MessageListenerContainer; import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.EnvironmentBuilderCustomizer; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.stream.binder.BinderFactory; @@ -43,6 +44,7 @@ import org.springframework.cloud.stream.config.ListenerContainerCustomizer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; @@ -52,6 +54,7 @@ /** * @author Gary Russell + * @author Soby Chacko */ class RabbitStreamBinderModuleIntegrationTests { @@ -89,7 +92,8 @@ void superStreamContainer() throws InterruptedException { } } - @SpringBootApplication(proxyBeanMethods = false) + @EnableAutoConfiguration + @Configuration public static class SimpleProcessor { final CountDownLatch consumerCountLatch = new CountDownLatch(3); diff --git a/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java b/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java index f025e15dc..2ae5d1136 100644 --- a/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java +++ b/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/edgecases/GH1801Test.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 the original author or authors. + * Copyright 2019-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. @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -38,6 +38,7 @@ * is addressed. * * @author Oleg Zhurakousky + * @author Soby Chacko * */ class GH1801Test { @@ -58,7 +59,7 @@ void verifyNoNPEWhenFactoryMethodNull() throws Exception { SampleBootApplication.main("--spring.cloud.stream.defaultBinder=integration1"); } - @SpringBootApplication + @EnableAutoConfiguration public static class SampleBootApplication { public static void main(String... args) throws Exception { ClassLoader classLoader = createClassLoader(new String[] { "binder1" }); diff --git a/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroMessageConverterSerializationTests.java b/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroMessageConverterSerializationTests.java index bf494e956..540384631 100644 --- a/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroMessageConverterSerializationTests.java +++ b/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroMessageConverterSerializationTests.java @@ -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. @@ -40,7 +40,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.cache.support.NoOpCacheManager; import org.springframework.cloud.stream.schema.registry.EnableSchemaRegistryServer; @@ -52,6 +52,7 @@ import org.springframework.cloud.stream.schema.registry.client.DefaultSchemaRegistryClient; import org.springframework.cloud.stream.schema.registry.client.SchemaRegistryClient; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Configuration; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.support.MutableMessageHeaders; import org.springframework.messaging.Message; @@ -64,6 +65,7 @@ /** * @author Vinicius Carvalho * @author Sercan Karaoglu + * @author Soby Chacko */ class AvroMessageConverterSerializationTests { @@ -222,7 +224,8 @@ private SchemaReference extractSchemaReference(MimeType mimeType) { return schemaReference; } - @SpringBootApplication + @EnableAutoConfiguration + @Configuration @EnableSchemaRegistryServer public static class ServerApplication { public static void main(String[] args) { diff --git a/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroSchemaRegistryClientMessageConverterTests.java b/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroSchemaRegistryClientMessageConverterTests.java index b6df22927..925cf6adc 100644 --- a/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroSchemaRegistryClientMessageConverterTests.java +++ b/schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/serialization/AvroSchemaRegistryClientMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 the original author or authors. + * Copyright 2016-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. @@ -29,7 +29,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; @@ -70,11 +69,12 @@ * @author Sercan Karaoglu * @author James Gee * @author Christian Tzolov + * @author Soby Chacko */ class AvroSchemaRegistryClientMessageConverterTests { - private ConfigurableApplicationContext schemaRegistryServerContext; + private RestTemplateBuilder restTemplateBuilder; @BeforeEach @@ -203,7 +203,8 @@ ServletWebServerFactory servletWebServerFactory() { } - @SpringBootApplication + @EnableAutoConfiguration + @Configuration @EnableSchemaRegistryServer public static class ServerApplication { public static void main(String[] args) {