1616 */
1717package org .acme .aws2 .s3 ;
1818
19+ import java .net .URI ;
1920import java .util .Collections ;
2021import java .util .Locale ;
2122import java .util .Map ;
2728import org .eclipse .microprofile .config .ConfigProvider ;
2829import org .slf4j .Logger ;
2930import org .slf4j .LoggerFactory ;
31+ import org .testcontainers .containers .GenericContainer ;
3032import org .testcontainers .containers .output .Slf4jLogConsumer ;
31- import org .testcontainers .localstack . LocalStackContainer ;
33+ import org .testcontainers .containers . wait . strategy . Wait ;
3234import org .testcontainers .utility .DockerImageName ;
3335import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
3436import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
3941
4042public class Aws2S3TestResource implements QuarkusTestResourceLifecycleManager {
4143 private static final Logger LOG = LoggerFactory .getLogger (Aws2S3TestResource .class );
44+ private static final int FLOCI_PORT = 4566 ;
45+ private static final String ACCESS_KEY = "testAccessKeyId" ;
46+ private static final String SECRET_KEY = "testSecretKeyId" ;
47+ private static final String REGION = "us-east-1" ;
4248
43- private LocalStackContainer localstack ;
49+ private GenericContainer <?> floci ;
4450
4551 @ Override
4652 public Map <String , String > start () {
@@ -54,39 +60,41 @@ public Map<String, String> start() {
5460 final boolean realCredentialsProvided = accessKey .isPresent () && secretKey .isPresent () && region .isPresent ()
5561 && bucketName .isPresent ();
5662
57- //do not start a localstack, when real credentials are provided
5863 if (realCredentialsProvided ) {
5964 LOG .info ("Real backend will be used" );
6065 return Collections .emptyMap ();
6166 }
6267 LOG .info ("Mock backend will be used" );
6368
6469 DockerImageName imageName = DockerImageName
65- .parse (config .getValue ("localstack.container.image" , String .class ))
66- .asCompatibleSubstituteFor ("localstack/localstack" );
67- localstack = new LocalStackContainer (imageName )
68- .withServices ("s3" )
69- .withEnv ("LS_LOG" , "info" )
70- .withEnv ("AWS_ACCESS_KEY_ID" , "testAccessKeyId" )
71- .withEnv ("AWS_SECRET_ACCESS_KEY" , "testSecretKeyId" )
70+ .parse (config .getValue ("floci.container.image" , String .class ));
71+ floci = new GenericContainer <>(imageName )
72+ .withExposedPorts (FLOCI_PORT )
73+ .waitingFor (Wait .forHttp ("/_floci/health" ).forPort (FLOCI_PORT ))
74+ .withEnv ("AWS_ACCESS_KEY_ID" , ACCESS_KEY )
75+ .withEnv ("AWS_SECRET_ACCESS_KEY" , SECRET_KEY )
7276 .withLogConsumer (new Slf4jLogConsumer (LOG ));
73- localstack .start ();
77+ floci .start ();
7478
75- return Map .of ("camel.component.aws2-s3.accessKey" , localstack .getAccessKey (),
76- "camel.component.aws2-s3.secretKey" , localstack .getSecretKey (),
77- "camel.component.aws2-s3.region" , localstack .getRegion (),
79+ String endpoint = String .format ("http://%s:%d" , floci .getHost (), floci .getMappedPort (FLOCI_PORT ));
80+
81+ return Map .of ("camel.component.aws2-s3.accessKey" , ACCESS_KEY ,
82+ "camel.component.aws2-s3.secretKey" , SECRET_KEY ,
83+ "camel.component.aws2-s3.region" , REGION ,
7884 "camel.component.aws2-s3.override-endpoint" , "true" ,
79- "camel.component.aws2-s3.uri-endpoint-override" , localstack .getEndpoint ().toString (),
80- "cq.aws2-s3.example.bucketName" , createBucket ());
85+ "camel.component.aws2-s3.uri-endpoint-override" , endpoint ,
86+ "camel.component.aws2-s3.force-path-style" , "true" ,
87+ "cq.aws2-s3.example.bucketName" , createBucket (endpoint ));
8188 }
8289
83- private String createBucket () {
90+ private String createBucket (String endpoint ) {
8491 S3ClientBuilder clientBuilder = S3Client .builder ();
8592 clientBuilder
8693 .credentialsProvider (StaticCredentialsProvider
87- .create (AwsBasicCredentials .create (localstack .getAccessKey (), localstack .getSecretKey ())))
88- .endpointOverride (localstack .getEndpoint ())
89- .region (Region .of (localstack .getRegion ()));
94+ .create (AwsBasicCredentials .create (ACCESS_KEY , SECRET_KEY )))
95+ .endpointOverride (URI .create (endpoint ))
96+ .forcePathStyle (true )
97+ .region (Region .of (REGION ));
9098 final S3Client s3Client = clientBuilder .build ();
9199
92100 final String bucketName = "camel-quarkus-" + RandomStringUtils .secure ().nextAlphanumeric (49 ).toLowerCase (Locale .ROOT );
@@ -96,8 +104,8 @@ private String createBucket() {
96104
97105 @ Override
98106 public void stop () {
99- if (localstack != null ) {
100- localstack .stop ();
107+ if (floci != null ) {
108+ floci .stop ();
101109 }
102110 }
103111}
0 commit comments