Skip to content

Commit b885082

Browse files
authored
Moves functional test from integration test suite to unit tests (aws#2745)
1 parent 9520147 commit b885082

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

services/s3/src/test/java/software/amazon/awssdk/services/s3/checksums/ChecksumResetsOnRetryTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
*/
5454
public class ChecksumResetsOnRetryTest {
5555
@Rule
56-
public WireMockRule mockServer = new WireMockRule(new WireMockConfiguration().port(0)
57-
.notifier(new ConsoleNotifier(true)));
56+
public WireMockRule mockServer = new WireMockRule(new WireMockConfiguration().port(0));
5857

5958
private S3Client s3Client;
6059

services/s3/src/it/java/software/amazon/awssdk/services/s3/AsyncResponseTransformerIntegrationTest.java renamed to services/s3/src/test/java/software/amazon/awssdk/services/s3/functionaltests/AsyncResponseTransformerTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,31 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.services.s3;
16+
package software.amazon.awssdk.services.s3.functionaltests;
1717

1818
import static org.assertj.core.api.Assertions.fail;
1919
import static org.mockito.Matchers.any;
2020
import static org.mockito.Mockito.times;
2121
import static org.mockito.Mockito.verify;
2222

23+
import java.util.concurrent.CompletionException;
2324
import org.junit.Test;
2425
import org.junit.runner.RunWith;
2526
import org.mockito.Mock;
2627
import org.mockito.runners.MockitoJUnitRunner;
2728
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
2829
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
2930
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
31+
import software.amazon.awssdk.services.s3.S3AsyncClient;
3032

3133
@RunWith(MockitoJUnitRunner.class)
32-
public class AsyncResponseTransformerIntegrationTest {
34+
public class AsyncResponseTransformerTest {
3335

3436
@Mock
3537
private AsyncResponseTransformer asyncResponseTransformer;
3638

3739
@Test
38-
public void AsyncResponseTransformerPrepareCalled_BeforeCredentailsResolution() {
40+
public void AsyncResponseTransformerPrepareCalled_BeforeCredentialsResolution() {
3941
S3AsyncClient client = S3AsyncClient.builder()
4042
.credentialsProvider(AwsCredentialsProviderChain.of(
4143
ProfileCredentialsProvider.create("dummyprofile")))
@@ -44,8 +46,7 @@ public void AsyncResponseTransformerPrepareCalled_BeforeCredentailsResolution()
4446
try {
4547
client.getObject(b -> b.bucket("dummy").key("key"), asyncResponseTransformer).join();
4648
fail("Expected an exception during credential resolution");
47-
} catch (Throwable t) {
48-
49+
} catch (CompletionException e) {
4950
}
5051

5152
verify(asyncResponseTransformer, times(1)).prepare();

test/protocol-tests/src/test/java/software/amazon/awssdk/protocol/tests/AsyncResponseTransformerTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
2020
import static com.github.tomakehurst.wiremock.client.WireMock.post;
2121
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
22+
import static org.assertj.core.api.Assertions.fail;
2223
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
2324
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;
2428

2529
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2630
import java.net.URI;
@@ -29,14 +33,18 @@
2933
import org.junit.Rule;
3034
import org.junit.Test;
3135
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
36+
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
37+
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
3238
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
3339
import software.amazon.awssdk.awscore.AwsResponse;
3440
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
3541
import software.amazon.awssdk.core.async.SdkPublisher;
42+
import software.amazon.awssdk.core.exception.SdkClientException;
3643
import software.amazon.awssdk.regions.Region;
3744
import software.amazon.awssdk.services.protocolquery.ProtocolQueryAsyncClient;
3845
import software.amazon.awssdk.services.protocolquery.model.ProtocolQueryException;
3946
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
47+
import software.amazon.awssdk.services.protocolrestjson.model.GetOperationWithBodyResponse;
4048
import software.amazon.awssdk.services.protocolrestjson.model.ProtocolRestJsonException;
4149
import software.amazon.awssdk.services.protocolrestjson.model.StreamingOutputOperationResponse;
4250
import software.amazon.awssdk.utils.builder.SdkBuilder;
@@ -86,6 +94,26 @@ public void xmlClient_nonRetriableError_shouldNotifyAsyncResponseTransformer() {
8694
assertThat(responseTransformer.exceptionOccurred).isEqualTo(true);
8795
}
8896

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+
89117
private class TestAsyncResponseTransformer<T extends AwsResponse> implements AsyncResponseTransformer<T, Void> {
90118
private boolean exceptionOccurred = false;
91119

0 commit comments

Comments
 (0)