org.testcontainers.containers.localstack.LocalStackContainer Java Examples

The following examples show how to use org.testcontainers.containers.localstack.LocalStackContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamoDBIOTestHelper.java    From beam with Apache License 2.0 5 votes vote down vote up
static AmazonDynamoDB getDynamoDBClient() {
  // Note: each test case got to have their own dynamo client obj, can't be shared
  // Otherwise will run into connection pool issue
  return AmazonDynamoDBClientBuilder.standard()
      .withEndpointConfiguration(
          localStackContainer.getEndpointConfiguration(LocalStackContainer.Service.DYNAMODB))
      .withCredentials(localStackContainer.getDefaultCredentialsProvider())
      .build();
}
 
Example #2
Source File: AWSS3LocalContainerService.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonS3 getClient() {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setProtocol(Protocol.HTTP);

    return AmazonS3ClientBuilder
            .standard()
            .withEndpointConfiguration(getContainer().getEndpointConfiguration(LocalStackContainer.Service.S3))
            .withCredentials(getContainer().getDefaultCredentialsProvider())
            .withClientConfiguration(clientConfiguration)
            .build();
}
 
Example #3
Source File: DynamoDBIOTestHelper.java    From beam with Apache License 2.0 5 votes vote down vote up
static void startServerClient() {
  localStackContainer.start();

  if (dynamoDBClient == null) {
    dynamoDBClient =
        AmazonDynamoDBClientBuilder.standard()
            .withEndpointConfiguration(
                localStackContainer.getEndpointConfiguration(
                    LocalStackContainer.Service.DYNAMODB))
            .withCredentials(localStackContainer.getDefaultCredentialsProvider())
            .build();
  }
}
 
Example #4
Source File: SqsResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    DockerClientFactory.instance().client();
    String queueUrl;
    try {
        services = new LocalStackContainer("0.11.1").withServices(Service.SQS);
        services.start();
        StaticCredentialsProvider staticCredentials = StaticCredentialsProvider
            .create(AwsBasicCredentials.create("accesskey", "secretKey"));

        client = SqsClient.builder()
            .endpointOverride(new URI(endpoint()))
            .credentialsProvider(staticCredentials)
            .httpClientBuilder(UrlConnectionHttpClient.builder())
            .region(Region.US_EAST_1).build();

        queueUrl = client.createQueue(q -> q.queueName(QUEUE_NAME)).queueUrl();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Could not start localstack server", e);
    }

    Map<String, String> properties = new HashMap<>();
    properties.put("quarkus.sqs.endpoint-override", endpoint());
    properties.put("quarkus.sqs.aws.region", "us-east-1");
    properties.put("quarkus.sqs.aws.credentials.type", "static");
    properties.put("quarkus.sqs.aws.credentials.static-provider.access-key-id", "accessKey");
    properties.put("quarkus.sqs.aws.credentials.static-provider.secret-access-key", "secretKey");
    properties.put("queue.url", queueUrl);

    return properties;
}
 
Example #5
Source File: AWSSQSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
@Override
public AWSSQSClient getClient() {
    AmazonSQS sqs = AmazonSQSClientBuilder
            .standard()
            .withEndpointConfiguration(getContainer()
                    .getEndpointConfiguration(LocalStackContainer.Service.SQS))
            .withCredentials(getContainer().getDefaultCredentialsProvider())
            .build();

    return new AWSSQSClient(sqs);
}
 
Example #6
Source File: DynamodbResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    DockerClientFactory.instance().client();
    try {
        dynamodb = new LocalStackContainer().withServices(Service.DYNAMODB);
        dynamodb.start();

        client = DynamoDbClient.builder()
            .endpointOverride(new URI(endpoint()))
            .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("accesskey", "secretKey")))
            .httpClientBuilder(UrlConnectionHttpClient.builder())
            .region(Region.US_EAST_1).build();

        client.createTable(tableRequest ->
            tableRequest.tableName(TABLE_NAME)
                .keySchema(keySchema -> keySchema.attributeName("fruitName").keyType(KeyType.HASH))
                .attributeDefinitions(attrDef -> attrDef.attributeName("fruitName").attributeType(ScalarAttributeType.S))
                .provisionedThroughput(throughput -> throughput.writeCapacityUnits(1L).readCapacityUnits(1L)));
    } catch (Exception e) {
        throw new RuntimeException("Could not start Dynamodb localstack server", e);
    }

    Map<String, String> properties = new HashMap<>();
    properties.put("quarkus.dynamodb.endpoint-override", endpoint());
    properties.put("quarkus.dynamodb.aws.region", "us-east-1");
    properties.put("quarkus.dynamodb.aws.credentials.type", "static");
    properties.put("quarkus.dynamodb.aws.credentials.static-provider.access-key-id", "accessKey");
    properties.put("quarkus.dynamodb.aws.credentials.static-provider.secret-access-key", "secretKey");

    return properties;
}
 
Example #7
Source File: SesResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    DockerClientFactory.instance().client();
    try {
        services = new LocalStackContainer("0.11.1").withServices(Service.SES);
        services.start();
        StaticCredentialsProvider staticCredentials = StaticCredentialsProvider
            .create(AwsBasicCredentials.create("accesskey", "secretKey"));

        client = SesClient.builder()
            .endpointOverride(new URI(endpoint()))
            .credentialsProvider(staticCredentials)
            .httpClientBuilder(UrlConnectionHttpClient.builder())
            .region(Region.US_EAST_1).build();

        client.verifyEmailIdentity(req -> req.emailAddress(FROM_EMAIL));
        client.verifyEmailIdentity(req -> req.emailAddress(TO_EMAIL));

    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Could not start localstack server", e);
    }

    Map<String, String> properties = new HashMap<>();
    properties.put("quarkus.ses.endpoint-override", endpoint());
    properties.put("quarkus.ses.aws.region", "us-east-1");
    properties.put("quarkus.ses.aws.credentials.type", "static");
    properties.put("quarkus.ses.aws.credentials.static-provider.access-key-id", "accessKey");
    properties.put("quarkus.ses.aws.credentials.static-provider.secret-access-key", "secretKey");

    return properties;
}
 
