use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class SelectObjectContentTest method runSimpleQuery.
private static CompletableFuture<Void> runSimpleQuery(S3AsyncClient s3, SelectObjectContentResponseHandler handler) {
InputSerialization inputSerialization = InputSerialization.builder().csv(CSVInput.builder().build()).compressionType(CompressionType.NONE).build();
OutputSerialization outputSerialization = OutputSerialization.builder().csv(CSVOutput.builder().build()).build();
SelectObjectContentRequest select = SelectObjectContentRequest.builder().bucket("test-bucket").key("test-key").expression("test-query").expressionType(ExpressionType.SQL).inputSerialization(inputSerialization).outputSerialization(outputSerialization).build();
return s3.selectObjectContent(select, handler);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_correctType.
@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_correctType() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<Code>InternalError</Code>\n" + "<Message>We encountered an internal error. Please try again.</Message>\n" + "<RequestId>656c76696e6727732072657175657374</RequestId>\n" + "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" + "</Error>";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
assertThatThrownBy(() -> s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join()).isInstanceOf(CompletionException.class).hasCauseInstanceOf(S3Exception.class);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_completeResponse.
@Test
public void completeMultipartUpload_asyncClient_completeResponse() {
String location = "http://Example-Bucket.s3.amazonaws.com/Example-Object";
String bucket = "Example-Bucket";
String key = "Example-Object";
String eTag = "\"3858f62230ac3c915f300c664312c11f-9\"";
String xmlResponseBody = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<CompleteMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n" + "<Location>%s</Location>\n" + "<Bucket>%s</Bucket>\n" + "<Key>%s</Key>\n" + "<ETag>%s</ETag>\n" + "</CompleteMultipartUploadResult>", location, bucket, key, eTag);
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
CompleteMultipartUploadResponse response = s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join();
assertThat(response.location()).isEqualTo(location);
assertThat(response.bucket()).isEqualTo(bucket);
assertThat(response.key()).isEqualTo(key);
assertThat(response.eTag()).isEqualTo(eTag);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_correctCode.
@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_correctCode() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<Code>CustomError</Code>\n" + "<Message>We encountered an internal error. Please try again.</Message>\n" + "<RequestId>656c76696e6727732072657175657374</RequestId>\n" + "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" + "</Error>";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
assertThatThrownBy(() -> s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join()).satisfies(e -> {
S3Exception s3Exception = (S3Exception) e.getCause();
assertThat(s3Exception.awsErrorDetails().errorCode()).isEqualTo("CustomError");
});
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_correctMessage.
@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_correctMessage() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<Code>CustomError</Code>\n" + "<Message>Foo bar</Message>\n" + "<RequestId>656c76696e6727732072657175657374</RequestId>\n" + "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" + "</Error>";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
assertThatThrownBy(() -> s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join()).satisfies(e -> {
S3Exception s3Exception = (S3Exception) e.getCause();
assertThat(s3Exception.awsErrorDetails().errorMessage()).isEqualTo("Foo bar");
});
}
Aggregations