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);
}
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));
}
Aggregations