Skip to content

Added tests to show the exception on the SES client V2 #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@
<version>2.14.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ses</artifactId>
<version>${aws.sdkv2.version}</version>
<scope>provided</scope>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down
66 changes: 66 additions & 0 deletions src/test/java/cloud/localstack/awssdkv1/SESMessagingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cloud.localstack.LocalstackTestRunner;
import cloud.localstack.awssdkv1.TestUtils;

import java.net.URI;
import java.util.UUID;

import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
Expand All @@ -12,6 +13,13 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ses.SesClient;
import software.amazon.awssdk.services.ses.model.CreateTemplateResponse;
import software.amazon.awssdk.services.ses.model.GetSendStatisticsResponse;
import software.amazon.awssdk.services.ses.model.SendTemplatedEmailResponse;

/**
* Test integration of SES messaging with LocalStack
Expand Down Expand Up @@ -129,4 +137,62 @@ public void testSendTemplatedEmail() throws Throwable {
SendTemplatedEmailResult result = client.sendTemplatedEmail(request);
Assert.assertNotNull(result);
}

@Test
public void testSendTemplatedEmailV2() throws Throwable {
SesClient client = SesClient.builder()
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("access", "secret")))
.region(Region.of(Localstack.INSTANCE.getDefaultRegion()))
.endpointOverride(new URI(Localstack.INSTANCE.getEndpointSES()))
.build();

software.amazon.awssdk.services.ses.model.VerifyEmailAddressRequest verifyEmailAddressRequestTo = software.amazon.awssdk.services.ses.model.VerifyEmailAddressRequest.builder().emailAddress(TO).build();
client.verifyEmailAddress(verifyEmailAddressRequestTo);

software.amazon.awssdk.services.ses.model.VerifyEmailAddressRequest verifyEmailAddressRequestFrom = software.amazon.awssdk.services.ses.model.VerifyEmailAddressRequest.builder().emailAddress(FROM).build();
client.verifyEmailAddress(verifyEmailAddressRequestFrom);

try {
this.testCreateTemplateV2(client);
} catch (Exception e) {
throw new Throwable("Error creating template to send");
}

String templateData = "{ \"name\":\"Alejandro\", \"favoriteanimal\": \"alligator\" }";

software.amazon.awssdk.services.ses.model.SendTemplatedEmailRequest request = software.amazon.awssdk.services.ses.model.SendTemplatedEmailRequest.builder()
.configurationSetName(CONFIGSET)
.source(FROM)
.destination(software.amazon.awssdk.services.ses.model.Destination.builder().toAddresses(TO).build())
.template(templateName)
.templateData(templateData)
.build();

SendTemplatedEmailResponse result = client.sendTemplatedEmail(request);

// this call is throwing exception
GetSendStatisticsResponse statistics = client.getSendStatistics();

Assert.assertNotNull(result);
}

private void testCreateTemplateV2(SesClient client) {
templateName = "test-s-" + UUID.randomUUID().toString();
String subjectPart = "Greetings, {{name}}!";
String htmlPart = "<h1>Hello {{name}},</h1><p>Your favorite animal is {{favoriteanimal}}.</p>";
String textPart = "Dear {{name}},\r\nYour favorite animal is {{favoriteanimal}}.";

software.amazon.awssdk.services.ses.model.Template template = software.amazon.awssdk.services.ses.model.Template.builder()
.htmlPart(htmlPart)
.textPart(textPart)
.subjectPart(subjectPart)
.templateName(templateName)
.build();

software.amazon.awssdk.services.ses.model.CreateTemplateRequest request = software.amazon.awssdk.services.ses.model.CreateTemplateRequest.builder().template(template).build();
CreateTemplateResponse result = client.createTemplate(request);

Assert.assertNotNull(result);
}

}