|
19 | 19 | import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
|
20 | 20 | import static com.github.tomakehurst.wiremock.client.WireMock.post;
|
21 | 21 | import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
| 22 | +import static org.assertj.core.api.Assertions.fail; |
22 | 23 | import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
23 | 24 | import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
| 25 | +import static org.mockito.Matchers.any; |
| 26 | +import static org.mockito.Mockito.times; |
| 27 | +import static org.mockito.Mockito.verify; |
24 | 28 |
|
25 | 29 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
26 | 30 | import java.net.URI;
|
|
29 | 33 | import org.junit.Rule;
|
30 | 34 | import org.junit.Test;
|
31 | 35 | import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
| 36 | +import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain; |
| 37 | +import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; |
32 | 38 | import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
33 | 39 | import software.amazon.awssdk.awscore.AwsResponse;
|
34 | 40 | import software.amazon.awssdk.core.async.AsyncResponseTransformer;
|
35 | 41 | import software.amazon.awssdk.core.async.SdkPublisher;
|
| 42 | +import software.amazon.awssdk.core.exception.SdkClientException; |
36 | 43 | import software.amazon.awssdk.regions.Region;
|
37 | 44 | import software.amazon.awssdk.services.protocolquery.ProtocolQueryAsyncClient;
|
38 | 45 | import software.amazon.awssdk.services.protocolquery.model.ProtocolQueryException;
|
39 | 46 | import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
|
| 47 | +import software.amazon.awssdk.services.protocolrestjson.model.GetOperationWithBodyResponse; |
40 | 48 | import software.amazon.awssdk.services.protocolrestjson.model.ProtocolRestJsonException;
|
41 | 49 | import software.amazon.awssdk.services.protocolrestjson.model.StreamingOutputOperationResponse;
|
42 | 50 | import software.amazon.awssdk.utils.builder.SdkBuilder;
|
@@ -86,6 +94,26 @@ public void xmlClient_nonRetriableError_shouldNotifyAsyncResponseTransformer() {
|
86 | 94 | assertThat(responseTransformer.exceptionOccurred).isEqualTo(true);
|
87 | 95 | }
|
88 | 96 |
|
| 97 | + @Test |
| 98 | + public void jsonClient_incorrectCredentials_shouldNotifyAsyncResponseTransformer() { |
| 99 | + ProtocolRestJsonAsyncClient clientWithIncorrectCredentials = ProtocolRestJsonAsyncClient |
| 100 | + .builder() |
| 101 | + .credentialsProvider(AwsCredentialsProviderChain.of(ProfileCredentialsProvider.create("dummyprofile"))) |
| 102 | + .region(Region.US_EAST_1) |
| 103 | + .endpointOverride(URI.create("http://localhost:" + wireMock.port())) |
| 104 | + .build(); |
| 105 | + |
| 106 | + stubFor(post(anyUrl()) |
| 107 | + .willReturn(aResponse() |
| 108 | + .withStatus(400))); |
| 109 | + |
| 110 | + TestAsyncResponseTransformer<StreamingOutputOperationResponse> responseTransformer = new TestAsyncResponseTransformer<>(); |
| 111 | + assertThatThrownBy(() -> clientWithIncorrectCredentials.streamingOutputOperation(SdkBuilder::build, responseTransformer).join()) |
| 112 | + .hasCauseExactlyInstanceOf(SdkClientException.class) |
| 113 | + .hasMessageContaining("Unable to load credentials"); |
| 114 | + assertThat(responseTransformer.exceptionOccurred).isEqualTo(true); |
| 115 | + } |
| 116 | + |
89 | 117 | private class TestAsyncResponseTransformer<T extends AwsResponse> implements AsyncResponseTransformer<T, Void> {
|
90 | 118 | private boolean exceptionOccurred = false;
|
91 | 119 |
|
|
0 commit comments