use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_customized_multipart_checksum.
@Test
public void async_getObject_with_customized_multipart_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "abcdef==-12").withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.FORCE_SKIP);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_correct_http_checksum.
@Test
public void async_getObject_with_correct_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "i9aeUg==").withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.VALIDATED);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isEqualTo(Algorithm.CRC32);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class AsyncResponseTransformerTest method AsyncResponseTransformerPrepareCalled_BeforeCredentialsResolution.
@Test
public void AsyncResponseTransformerPrepareCalled_BeforeCredentialsResolution() {
S3AsyncClient client = S3AsyncClient.builder().credentialsProvider(AwsCredentialsProviderChain.of(ProfileCredentialsProvider.create("dummyprofile"))).build();
try {
client.getObject(b -> b.bucket("dummy").key("key"), asyncResponseTransformer).join();
fail("Expected an exception during credential resolution");
} catch (CompletionException e) {
}
verify(asyncResponseTransformer, times(1)).prepare();
verify(asyncResponseTransformer, times(1)).exceptionOccurred(any());
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class ContentLengthMismatchTest method contentShorterThanRequestBodyLengthFails.
@Test
public void contentShorterThanRequestBodyLengthFails() {
String bucket = "Example-Bucket";
String key = "Example-Object";
S3AsyncClient s3Client = getAsyncClientBuilder().build();
AsyncRequestBody requestBody = new AsyncRequestBody() {
@Override
public Optional<Long> contentLength() {
return Optional.of(2L);
}
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
AsyncRequestBody.fromString("A").subscribe(subscriber);
}
};
assertThatThrownBy(() -> s3Client.putObject(r -> r.bucket(bucket).key(key), requestBody).get(10, TimeUnit.SECONDS)).isInstanceOf(ExecutionException.class).hasMessageContaining("content-length");
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class ContentLengthMismatchTest method checksumDoesNotExceedAsyncRequestBodyLengthForPuts.
@Test
public void checksumDoesNotExceedAsyncRequestBodyLengthForPuts() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String content = "Hello, World!";
String eTag = "65A8E27D8879283831B664BD8B7F0AD4";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("ETag", eTag)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
PutObjectResponse response = s3Client.putObject(r -> r.bucket(bucket).key(key), new AsyncRequestBody() {
@Override
public Optional<Long> contentLength() {
return Optional.of((long) content.length());
}
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
AsyncRequestBody.fromString(content + " Extra stuff!").subscribe(subscriber);
}
}).join();
verify(putRequestedFor(anyUrl()).withRequestBody(equalTo(content)));
assertThat(response.eTag()).isEqualTo(eTag);
}
Aggregations