Search in sources :

Example 46 with StringInputStream

use of software.amazon.awssdk.utils.StringInputStream in project aws-lambda-powertools-java by awslabs.

the class CloudFormationResponseTest method responseBodyStreamFailedResponse.

@Test
void responseBodyStreamFailedResponse() throws Exception {
    CloudFormationCustomResourceEvent event = mockCloudFormationCustomResourceEvent();
    Context context = mock(Context.class);
    CloudFormationResponse cfnResponse = testableCloudFormationResponse();
    StringInputStream stream = cfnResponse.responseBodyStream(event, context, Response.failed());
    String expectedJson = "{" + "\"Status\":\"FAILED\"," + "\"Reason\":\"See the details in CloudWatch Log Stream: null\"," + "\"PhysicalResourceId\":null," + "\"StackId\":null," + "\"RequestId\":null," + "\"LogicalResourceId\":null," + "\"NoEcho\":false," + "\"Data\":null" + "}";
    assertThat(stream.getString()).isEqualTo(expectedJson);
}
Also used : Context(com.amazonaws.services.lambda.runtime.Context) CloudFormationCustomResourceEvent(com.amazonaws.services.lambda.runtime.events.CloudFormationCustomResourceEvent) StringInputStream(software.amazon.awssdk.utils.StringInputStream) Test(org.junit.jupiter.api.Test)

Example 47 with StringInputStream

use of software.amazon.awssdk.utils.StringInputStream in project aws-lambda-powertools-java by awslabs.

the class SqsUtilsLargeMessageTest method shouldFailEntireBatchIfFailedProcessingDownloadMessageFromS3.

@Test
public void shouldFailEntireBatchIfFailedProcessingDownloadMessageFromS3() {
    ResponseInputStream<GetObjectResponse> s3Response = new ResponseInputStream<>(GetObjectResponse.builder().build(), AbortableInputStream.create(new StringInputStream("test") {

        @Override
        public void close() throws IOException {
            throw new IOException("Failed");
        }
    }));
    when(s3Client.getObject(any(GetObjectRequest.class))).thenReturn(s3Response);
    String messageBody = "[\"software.amazon.payloadoffloading.PayloadS3Pointer\",{\"s3BucketName\":\"" + BUCKET_NAME + "\",\"s3Key\":\"" + BUCKET_KEY + "\"}]";
    SQSEvent sqsEvent = messageWithBody(messageBody);
    assertThatExceptionOfType(SqsLargeMessageAspect.FailedProcessingLargePayloadException.class).isThrownBy(() -> SqsUtils.enrichedMessageFromS3(sqsEvent, sqsMessages -> sqsMessages.get(0).getBody())).withCauseInstanceOf(IOException.class);
    verify(s3Client, never()).deleteObject(any(DeleteObjectRequest.class));
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) StringInputStream(software.amazon.awssdk.utils.StringInputStream) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) SQSEvent(com.amazonaws.services.lambda.runtime.events.SQSEvent) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) IOException(java.io.IOException) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) SqsLargeMessageAspect(software.amazon.lambda.powertools.sqs.internal.SqsLargeMessageAspect) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

StringInputStream (software.amazon.awssdk.utils.StringInputStream)47 Test (org.junit.Test)20 Test (org.junit.jupiter.api.Test)19 ProfileFile (software.amazon.awssdk.profiles.ProfileFile)19 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 ProfileCredentialsUtils (software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils)9 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)7 AbortableInputStream (software.amazon.awssdk.http.AbortableInputStream)7 Region (software.amazon.awssdk.regions.Region)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Optional (java.util.Optional)6 ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)6 URI (java.net.URI)5 Duration (java.time.Duration)5 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)5 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)5 SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)4 SdkAutoCloseable (software.amazon.awssdk.utils.SdkAutoCloseable)4 ArrayList (java.util.ArrayList)3