use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class ClientRetryModeTestSuite method retryModeCanBeSetByProfileFile.
@Test
public void retryModeCanBeSetByProfileFile() {
ProfileFile profileFile = ProfileFile.builder().content(new StringInputStream("[profile foo]\n" + "retry_mode = standard")).type(ProfileFile.Type.CONFIGURATION).build();
stubThrottlingResponse();
ClientT client = clientBuilder().overrideConfiguration(o -> o.defaultProfileFile(profileFile).defaultProfileName("foo")).build();
assertThatThrownBy(() -> callAllTypes(client)).isInstanceOf(SdkException.class);
verifyRequestCount(3);
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class AwsServiceExceptionSerializationTest method createException.
private AwsServiceException createException() {
AbortableInputStream contentStream = AbortableInputStream.create(new StringInputStream("some content"));
SdkHttpResponse httpResponse = SdkHttpFullResponse.builder().statusCode(403).statusText("SomeText").putHeader("sample", "value").content(contentStream).build();
AwsErrorDetails errorDetails = AwsErrorDetails.builder().errorCode("someCode").errorMessage("message").serviceName("someService").sdkHttpResponse(httpResponse).build();
return AwsServiceException.builder().awsErrorDetails(errorDetails).statusCode(403).cause(new RuntimeException("someThrowable")).clockSkew(Duration.ofSeconds(2)).requestId("requestId").extendedRequestId("extendedRequestId").message("message").build();
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class EndpointDiscoveryTest method canBeEnabledViaProfileOnOverrideConfiguration.
@Test(timeout = 10_000)
public void canBeEnabledViaProfileOnOverrideConfiguration() throws InterruptedException {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "aws_endpoint_discovery_enabled = true";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
DynamoDbClient dynamoDb = DynamoDbClient.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).build();
assertThatThrownBy(dynamoDb::listTables).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context;
do {
Thread.sleep(1);
context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor, atLeastOnce()).beforeTransmission(context.capture(), any());
} while (context.getAllValues().size() < 2);
assertThat(context.getAllValues().stream().anyMatch(v -> v.httpRequest().firstMatchingHeader("X-Amz-Target").map(h -> h.equals("DynamoDB_20120810.DescribeEndpoints")).orElse(false))).isTrue();
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class SsoProfileTest method createSsoCredentialsProvider_SsoRegionMissing_throwException.
@Test
public void createSsoCredentialsProvider_SsoRegionMissing_throwException() {
String profileContent = "[profile foo]\n" + "sso_account_id=012345678901\n" + "sso_role_name=SampleRole\n" + "sso_start_url=https://d-abc123.awsapps.com/start-beta\n";
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(profileContent)).type(ProfileFile.Type.CONFIGURATION).build();
assertThat(profiles.profile("foo")).hasValueSatisfying(profile -> {
assertThatThrownBy(() -> new ProfileCredentialsUtils(profiles, profile, profiles::profile).credentialsProvider()).hasMessageContaining("Profile property 'sso_region' was not configured");
});
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class SsoProfileTest method createSsoCredentialsProvider_SsoStartUrlMissing_throwException.
@Test
public void createSsoCredentialsProvider_SsoStartUrlMissing_throwException() {
String profileContent = "[profile foo]\n" + "sso_account_id=012345678901\n" + "sso_region=us-east-1\n" + "sso_role_name=SampleRole\n";
ProfileFile profiles = ProfileFile.builder().content(new StringInputStream(profileContent)).type(ProfileFile.Type.CONFIGURATION).build();
assertThat(profiles.profile("foo")).hasValueSatisfying(profile -> {
assertThatThrownBy(() -> new ProfileCredentialsUtils(profiles, profile, profiles::profile).credentialsProvider()).hasMessageContaining("Profile property 'sso_start_url' was not configured");
});
}
Aggregations