From 2eb9339b14f1ab49759a553a58fa3856f4cb0961 Mon Sep 17 00:00:00 2001 From: Iuliia Sobolevska Date: Mon, 27 Nov 2023 18:06:05 -0800 Subject: [PATCH] fix: correct conditional for S3CrtAsyncClientAutoConfiguration --- .../s3/S3CrtAsyncClientAutoConfiguration.java | 2 +- .../s3/S3CrtAsyncClientAutoConfigurationTests.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfiguration.java b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfiguration.java index 6d55d1546..25d9449d6 100644 --- a/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfiguration.java +++ b/spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfiguration.java @@ -42,7 +42,7 @@ * @since 3.0 */ @AutoConfiguration -@ConditionalOnClass({ S3Client.class }) +@ConditionalOnClass({ S3Client.class, S3AsyncClient.class }) @EnableConfigurationProperties({ S3Properties.class }) @ConditionalOnProperty(name = "spring.cloud.aws.s3.enabled", havingValue = "true", matchIfMissing = true) @AutoConfigureBefore(S3TransferManagerAutoConfiguration.class) diff --git a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfigurationTests.java b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfigurationTests.java index 804dc25f6..bdd5af53b 100644 --- a/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfigurationTests.java +++ b/spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/s3/S3CrtAsyncClientAutoConfigurationTests.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.test.util.ReflectionTestUtils; import software.amazon.awssdk.http.async.SdkAsyncHttpClient; @@ -92,6 +93,14 @@ void setsPropertiesOnClient() { }); } + @Test + void handlesMissingS3AsyncClient() { + contextRunner.withClassLoader(new FilteredClassLoader(S3AsyncClient.class)).run(context -> { + assertThat(context).hasNotFailed(); + assertThat(context).doesNotHaveBean(S3AsyncClient.class); + }); + } + private static S3NativeClientConfiguration s3NativeClientConfiguration(S3AsyncClient client) { ConfiguredAwsClient configuredClient = new ConfiguredAwsClient(client); SdkAsyncHttpClient sdkAsyncHttpClient = configuredClient.getAsyncHttpClient();