use of software.amazon.awssdk.utils.StringInputStream in project aws-lambda-powertools-java by awslabs.
the class CloudFormationResponseTest method responseBodyStreamSuccessResponse.
@Test
void responseBodyStreamSuccessResponse() throws Exception {
CloudFormationCustomResourceEvent event = mockCloudFormationCustomResourceEvent();
Context context = mock(Context.class);
CloudFormationResponse cfnResponse = testableCloudFormationResponse();
StringInputStream stream = cfnResponse.responseBodyStream(event, context, Response.success());
String expectedJson = "{" + "\"Status\":\"SUCCESS\"," + "\"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 SqsLargeMessageAspectTest 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(FailedProcessingLargePayloadException.class).isThrownBy(() -> requestHandler.handleRequest(sqsEvent, context)).withCauseInstanceOf(IOException.class);
verify(s3Client, never()).deleteObject(any(DeleteObjectRequest.class));
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class S3PresignerIntegrationTest method execute.
private HttpExecuteResponse execute(PresignedRequest presigned, String payload) throws IOException {
SdkHttpClient httpClient = ApacheHttpClient.builder().build();
ContentStreamProvider requestPayload = payload == null ? null : () -> new StringInputStream(payload);
HttpExecuteRequest request = HttpExecuteRequest.builder().request(presigned.httpRequest()).contentStreamProvider(requestPayload).build();
return httpClient.prepareRequest(request).call();
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class DefaultClientBuilderTest method buildIncludesClientOverrides.
@Test
public void buildIncludesClientOverrides() {
List<ExecutionInterceptor> interceptors = new ArrayList<>();
ExecutionInterceptor interceptor = new ExecutionInterceptor() {
};
interceptors.add(interceptor);
RetryPolicy retryPolicy = RetryPolicy.builder().build();
Map<String, List<String>> headers = new HashMap<>();
List<String> headerValues = new ArrayList<>();
headerValues.add("value");
headers.put("client-override-test", headerValues);
List<MetricPublisher> metricPublishers = new ArrayList<>();
MetricPublisher metricPublisher = new MetricPublisher() {
@Override
public void publish(MetricCollection metricCollection) {
}
@Override
public void close() {
}
};
metricPublishers.add(metricPublisher);
ExecutionAttribute<String> execAttribute = new ExecutionAttribute<>("test");
ExecutionAttributes executionAttributes = ExecutionAttributes.builder().put(execAttribute, "value").build();
Signer signer = (request, execAttributes) -> request;
String suffix = "suffix";
String prefix = "prefix";
Duration apiCallTimeout = Duration.ofMillis(42);
Duration apiCallAttemptTimeout = Duration.ofMillis(43);
ProfileFile profileFile = ProfileFile.builder().content(new StringInputStream("")).type(ProfileFile.Type.CONFIGURATION).build();
String profileName = "name";
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder().executionInterceptors(interceptors).retryPolicy(retryPolicy).headers(headers).putAdvancedOption(SIGNER, signer).putAdvancedOption(USER_AGENT_SUFFIX, suffix).putAdvancedOption(USER_AGENT_PREFIX, prefix).apiCallTimeout(apiCallTimeout).apiCallAttemptTimeout(apiCallAttemptTimeout).putAdvancedOption(DISABLE_HOST_PREFIX_INJECTION, Boolean.TRUE).defaultProfileFile(profileFile).defaultProfileName(profileName).metricPublishers(metricPublishers).executionAttributes(executionAttributes).putAdvancedOption(ENDPOINT_OVERRIDDEN_OVERRIDE, Boolean.TRUE).build();
SdkClientConfiguration config = testClientBuilder().overrideConfiguration(overrideConfig).build().clientConfiguration;
assertThat(config.option(EXECUTION_INTERCEPTORS)).contains(interceptor);
assertThat(config.option(RETRY_POLICY)).isEqualTo(retryPolicy);
assertThat(config.option(ADDITIONAL_HTTP_HEADERS).get("client-override-test")).isEqualTo(headerValues);
assertThat(config.option(SIGNER)).isEqualTo(signer);
assertThat(config.option(USER_AGENT_SUFFIX)).isEqualTo(suffix);
assertThat(config.option(USER_AGENT_PREFIX)).isEqualTo(prefix);
assertThat(config.option(API_CALL_TIMEOUT)).isEqualTo(apiCallTimeout);
assertThat(config.option(API_CALL_ATTEMPT_TIMEOUT)).isEqualTo(apiCallAttemptTimeout);
assertThat(config.option(DISABLE_HOST_PREFIX_INJECTION)).isEqualTo(Boolean.TRUE);
assertThat(config.option(PROFILE_FILE)).isEqualTo(profileFile);
assertThat(config.option(PROFILE_NAME)).isEqualTo(profileName);
assertThat(config.option(METRIC_PUBLISHERS)).contains(metricPublisher);
assertThat(config.option(EXECUTION_ATTRIBUTES).getAttribute(execAttribute)).isEqualTo("value");
assertThat(config.option(ENDPOINT_OVERRIDDEN)).isEqualTo(Boolean.TRUE);
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class DefaultClientBuilderTest method overrideConfigurationReturnsSetValues.
@Test
public void overrideConfigurationReturnsSetValues() {
List<ExecutionInterceptor> interceptors = new ArrayList<>();
RetryPolicy retryPolicy = RetryPolicy.builder().build();
Map<String, List<String>> headers = new HashMap<>();
List<MetricPublisher> metricPublishers = new ArrayList<>();
ExecutionAttributes executionAttributes = new ExecutionAttributes();
Signer signer = (request, execAttributes) -> request;
String suffix = "suffix";
String prefix = "prefix";
Duration apiCallTimeout = Duration.ofMillis(42);
Duration apiCallAttemptTimeout = Duration.ofMillis(43);
ProfileFile profileFile = ProfileFile.builder().content(new StringInputStream("")).type(ProfileFile.Type.CONFIGURATION).build();
String profileName = "name";
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder().executionInterceptors(interceptors).retryPolicy(retryPolicy).headers(headers).putAdvancedOption(SIGNER, signer).putAdvancedOption(USER_AGENT_SUFFIX, suffix).putAdvancedOption(USER_AGENT_PREFIX, prefix).apiCallTimeout(apiCallTimeout).apiCallAttemptTimeout(apiCallAttemptTimeout).putAdvancedOption(DISABLE_HOST_PREFIX_INJECTION, Boolean.TRUE).defaultProfileFile(profileFile).defaultProfileName(profileName).metricPublishers(metricPublishers).executionAttributes(executionAttributes).putAdvancedOption(ENDPOINT_OVERRIDDEN_OVERRIDE, Boolean.TRUE).build();
TestClientBuilder builder = testClientBuilder().overrideConfiguration(overrideConfig);
ClientOverrideConfiguration builderOverrideConfig = builder.overrideConfiguration();
assertThat(builderOverrideConfig.executionInterceptors()).isEqualTo(interceptors);
assertThat(builderOverrideConfig.retryPolicy()).isEqualTo(Optional.of(retryPolicy));
assertThat(builderOverrideConfig.headers()).isEqualTo(headers);
assertThat(builderOverrideConfig.advancedOption(SIGNER)).isEqualTo(Optional.of(signer));
assertThat(builderOverrideConfig.advancedOption(USER_AGENT_SUFFIX)).isEqualTo(Optional.of(suffix));
assertThat(builderOverrideConfig.apiCallTimeout()).isEqualTo(Optional.of(apiCallTimeout));
assertThat(builderOverrideConfig.apiCallAttemptTimeout()).isEqualTo(Optional.of(apiCallAttemptTimeout));
assertThat(builderOverrideConfig.advancedOption(DISABLE_HOST_PREFIX_INJECTION)).isEqualTo(Optional.of(Boolean.TRUE));
assertThat(builderOverrideConfig.defaultProfileFile()).isEqualTo(Optional.of(profileFile));
assertThat(builderOverrideConfig.defaultProfileName()).isEqualTo(Optional.of(profileName));
assertThat(builderOverrideConfig.metricPublishers()).isEqualTo(metricPublishers);
assertThat(builderOverrideConfig.executionAttributes().getAttributes()).isEqualTo(executionAttributes.getAttributes());
assertThat(builderOverrideConfig.advancedOption(ENDPOINT_OVERRIDDEN_OVERRIDE)).isEqualTo(Optional.of(Boolean.TRUE));
}
Aggregations