1818import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
1919import static com .github .tomakehurst .wiremock .client .WireMock .any ;
2020import static com .github .tomakehurst .wiremock .client .WireMock .anyUrl ;
21+ import static com .github .tomakehurst .wiremock .client .WireMock .head ;
2122import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
2223import static org .assertj .core .api .Assertions .assertThat ;
24+ import static org .mockito .ArgumentMatchers .any ;
25+ import static org .mockito .Mockito .verify ;
2326
27+ import com .github .tomakehurst .wiremock .client .WireMock ;
2428import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
2529import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
2630import java .net .URI ;
31+ import java .util .concurrent .Executor ;
2732import org .junit .jupiter .api .AfterEach ;
2833import org .junit .jupiter .api .BeforeAll ;
2934import org .junit .jupiter .api .BeforeEach ;
3035import org .junit .jupiter .api .Test ;
36+ import org .mockito .ArgumentMatchers ;
37+ import org .mockito .Mockito ;
3138import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
3239import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
3340import software .amazon .awssdk .crt .CrtResource ;
4249@ WireMockTest
4350public class S3CrtClientWiremockTest {
4451
52+ private static final String LOCATION = "http://Example-Bucket.s3.amazonaws.com/Example-Object" ;
53+ private static final String BUCKET = "Example-Bucket" ;
54+ private static final String KEY = "Example-Object" ;
55+ private static final String E_TAG = "\" 3858f62230ac3c915f300c664312c11f-9\" " ;
56+ private static final String XML_RESPONSE_BODY = String .format (
57+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
58+ + "<CompleteMultipartUploadResult xmlns=\" http://s3.amazonaws.com/doc/2006-03-01/\" >\n "
59+ + "<Location>%s</Location>\n "
60+ + "<Bucket>%s</Bucket>\n "
61+ + "<Key>%s</Key>\n "
62+ + "<ETag>%s</ETag>\n "
63+ + "</CompleteMultipartUploadResult>" , LOCATION , BUCKET , KEY , E_TAG );
4564 private S3AsyncClient s3AsyncClient ;
65+ private S3AsyncClient clientWithCustomExecutor ;
66+ private SpyableExecutor mockExecutor ;
4667
4768 @ BeforeAll
4869 public static void setUpBeforeAll () {
@@ -68,27 +89,43 @@ public void tearDown() {
6889
6990 @ Test
7091 public void completeMultipartUpload_completeResponse () {
71- String location = "http://Example-Bucket.s3.amazonaws.com/Example-Object" ;
72- String bucket = "Example-Bucket" ;
73- String key = "Example-Object" ;
74- String eTag = "\" 3858f62230ac3c915f300c664312c11f-9\" " ;
75- String xmlResponseBody = String .format (
76- "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
77- + "<CompleteMultipartUploadResult xmlns=\" http://s3.amazonaws.com/doc/2006-03-01/\" >\n "
78- + "<Location>%s</Location>\n "
79- + "<Bucket>%s</Bucket>\n "
80- + "<Key>%s</Key>\n "
81- + "<ETag>%s</ETag>\n "
82- + "</CompleteMultipartUploadResult>" , location , bucket , key , eTag );
83-
84- stubFor (any (anyUrl ()).willReturn (aResponse ().withStatus (200 ).withBody (xmlResponseBody )));
92+ stubFor (any (anyUrl ()).willReturn (aResponse ().withStatus (200 ).withBody (XML_RESPONSE_BODY )));
8593
8694 CompleteMultipartUploadResponse response = s3AsyncClient .completeMultipartUpload (
87- r -> r .bucket (bucket ).key (key ).uploadId ("upload-id" )).join ();
95+ r -> r .bucket (BUCKET ).key (KEY ).uploadId ("upload-id" )).join ();
8896
89- assertThat (response .location ()).isEqualTo (location );
90- assertThat (response .bucket ()).isEqualTo (bucket );
91- assertThat (response .key ()).isEqualTo (key );
92- assertThat (response .eTag ()).isEqualTo (eTag );
97+ assertThat (response .location ()).isEqualTo (LOCATION );
98+ assertThat (response .bucket ()).isEqualTo (BUCKET );
99+ assertThat (response .key ()).isEqualTo (KEY );
100+ assertThat (response .eTag ()).isEqualTo (E_TAG );
101+ }
102+
103+ @ Test
104+ void overrideResponseCompletionExecutor_shouldCompleteWithCustomExecutor (WireMockRuntimeInfo wiremock ) {
105+
106+ mockExecutor = Mockito .spy (new SpyableExecutor ());
107+
108+ try (S3AsyncClient s3AsyncClient = S3AsyncClient .crtBuilder ()
109+ .region (Region .US_EAST_1 )
110+ .endpointOverride (URI .create ("http://localhost:" + wiremock .getHttpPort ()))
111+ .futureCompletionExecutor (mockExecutor )
112+ .credentialsProvider (
113+ StaticCredentialsProvider .create (AwsBasicCredentials .create ("key" ,
114+ "secret" )))
115+ .build ()) {
116+ stubFor (any (anyUrl ()).willReturn (aResponse ().withStatus (200 ).withBody (XML_RESPONSE_BODY )));
117+
118+ CompleteMultipartUploadResponse response = s3AsyncClient .completeMultipartUpload (
119+ r -> r .bucket (BUCKET ).key (KEY ).uploadId ("upload-id" )).join ();
120+
121+ verify (mockExecutor ).execute (any (Runnable .class ));
122+ }
123+ }
124+
125+ private static class SpyableExecutor implements Executor {
126+ @ Override
127+ public void execute (Runnable command ) {
128+ command .run ();
129+ }
93130 }
94131}
0 commit comments