1
1
package org .testcontainers .containers .localstack ;
2
2
3
+ import com .amazonaws .auth .AWSStaticCredentialsProvider ;
4
+ import com .amazonaws .auth .BasicAWSCredentials ;
3
5
import com .amazonaws .client .builder .AwsClientBuilder ;
4
6
import com .amazonaws .services .kms .AWSKMS ;
5
7
import com .amazonaws .services .kms .AWSKMSClientBuilder ;
@@ -73,11 +75,22 @@ public static class WithoutNetwork {
73
75
74
76
@ Test
75
77
public void s3TestOverBridgeNetwork () throws IOException {
78
+ // with_aws_sdk_v1 {
76
79
AmazonS3 s3 = AmazonS3ClientBuilder
77
80
.standard ()
78
- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .S3 ))
79
- .withCredentials (localstack .getDefaultCredentialsProvider ())
81
+ .withEndpointConfiguration (
82
+ new AwsClientBuilder .EndpointConfiguration (
83
+ localstack .getEndpointOverride (Service .S3 ).toString (),
84
+ localstack .getRegion ()
85
+ )
86
+ )
87
+ .withCredentials (
88
+ new AWSStaticCredentialsProvider (
89
+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
90
+ )
91
+ )
80
92
.build ();
93
+ // }
81
94
82
95
final String bucketName = "foo" ;
83
96
s3 .createBucket (bucketName );
@@ -103,6 +116,7 @@ public void s3TestOverBridgeNetwork() throws IOException {
103
116
104
117
@ Test
105
118
public void s3TestUsingAwsSdkV2 () {
119
+ // with_aws_sdk_v2 {
106
120
S3Client s3 = S3Client
107
121
.builder ()
108
122
.endpointOverride (localstack .getEndpointOverride (Service .S3 ))
@@ -113,6 +127,7 @@ public void s3TestUsingAwsSdkV2() {
113
127
)
114
128
.region (Region .of (localstack .getRegion ()))
115
129
.build ();
130
+ // }
116
131
117
132
final String bucketName = "foov2" ;
118
133
s3 .createBucket (b -> b .bucket (bucketName ));
@@ -126,8 +141,17 @@ public void s3TestUsingAwsSdkV2() {
126
141
public void sqsTestOverBridgeNetwork () {
127
142
AmazonSQS sqs = AmazonSQSClientBuilder
128
143
.standard ()
129
- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .SQS ))
130
- .withCredentials (localstack .getDefaultCredentialsProvider ())
144
+ .withEndpointConfiguration (
145
+ new AwsClientBuilder .EndpointConfiguration (
146
+ localstack .getEndpointOverride (Service .SQS ).toString (),
147
+ localstack .getRegion ()
148
+ )
149
+ )
150
+ .withCredentials (
151
+ new AWSStaticCredentialsProvider (
152
+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
153
+ )
154
+ )
131
155
.build ();
132
156
133
157
CreateQueueResult queueResult = sqs .createQueue ("baz" );
@@ -157,8 +181,17 @@ public void sqsTestOverBridgeNetwork() {
157
181
public void cloudWatchLogsTestOverBridgeNetwork () {
158
182
AWSLogs logs = AWSLogsClientBuilder
159
183
.standard ()
160
- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .CLOUDWATCHLOGS ))
161
- .withCredentials (localstack .getDefaultCredentialsProvider ())
184
+ .withEndpointConfiguration (
185
+ new AwsClientBuilder .EndpointConfiguration (
186
+ localstack .getEndpointOverride (Service .CLOUDWATCHLOGS ).toString (),
187
+ localstack .getRegion ()
188
+ )
189
+ )
190
+ .withCredentials (
191
+ new AWSStaticCredentialsProvider (
192
+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
193
+ )
194
+ )
162
195
.build ();
163
196
164
197
logs .createLogGroup (new CreateLogGroupRequest ("foo" ));
@@ -172,8 +205,17 @@ public void cloudWatchLogsTestOverBridgeNetwork() {
172
205
public void kmsKeyCreationTest () {
173
206
AWSKMS awskms = AWSKMSClientBuilder
174
207
.standard ()
175
- .withEndpointConfiguration (localstack .getEndpointConfiguration (Service .KMS ))
176
- .withCredentials (localstack .getDefaultCredentialsProvider ())
208
+ .withEndpointConfiguration (
209
+ new AwsClientBuilder .EndpointConfiguration (
210
+ localstack .getEndpointOverride (Service .KMS ).toString (),
211
+ localstack .getRegion ()
212
+ )
213
+ )
214
+ .withCredentials (
215
+ new AWSStaticCredentialsProvider (
216
+ new BasicAWSCredentials (localstack .getAccessKey (), localstack .getSecretKey ())
217
+ )
218
+ )
177
219
.build ();
178
220
179
221
String desc = String .format ("AWS CMK Description" );
@@ -198,8 +240,16 @@ public void samePortIsExposedForAllServices() {
198
240
);
199
241
assertEquals (
200
242
"Endpoint configuration have different endpoints" ,
201
- localstack .getEndpointConfiguration (Service .S3 ).getServiceEndpoint (),
202
- localstack .getEndpointConfiguration (Service .SQS ).getServiceEndpoint ()
243
+ new AwsClientBuilder .EndpointConfiguration (
244
+ localstack .getEndpointOverride (Service .S3 ).toString (),
245
+ localstack .getRegion ()
246
+ )
247
+ .getServiceEndpoint (),
248
+ new AwsClientBuilder .EndpointConfiguration (
249
+ localstack .getEndpointOverride (Service .SQS ).toString (),
250
+ localstack .getRegion ()
251
+ )
252
+ .getServiceEndpoint ()
203
253
);
204
254
}
205
255
}
@@ -302,8 +352,9 @@ public static class WithRegion {
302
352
303
353
@ Test
304
354
public void s3EndpointHasProperRegion () {
305
- final AwsClientBuilder .EndpointConfiguration endpointConfiguration = localstack .getEndpointConfiguration (
306
- Service .S3
355
+ final AwsClientBuilder .EndpointConfiguration endpointConfiguration = new AwsClientBuilder .EndpointConfiguration (
356
+ localstack .getEndpointOverride (Service .S3 ).toString (),
357
+ localstack .getRegion ()
307
358
);
308
359
assertEquals (
309
360
"The endpoint configuration has right region" ,
0 commit comments