diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2017-09-04 10:05:38 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2017-09-04 10:05:38 -0700 |
commit | cbf149af1f07bb98c1f856948a79dcf3fb0c43b3 (patch) | |
tree | 7901334e10e181ba2c79c09b3a9a32f16c1abc42 /src/test/java | |
parent | 72ee0f10ddca0d880e50d13446f9ac0269e542eb (diff) |
SESNotificationService to accept multiple destinations.20170904
notificationEmail is now a comma separated list of addresses.
Adding unit tests for SESNotificationService.
Refactored AWS credential selection into ConfigCredentialProvider.
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/p4square/grow/backend/SESNotificationServiceTest.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/test/java/com/p4square/grow/backend/SESNotificationServiceTest.java b/src/test/java/com/p4square/grow/backend/SESNotificationServiceTest.java new file mode 100644 index 0000000..6b61f8e --- /dev/null +++ b/src/test/java/com/p4square/grow/backend/SESNotificationServiceTest.java @@ -0,0 +1,94 @@ +package com.p4square.grow.backend; + +import com.amazonaws.services.simpleemail.AmazonSimpleEmailService; +import com.amazonaws.services.simpleemail.model.SendEmailRequest; +import com.amazonaws.services.simpleemail.model.SendEmailResult; +import com.p4square.grow.config.Config; +import org.easymock.Capture; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests for {@link SESNotificationService}. + */ +public class SESNotificationServiceTest { + + private SESNotificationService service; + + private AmazonSimpleEmailService mockSES; + private SendEmailResult emailResult; + + @Before + public void setup() { + mockSES = EasyMock.createMock(AmazonSimpleEmailService.class); + emailResult = new SendEmailResult().withMessageId("1234"); + } + + @Test + public void notificationsDisabled() { + // Setup + Config testConfig = new Config(); + service = new SESNotificationService(testConfig, mockSES); + + EasyMock.replay(mockSES); + + // Run test + service.sendNotification("Hello World"); + + // Verify + EasyMock.verify(mockSES); + + } + + @Test + public void sendNotification() throws Exception { + // Setup + Config testConfig = new Config(); + testConfig.setString("notificationSourceEmail", "from@example.com"); + testConfig.setString("notificationEmail", "to@example.com"); + service = new SESNotificationService(testConfig, mockSES); + + Capture<SendEmailRequest> requestCapture = EasyMock.newCapture(); + EasyMock.expect(mockSES.sendEmail(EasyMock.capture(requestCapture))).andReturn(emailResult).once(); + EasyMock.replay(mockSES); + + // Run test + service.sendNotification("Hello World"); + + // Verify + EasyMock.verify(mockSES); + SendEmailRequest request = requestCapture.getValue(); + assertEquals("from@example.com", request.getSource()); + assertEquals(1, request.getDestination().getToAddresses().size()); + assertEquals("to@example.com", request.getDestination().getToAddresses().get(0)); + } + + @Test + public void testMultipleDestinations() { + // Setup + Config testConfig = new Config(); + testConfig.setString("notificationSourceEmail", "from@example.com"); + testConfig.setString("notificationEmail", "to@example.com,another@example.com"); + service = new SESNotificationService(testConfig, mockSES); + + Capture<SendEmailRequest> requestCapture = EasyMock.newCapture(); + EasyMock.expect(mockSES.sendEmail(EasyMock.capture(requestCapture))).andReturn(emailResult).once(); + EasyMock.replay(mockSES); + + + // Run test + service.sendNotification("Hello World"); + + // Verify + EasyMock.verify(mockSES); + SendEmailRequest request = requestCapture.getValue(); + assertEquals("from@example.com", request.getSource()); + assertEquals(2, request.getDestination().getToAddresses().size()); + assertEquals("to@example.com", request.getDestination().getToAddresses().get(0)); + assertEquals("another@example.com", request.getDestination().getToAddresses().get(1)); + } + +}
\ No newline at end of file |