Example #8
Source File: AWSSNSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
@Override
public AWSSQSClient getClient() {
    AmazonSQS sqs = AmazonSQSClientBuilder
            .standard()
            .withEndpointConfiguration(getContainer()
                    .getEndpointConfiguration(LocalStackContainer.Service.SQS))
            .withCredentials(getContainer().getDefaultCredentialsProvider())
            .build();

    return new AWSSQSClient(sqs);
}
 
Example #9
Source File: S3Resource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    DockerClientFactory.instance().client();
    try {
        s3 = new LocalStackContainer().withServices(Service.S3);
        s3.start();

        client = S3Client.builder()
            .endpointOverride(new URI(endpoint()))
            .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("accesskey", "secretKey")))
            .httpClientBuilder(UrlConnectionHttpClient.builder())
            .region(Region.US_EAST_1).build();

        client.createBucket(b -> b.bucket(BUCKET_NAME));
    } catch (Exception e) {
        throw new RuntimeException("Could not start S3 localstack server", e);
    }

    Map<String, String> properties = new HashMap<>();
    properties.put("quarkus.s3.endpoint-override", endpoint());
    properties.put("quarkus.s3.aws.region", "us-east-1");
    properties.put("quarkus.s3.aws.credentials.type", "static");
    properties.put("quarkus.s3.aws.credentials.static-provider.access-key-id", "accessKey");
    properties.put("quarkus.s3.aws.credentials.static-provider.secret-access-key", "secretKey");
    properties.put("bucket.name", BUCKET_NAME);

    return properties;
}
 
Example #10
Source File: SnsResource.java    From quarkus-quickstarts with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    DockerClientFactory.instance().client();
    String topicArn;
    try {
        services = new LocalStackContainer("0.11.1").withServices(Service.SNS);
        services.start();
        StaticCredentialsProvider staticCredentials = StaticCredentialsProvider
            .create(AwsBasicCredentials.create("accesskey", "secretKey"));

        client = SnsClient.builder()
            .endpointOverride(new URI(endpoint()))
            .credentialsProvider(staticCredentials)
            .httpClientBuilder(UrlConnectionHttpClient.builder())
            .region(Region.US_EAST_1).build();

        topicArn = client.createTopic(t -> t.name(TOPIC_NAME)).topicArn();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Could not start ocalstack server", e);
    }

    Map<String, String> properties = new HashMap<>();
    properties.put("quarkus.sns.endpoint-override", endpoint());
    properties.put("quarkus.sns.aws.region", "us-east-1");
    properties.put("quarkus.sns.aws.credentials.type", "static");
    properties.put("quarkus.sns.aws.credentials.static-provider.access-key-id", "accessKey");
    properties.put("quarkus.sns.aws.credentials.static-provider.secret-access-key", "secretKey");
    properties.put("topic.arn", topicArn);

    return properties;
}
 
Example #11
Source File: AWSKinesisLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonKinesis getClient() {
    ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setProtocol(Protocol.HTTP);

    return AmazonKinesisClientBuilder
            .standard()
            .withEndpointConfiguration(getContainer().getEndpointConfiguration(LocalStackContainer.Service.KINESIS))
            .withCredentials(getContainer().getDefaultCredentialsProvider())
            .withClientConfiguration(clientConfiguration)
            .build();
}
 
Example #12
Source File: AWSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
protected String getServiceEndpoint(LocalStackContainer.Service service) {
    return container
            .getEndpointConfiguration(service)
            .getServiceEndpoint();
}
 
Example #13
Source File: AWSKinesisLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
@Override
public String getServiceEndpoint() {
    return super.getServiceEndpoint(LocalStackContainer.Service.KINESIS);
}
 
Example #14
Source File: AWSKinesisLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public AWSKinesisLocalContainerService() {
    super(LocalStackContainer.Service.KINESIS);
}
 
Example #15
Source File: AWSS3LocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public AWSS3LocalContainerService() {
    super(LocalStackContainer.Service.S3);
}
 
Example #16
Source File: AWSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
protected LocalStackContainer getContainer() {
    return container;
}
 
Example #17
Source File: AWSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public AWSLocalContainerService(LocalStackContainer.Service...services) {
    this.container = new LocalStackContainer().withServices(services);

    container.start();
}
 
Example #18
Source File: AWSSNSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
@Override
public String getServiceEndpoint() {
    return super.getServiceEndpoint(LocalStackContainer.Service.SNS);
}
 
Example #19
Source File: AWSSNSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public AWSSNSLocalContainerService() {
    super(LocalStackContainer.Service.SQS,
            LocalStackContainer.Service.SNS);
}
 
Example #20
Source File: AWSSQSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
@Override
public String getServiceEndpoint() {
    return super.getServiceEndpoint(LocalStackContainer.Service.SQS);
}
 
Example #21
Source File: AWSSQSLocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public AWSSQSLocalContainerService() {
    super(LocalStackContainer.Service.SQS);
}
 
Example #22
Source File: AWSS3LocalContainerService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
@Override
public String getServiceEndpoint() {
    return super.getServiceEndpoint(LocalStackContainer.Service.S3);
}