Search in sources :

Example 6 with StringInputStream

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);
}
Also used : ProfileFile(software.amazon.awssdk.profiles.ProfileFile) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SdkException(software.amazon.awssdk.core.exception.SdkException) Test(org.junit.Test) AllTypesResponse(software.amazon.awssdk.services.protocolrestjson.model.AllTypesResponse) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) WireMock.anyRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.anyRequestedFor) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) AwsClientBuilder(software.amazon.awssdk.awscore.client.builder.AwsClientBuilder) StringInputStream(software.amazon.awssdk.utils.StringInputStream) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) URI(java.net.URI) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) RetryMode(software.amazon.awssdk.core.retry.RetryMode) Region(software.amazon.awssdk.regions.Region) ExecutorService(java.util.concurrent.ExecutorService) StringInputStream(software.amazon.awssdk.utils.StringInputStream) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.Test)

Example 7 with StringInputStream

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();
}
Also used : StringInputStream(software.amazon.awssdk.utils.StringInputStream) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse)

Example 8 with StringInputStream

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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) SdkException(software.amazon.awssdk.core.exception.SdkException) Test(org.junit.Test) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) Context(software.amazon.awssdk.core.interceptor.Context) Mockito(org.mockito.Mockito) StringInputStream(software.amazon.awssdk.utils.StringInputStream) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AnonymousCredentialsProvider(software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider) Region(software.amazon.awssdk.regions.Region) StringInputStream(software.amazon.awssdk.utils.StringInputStream) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.Test)

Example 9 with StringInputStream

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");
    });
}
Also used : StringInputStream(software.amazon.awssdk.utils.StringInputStream) ProfileCredentialsUtils(software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

Example 10 with StringInputStream

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");
    });
}
Also used : StringInputStream(software.amazon.awssdk.utils.StringInputStream) ProfileCredentialsUtils(software.amazon.awssdk.auth.credentials.internal.ProfileCredentialsUtils) ProfileFile(software.amazon.awssdk.profiles.ProfileFile) Test(org.junit.jupiter.api.Test)

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