use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class UploadRequestTest method bodyEqualsGivenBody.
@Test
public void bodyEqualsGivenBody() {
AsyncRequestBody requestBody = AsyncRequestBody.fromString("foo");
UploadRequest request = UploadRequest.builder().putObjectRequest(b -> b.bucket("bucket").key("key")).requestBody(requestBody).build();
assertThat(request.requestBody()).isSameAs(requestBody);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody 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.core.async.AsyncRequestBody 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);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class AsyncChecksumValidationInterceptorTest method modifyAsyncHttpContent_putObjectRequestChecksumEnabled_shouldWrapChecksumRequestBody.
@Test
public void modifyAsyncHttpContent_putObjectRequestChecksumEnabled_shouldWrapChecksumRequestBody() {
ExecutionAttributes executionAttributes = getExecutionAttributes();
Context.ModifyHttpRequest modifyHttpRequest = InterceptorTestUtils.modifyHttpRequestContext(PutObjectRequest.builder().build());
Optional<AsyncRequestBody> asyncRequestBody = interceptor.modifyAsyncHttpContent(modifyHttpRequest, executionAttributes);
assertThat(asyncRequestBody.isPresent()).isTrue();
assertThat(executionAttributes.getAttribute(CHECKSUM)).isNotNull();
assertThat(asyncRequestBody.get()).isExactlyInstanceOf(ChecksumCalculatingAsyncRequestBody.class);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class AsyncChecksumValidationInterceptorTest method modifyAsyncHttpContent_nonPutObjectRequest_shouldNotModify.
@Test
public void modifyAsyncHttpContent_nonPutObjectRequest_shouldNotModify() {
ExecutionAttributes executionAttributes = getExecutionAttributes();
Context.ModifyHttpRequest modifyHttpRequest = InterceptorTestUtils.modifyHttpRequestContext(GetObjectRequest.builder().build());
Optional<AsyncRequestBody> asyncRequestBody = interceptor.modifyAsyncHttpContent(modifyHttpRequest, executionAttributes);
assertThat(asyncRequestBody).isEqualTo(modifyHttpRequest.asyncRequestBody());
}
Aggregations