-
Notifications
You must be signed in to change notification settings - Fork 0
/
S3IntegrationTest.java
44 lines (36 loc) · 2.01 KB
/
S3IntegrationTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io.github.test_containers_sandbox.configuration;
import static com.amazonaws.regions.ServiceAbbreviations.S3;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.flywaydb.core.Flyway;
import org.junit.jupiter.api.AfterAll;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
public class S3IntegrationTest {
static final DockerImageName localstackImage = DockerImageName.parse("localstack/localstack");
static final LocalStackContainer localStackContainer = new LocalStackContainer(localstackImage)
.withServices(Service.S3);
@DynamicPropertySource
static void registerS3Properties(DynamicPropertyRegistry registry) {
localStackContainer.start();
await().until(localStackContainer::isRunning);
registry.add("bucket.name", () -> "testing-bucket");
registry.add("bucket.endpoint", () -> localStackContainer.getEndpoint().toString());
registry.add("bucket.access-key", localStackContainer::getAccessKey);
registry.add("bucket.secret-key", localStackContainer::getSecretKey);
registry.add("bucket.region", localStackContainer::getRegion);
}
}