|
| 1 | +package cloud.localstack; |
| 2 | + |
| 3 | +import cloud.localstack.awssdkv1.TestUtils; |
| 4 | + |
| 5 | +import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; |
| 6 | +import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceAsync; |
| 7 | +import com.amazonaws.services.simpleemail.model.*; |
| 8 | + |
| 9 | +import org.junit.Assert; |
| 10 | +import org.junit.Test; |
| 11 | +import org.junit.runner.RunWith; |
| 12 | + |
| 13 | +/** |
| 14 | + * Test integration of SES messaging with LocalStack |
| 15 | + */ |
| 16 | +@RunWith(LocalstackTestRunner.class) |
| 17 | +public class SESMessagingTest { |
| 18 | + |
| 19 | + static final String FROM = "sender@example.com"; |
| 20 | + static final String TO = "recipient@example.com"; |
| 21 | + static final String CONFIGSET = "ConfigSet"; |
| 22 | + static final String SUBJECT = "Amazon SES test (AWS SDK for Java)"; |
| 23 | + static final String HTMLBODY = "<h1>Amazon SES test (AWS SDK for Java)</h1>" |
| 24 | + + "<p>This email was sent with <a href='https://aws.amazon.com/ses/'>" |
| 25 | + + "Amazon SES</a> using the <a href='https://aws.amazon.com/sdk-for-java/'>" + "AWS SDK for Java</a>"; |
| 26 | + static final String TEXTBODY = "This email was sent through Amazon SES " + "using the AWS SDK for Java."; |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testSendEmail() throws Exception { |
| 32 | + AmazonSimpleEmailService client = TestUtils.getClientSES(); |
| 33 | + |
| 34 | + VerifyEmailAddressRequest verifyEmailAddressRequest = new VerifyEmailAddressRequest().withEmailAddress(TO); |
| 35 | + client.verifyEmailAddress(verifyEmailAddressRequest); |
| 36 | + |
| 37 | + verifyEmailAddressRequest.setEmailAddress(FROM); |
| 38 | + client.verifyEmailAddress(verifyEmailAddressRequest); |
| 39 | + |
| 40 | + SendEmailRequest request = new SendEmailRequest() |
| 41 | + .withDestination(new Destination().withToAddresses(TO)) |
| 42 | + .withMessage(new Message() |
| 43 | + .withBody(new Body().withHtml(new Content().withCharset("UTF-8").withData(HTMLBODY)) |
| 44 | + .withText(new Content().withCharset("UTF-8").withData(TEXTBODY))) |
| 45 | + .withSubject(new Content().withCharset("UTF-8").withData(SUBJECT))) |
| 46 | + .withSource(FROM).withConfigurationSetName(CONFIGSET); |
| 47 | + |
| 48 | + SendEmailResult result = client.sendEmail(request); |
| 49 | + Assert.assertNotNull(result); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testSendAsyncEmail() throws Exception { |
| 54 | + AmazonSimpleEmailServiceAsync client = TestUtils.getClientSESAsync(); |
| 55 | + |
| 56 | + VerifyEmailAddressRequest verifyEmailAddressRequest = new VerifyEmailAddressRequest().withEmailAddress(TO); |
| 57 | + client.verifyEmailAddress(verifyEmailAddressRequest); |
| 58 | + |
| 59 | + verifyEmailAddressRequest.setEmailAddress(FROM); |
| 60 | + client.verifyEmailAddress(verifyEmailAddressRequest); |
| 61 | + |
| 62 | + SendEmailRequest request = new SendEmailRequest() |
| 63 | + .withDestination(new Destination().withToAddresses(TO)) |
| 64 | + .withMessage(new Message() |
| 65 | + .withBody(new Body().withHtml(new Content().withCharset("UTF-8").withData(HTMLBODY)) |
| 66 | + .withText(new Content().withCharset("UTF-8").withData(TEXTBODY))) |
| 67 | + .withSubject(new Content().withCharset("UTF-8").withData(SUBJECT))) |
| 68 | + .withSource(FROM).withConfigurationSetName(CONFIGSET); |
| 69 | + |
| 70 | + SendEmailResult result = client.sendEmail(request); |
| 71 | + Assert.assertNotNull(result); |
| 72 | + } |
| 73 | +} |
0 commit comments