14
14
import org .testcontainers .junit .jupiter .Container ;
15
15
import org .testcontainers .junit .jupiter .Testcontainers ;
16
16
import org .testcontainers .utility .DockerImageName ;
17
+ import org .testcontainers .utility .MountableFile ;
17
18
import software .amazon .awssdk .core .sync .RequestBody ;
18
19
import software .amazon .awssdk .services .s3 .S3Client ;
19
20
import software .amazon .awssdk .services .s3 .model .GetObjectRequest ;
21
+ import software .amazon .awssdk .services .s3 .model .NoSuchKeyException ;
20
22
import software .amazon .awssdk .services .s3 .model .PutObjectRequest ;
23
+ import software .amazon .awssdk .services .sqs .SqsAsyncClient ;
21
24
import software .amazon .awssdk .services .sqs .SqsClient ;
22
25
import software .amazon .awssdk .services .sqs .model .SendMessageRequest ;
23
26
24
27
import static org .awaitility .Awaitility .given ;
25
28
import static org .junit .jupiter .api .Assertions .assertNotNull ;
26
- import static org .testcontainers .containers .BindMode .READ_ONLY ;
27
29
import static org .testcontainers .containers .localstack .LocalStackContainer .Service ;
28
30
import static org .testcontainers .containers .localstack .LocalStackContainer .Service .SQS ;
29
31
@@ -35,21 +37,22 @@ class ImageUploadEventListenerIT {
35
37
static LocalStackContainer localStack =
36
38
new LocalStackContainer (DockerImageName .parse ("localstack/localstack:4.0.1" ))
37
39
.withServices (Service .S3 , Service .SQS )
38
- .withClasspathResourceMapping ( "/ localstack" , "/docker-entrypoint-initaws .d", READ_ONLY )
40
+ .withCopyFileToContainer ( MountableFile . forClasspathResource ( " localstack/ " , 0777 ), "/etc/localstack/init/ready .d" )
39
41
.waitingFor (Wait .forLogMessage (".*Initialized\\ .\n " , 1 ));
40
42
41
43
@ DynamicPropertySource
42
44
static void configureLocalStackAccess (DynamicPropertyRegistry registry ) {
43
45
registry .add ("spring.cloud.aws.credentials.secret-key" , () -> "foo" );
44
46
registry .add ("spring.cloud.aws.credentials.access-key" , () -> "bar" );
47
+ registry .add ("spring.cloud.aws.sqs.enabled" , () -> "true" );
45
48
registry .add ("spring.cloud.aws.endpoint" , () -> localStack .getEndpointOverride (SQS ));
46
49
}
47
50
48
51
@ Autowired
49
52
private S3Client s3Client ;
50
53
51
54
@ Autowired
52
- private SqsClient sqsClient ;
55
+ private SqsAsyncClient sqsClient ;
53
56
54
57
@ Test
55
58
void shouldProcessIncomingUploadEventAndUploadThumbnailImage () throws IOException {
@@ -71,6 +74,7 @@ void shouldProcessIncomingUploadEventAndUploadThumbnailImage() throws IOExceptio
71
74
given ()
72
75
.atMost (Duration .ofSeconds (5 ))
73
76
.await ()
77
+ .ignoreException (NoSuchKeyException .class )
74
78
.untilAsserted (() -> assertNotNull (s3Client .getObject (GetObjectRequest .builder ().bucket ("processed-images" ).key ("thumbnail-duke-mascot.png" ).build ())));
75
79
}
76
80
}
0 commit comments