Fix AmazonS3ConfigurationTests for proper configs
The `CompatibleStorageAmazonS3Configuration` and `AmazonS3Configuration` are really auto-configurations, so they have to take an effect already after end-user configurations processing * Fix `AmazonS3ConfigurationTests` to configure an `ApplicationContextRunner` in a proper way putting auto-configurations to their `AutoConfigurations.of()` part and leaving only a `TestConfiguration.class` as a `UserConfiguration`
This commit is contained in:
@@ -26,27 +26,31 @@ import io.awspring.cloud.core.region.StaticRegionProvider;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.context.annotation.UserConfigurations;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* @author Timo Salm
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class AmazonS3ConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
.withConfiguration(UserConfigurations.of(CompatibleStorageAmazonS3Configuration.class,
|
||||
AmazonS3Configuration.class, TestConfiguration.class));
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(
|
||||
CompatibleStorageAmazonS3Configuration.class,
|
||||
AmazonS3Configuration.class))
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
|
||||
private final String testRegionName = "eu-central-1";
|
||||
private static final String TEST_REGION_NAME = "eu-central-1";
|
||||
|
||||
@Test
|
||||
public void testAmazonS3Configuration() {
|
||||
runner.withPropertyValues().run(context -> {
|
||||
final AmazonS3Client amazonS3 = (AmazonS3Client) context.getBean(AmazonS3.class);
|
||||
Assertions.assertNotNull(amazonS3);
|
||||
Assertions.assertEquals(testRegionName, amazonS3.getRegionName());
|
||||
Assertions.assertEquals(TEST_REGION_NAME, amazonS3.getRegionName());
|
||||
Assertions.assertTrue(amazonS3.getResourceUrl("b", "k")
|
||||
.startsWith("https://s3.eu-central-1.amazonaws.com"));
|
||||
});
|
||||
@@ -65,14 +69,17 @@ public class AmazonS3ConfigurationTests {
|
||||
}
|
||||
|
||||
private static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
RegionProvider regionProvider() {
|
||||
return new StaticRegionProvider("eu-central-1");
|
||||
return new StaticRegionProvider(TEST_REGION_NAME);
|
||||
}
|
||||
|
||||
@Bean
|
||||
AWSCredentialsProvider awsCredentialsProvider() {
|
||||
return new AWSStaticCredentialsProvider(new BasicAWSCredentials("accessKey", "secretKey"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user