mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(ses): split SesService into per-domain services behind a facade (#2357)
* refactor(ses): extract SesReceiptRuleService from SesService (strangler step 1) First step of the store-based domain split. Moves the receipt-rule-set domain — its store, lock, name validation, and the six Create/Describe/List/Delete/SetActive/DescribeActive methods — into a new @ApplicationScoped SesReceiptRuleService. SesService becomes a facade that delegates, so the v1 SesQueryHandler call sites are unchanged. The domain service is now unit-testable with just its own store and a clock. * refactor(ses): extract SesAccountService from SesService (strangler step 2) Second store-based domain split, same procedure as the receipt-rule step: the account sending-enabled flag (accountSettingsStore) moves into a new @ApplicationScoped SesAccountService, and SesService delegates. Consumers (v1 SesQueryHandler and v2 SesController) are unchanged. Account suppression/VDM stay in the facade for now — they share validateSuppressionReason with the suppression-list domain and extract with it later. * refactor(ses): extract SesCvetService from SesService (strangler step 3) Third store-based domain split, showing the facade-as-coordinator case: get/list/delete delegate straight through, but create/update keep their From-verified identity validation in the SesService facade before delegating storage, and sendCustomVerificationEmail stays in the facade and reads via cvetService.find() so a domain used by the send path never becomes a cross-service dependency. Consumers (v1 SesQueryHandler, v2 SesController) are unchanged. * refactor(ses): extract SesPolicyService from SesService (strangler step 4) Fourth store-based domain split, showing the two-way relationship with the not-yet-extracted Identity domain: the facade keeps requireIdentityExists and runs it before delegating the v2 policy mutators, while deleteIdentity now calls policyService.deletePoliciesForIdentity — the monolith depending on the extracted service. Policy storage, the per-identity count limit, and name validation move into a new @ApplicationScoped SesPolicyService. Consumers (v1 SesQueryHandler, v2 SesController) are unchanged. * refactor(ses): extract SesContactService from SesService (strangler step 5) Fifth store-based domain split, the first multi-store one: one @ApplicationScoped service owns both the contact-list and contact stores plus their locks, collapsing two SesService constructor arguments into one. It also owns the list-management contact behaviour (auto-create-on-send, opt-out evaluation, unsubscribe); the send orchestration (collectListManagementOptOuts) stays in the facade and calls into the service, keeping the shared extractEmailAddress helper there. SesController's two ContactWithList/ContactsWithList type references move to the service; otherwise consumers are unchanged. * refactor(ses): extract SesSuppressionService from SesService (strangler step 6) Sixth store-based domain split, resolving the shared-helper deferral from the account step: account suppression and the suppression list share validateSuppressionReason, so both stores move together into one @ApplicationScoped SesSuppressionService where the helper becomes private. The send filters stay in the facade — getEffectiveSuppressedReasons reads a configuration set's options or falls back here, and collectSuppressedReasons/resolveSuppressionReason read entries back through findSuppressedDestination. Consumers (v1 SesQueryHandler, v2 SesController) are unchanged. * refactor(ses): fold VDM into SesAccountService (strangler step 7) VDM (accountVdmStore + the account-level VdmAttributes methods) entered the tree via the merged PutAccountVdmAttributes work and was left on the facade during the rebase. It is account-level with no shared helper, so move it into SesAccountService alongside the sending-enabled flag — where it was always meant to live. The facade delegates find/putAccountVdmAttributes; SesController's getAccount VdmAttributes rendering is unchanged. * refactor(ses): extract SesDedicatedIpService from SesService (strangler step 8) * refactor(ses): extract SesTemplateService from SesService (strangler step 9) Ninth store-based domain split: the email templates (templateStore) move to SesTemplateService, with the facade forwarding CRUD and the templated-send path reading via getTemplate. New facet: the shared tag validator stays on the facade — SesTemplateService.createTemplate calls the package-private SesService.validateTag, the same static-utility convention the controllers use for templateNameFromArn — and ARN-dispatched tagging reads/writes through the service's find/save so the facade keeps mergeTags without owning the key derivation. templateNameFromArn stays on the facade because external callers reference it statically. * refactor(ses): extract SesSentEmailService from SesService (strangler step 10) Tenth store-based domain split: the sent-email records (emailStore) move to SesSentEmailService. This is the send path's output sink — the facade keeps the whole send orchestration and only hands the finished record over through record(), while GetSendStatistics and the inspection endpoints read back through countInRegion / listAll / clear. getSentEmailCount keeps its existing region-wide (non-24h) count semantics verbatim. * refactor(ses): move SES tag validation into a shared helper Extract SesService.validateTag into a small SesTags helper so the extracted domain services validate tags without depending back on the facade, keeping them dependency-free leaves. Also tighten the template service's tagging test to assert the save() round-trip, not just find().
This commit is contained in:
1 parent
3374bfeb04
commit
3726b88fc9
27 files changed
+2653
-1273
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted account domain: the account sending-enabled flag and
|
||||
* the VDM attributes. The service is constructed with just its own two stores — no 14-argument
|
||||
* SesService needed.
|
||||
*/
|
||||
class SesAccountServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesAccountService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesAccountService(new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendingEnabled_defaultsTrue() {
|
||||
assertTrue(service.isAccountSendingEnabled(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void setSendingEnabled_roundTrips() {
|
||||
service.setAccountSendingEnabled(REGION, false);
|
||||
assertFalse(service.isAccountSendingEnabled(REGION));
|
||||
|
||||
service.setAccountSendingEnabled(REGION, true);
|
||||
assertTrue(service.isAccountSendingEnabled(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendingEnabled_isPerRegion() {
|
||||
service.setAccountSendingEnabled(REGION, false);
|
||||
assertTrue(service.isAccountSendingEnabled("eu-west-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void vdmAttributes_absentUntilConfigured_thenRoundTrip() {
|
||||
// Opt-in: a never-configured region has no VdmAttributes at all.
|
||||
assertTrue(service.findAccountVdmAttributes(REGION).isEmpty());
|
||||
|
||||
service.putAccountVdmAttributes(REGION, new AccountVdmAttributes(true, true, false));
|
||||
AccountVdmAttributes vdm = service.findAccountVdmAttributes(REGION).orElseThrow();
|
||||
assertTrue(vdm.vdmEnabled());
|
||||
assertTrue(vdm.engagementMetrics());
|
||||
assertFalse(vdm.optimizedSharedDelivery());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.Contact;
|
||||
import io.github.hectorvent.floci.services.ses.model.ContactList;
|
||||
import io.github.hectorvent.floci.services.ses.model.Topic;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted contact domain. New facet: a multi-store service
|
||||
* (contact lists + contacts) constructed with just its two stores and a clock — the two SesService
|
||||
* constructor arguments collapse into one. Also exercises the list-management behaviour the send
|
||||
* path calls into.
|
||||
*/
|
||||
class SesContactServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String LIST = "news";
|
||||
private SesContactService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesContactService(new InMemoryStorage<>(), new InMemoryStorage<>(), Clock.systemUTC());
|
||||
service.createContactList(LIST, "desc",
|
||||
List.of(new Topic("Sports", "Sports", "OPT_OUT", "d")), List.of(), REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void secondContactList_hitsOneListLimit() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createContactList("other", "d", List.of(), List.of(), REGION));
|
||||
assertEquals("BadRequestException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createContact_thenGet_roundTrips() {
|
||||
service.createContact(LIST, "a@example.com", List.of(), false, null, REGION);
|
||||
assertEquals("a@example.com", service.getContact(LIST, "a@example.com", REGION).contact().getEmailAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteContactList_purgesContacts() {
|
||||
service.createContact(LIST, "a@example.com", List.of(), false, null, REGION);
|
||||
service.deleteContactList(LIST, REGION);
|
||||
// The list — and its contacts — are gone.
|
||||
assertThrows(AwsException.class, () -> service.listContacts(LIST, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOrAutoCreateContact_createsOnSend() {
|
||||
ContactList list = service.getContactList(LIST, REGION);
|
||||
Contact created = service.getOrAutoCreateContact(list, "auto@example.com", REGION);
|
||||
assertEquals("auto@example.com", created.getEmailAddress());
|
||||
assertTrue(service.getContact(LIST, "auto@example.com", REGION).contact() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsubscribeAll_thenListManagementOptedOut() {
|
||||
ContactList list = service.getContactList(LIST, REGION);
|
||||
service.unsubscribeContact(LIST, "bye@example.com", null, REGION);
|
||||
Contact c = service.getContact(LIST, "bye@example.com", REGION).contact();
|
||||
assertTrue(service.isListManagementOptedOut(c, list, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted CVET storage domain. The identity-dependent
|
||||
* validation lives in the SesService facade, so this service is a pure store — constructed with just
|
||||
* its own store and unit-tested without a 14-argument SesService.
|
||||
*/
|
||||
class SesCvetServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesCvetService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesCvetService(new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
private static CustomVerificationEmailTemplate template(String name) {
|
||||
CustomVerificationEmailTemplate t = new CustomVerificationEmailTemplate();
|
||||
t.setTemplateName(name);
|
||||
t.setFromEmailAddress("verify@example.com");
|
||||
t.setTemplateSubject("Verify");
|
||||
t.setTemplateContent("Hello");
|
||||
t.setSuccessRedirectionURL("https://example.com/ok");
|
||||
t.setFailureRedirectionURL("https://example.com/no");
|
||||
return t;
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_thenGet_roundTrips() {
|
||||
service.createCustomVerificationEmailTemplate(template("t1"), REGION);
|
||||
assertEquals("t1", service.getCustomVerificationEmailTemplate("t1", REGION).getTemplateName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_duplicate_throwsAlreadyExists() {
|
||||
service.createCustomVerificationEmailTemplate(template("t1"), REGION);
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createCustomVerificationEmailTemplate(template("t1"), REGION));
|
||||
assertEquals("CustomVerificationEmailTemplateAlreadyExists", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void get_unknown_throwsDoesNotExist() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.getCustomVerificationEmailTemplate("ghost", REGION));
|
||||
assertEquals("CustomVerificationEmailTemplateDoesNotExist", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_removesIt_andFindReflectsIt() {
|
||||
service.createCustomVerificationEmailTemplate(template("t1"), REGION);
|
||||
assertTrue(service.find("t1", REGION).isPresent());
|
||||
|
||||
service.deleteCustomVerificationEmailTemplate("t1", REGION);
|
||||
assertTrue(service.find("t1", REGION).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_unknown_throwsDoesNotExist() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.updateCustomVerificationEmailTemplate(template("ghost"), REGION));
|
||||
assertEquals("CustomVerificationEmailTemplateDoesNotExist", e.getErrorCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.DedicatedIpPool;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted dedicated-IP-pool domain: create/get/list/delete plus
|
||||
* the scaling-mode and duplicate validation. The service is constructed with just its own store — no
|
||||
* 14-argument SesService needed.
|
||||
*/
|
||||
class SesDedicatedIpServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesDedicatedIpService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesDedicatedIpService(new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_defaultsScalingModeToStandard() {
|
||||
DedicatedIpPool pool = service.createDedicatedIpPool("pool-a", null, REGION);
|
||||
assertEquals("pool-a", pool.getPoolName());
|
||||
assertEquals("STANDARD", pool.getScalingMode());
|
||||
assertTrue(service.dedicatedIpPoolExists("pool-a", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsBlankName() {
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool(" ", "STANDARD", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsInvalidScalingMode() {
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "TURBO", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsDuplicate() {
|
||||
service.createDedicatedIpPool("pool-a", "STANDARD", REGION);
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "STANDARD", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void get_missingThrows() {
|
||||
assertThrows(AwsException.class, () -> service.getDedicatedIpPool("ghost", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_isSortedAndPerRegion() {
|
||||
service.createDedicatedIpPool("pool-b", "STANDARD", REGION);
|
||||
service.createDedicatedIpPool("pool-a", "STANDARD", REGION);
|
||||
service.createDedicatedIpPool("pool-other", "STANDARD", "eu-west-1");
|
||||
|
||||
assertEquals(List.of("pool-a", "pool-b"), service.listDedicatedIpPools(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_removesPool() {
|
||||
service.createDedicatedIpPool("pool-a", "MANAGED", REGION);
|
||||
service.deleteDedicatedIpPool("pool-a", REGION);
|
||||
assertFalse(service.dedicatedIpPoolExists("pool-a", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_missingThrows() {
|
||||
assertThrows(AwsException.class, () -> service.deleteDedicatedIpPool("ghost", REGION));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted identity-policy domain. The identity-existence check
|
||||
* stays in the SesService facade, so this service is a pure policy store — unit-tested with just its
|
||||
* store and an ObjectMapper, and it exercises the reverse-coupling helper deletePoliciesForIdentity.
|
||||
*/
|
||||
class SesPolicyServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String IDENTITY = "sender@example.com";
|
||||
private SesPolicyService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesPolicyService(new InMemoryStorage<>(), new ObjectMapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_thenList_roundTrips() {
|
||||
service.createEmailIdentityPolicy(IDENTITY, "p1", "{\"Version\":\"2012-10-17\"}", REGION);
|
||||
assertTrue(service.listAllPolicies(IDENTITY, REGION).containsKey("p1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_duplicate_throwsAlreadyExists() {
|
||||
service.createEmailIdentityPolicy(IDENTITY, "p1", "{}", REGION);
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createEmailIdentityPolicy(IDENTITY, "p1", "{}", REGION));
|
||||
assertEquals("AlreadyExistsException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_missing_throwsNotFound() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.updateEmailIdentityPolicy(IDENTITY, "ghost", "{}", REGION));
|
||||
assertEquals("NotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidPolicyName_throws() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createEmailIdentityPolicy(IDENTITY, "bad name!", "{}", REGION));
|
||||
assertEquals("InvalidParameterValue", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enforcesPerIdentityLimit() {
|
||||
for (int i = 0; i < SesPolicyService.MAX_POLICIES_PER_IDENTITY; i++) {
|
||||
service.createEmailIdentityPolicy(IDENTITY, "p" + i, "{}", REGION);
|
||||
}
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createEmailIdentityPolicy(IDENTITY, "one-too-many", "{}", REGION));
|
||||
assertEquals("LimitExceededException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePoliciesForIdentity_purgesAll() {
|
||||
service.putIdentityPolicy(IDENTITY, "p1", "{}", REGION);
|
||||
service.putIdentityPolicy(IDENTITY, "p2", "{}", REGION);
|
||||
service.deletePoliciesForIdentity(IDENTITY, REGION);
|
||||
assertTrue(service.listAllPolicies(IDENTITY, REGION).isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.ReceiptRuleSet;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted receipt-rule domain. The payoff of the split: the
|
||||
* service is constructed with just its own store and a clock — no 14-argument SesService needed.
|
||||
*/
|
||||
class SesReceiptRuleServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesReceiptRuleService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesReceiptRuleService(new InMemoryStorage<>(), Clock.systemUTC());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_thenDescribe_roundTrips() {
|
||||
service.createReceiptRuleSet("rules-a", REGION);
|
||||
assertEquals("rules-a", service.describeReceiptRuleSet("rules-a", REGION).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_duplicate_throwsAlreadyExists() {
|
||||
service.createReceiptRuleSet("rules-a", REGION);
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createReceiptRuleSet("rules-a", REGION));
|
||||
assertEquals("AlreadyExists", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describe_unknown_throwsRuleSetDoesNotExist() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.describeReceiptRuleSet("ghost", REGION));
|
||||
assertEquals("RuleSetDoesNotExist", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setActive_thenDescribeActive_andDeleteActiveRejected() {
|
||||
service.createReceiptRuleSet("rules-a", REGION);
|
||||
service.setActiveReceiptRuleSet("rules-a", REGION);
|
||||
|
||||
ReceiptRuleSet active = service.describeActiveReceiptRuleSet(REGION);
|
||||
assertNotNull(active);
|
||||
assertEquals("rules-a", active.getName());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.deleteReceiptRuleSet("rules-a", REGION));
|
||||
assertEquals("CannotDelete", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidName_throwsValidationError() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.createReceiptRuleSet("bad name!", REGION));
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.SentEmail;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted sent-email record domain: the send path's output sink plus the
|
||||
* per-region count and the inspection list/clear. The service is constructed with just its own store
|
||||
* — no 14-argument SesService needed.
|
||||
*/
|
||||
class SesSentEmailServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesSentEmailService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesSentEmailService(new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
private static SentEmail email(String messageId, String region) {
|
||||
SentEmail e = new SentEmail();
|
||||
e.setMessageId(messageId);
|
||||
e.setRegion(region);
|
||||
e.setSource("sender@example.com");
|
||||
return e;
|
||||
}
|
||||
|
||||
@Test
|
||||
void record_thenListAll() {
|
||||
service.record(REGION, "m1", email("m1", REGION));
|
||||
service.record(REGION, "m2", email("m2", REGION));
|
||||
|
||||
List<SentEmail> all = service.listAll();
|
||||
assertEquals(2, all.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void countInRegion_isPerRegion() {
|
||||
service.record(REGION, "m1", email("m1", REGION));
|
||||
service.record(REGION, "m2", email("m2", REGION));
|
||||
service.record("eu-west-1", "m3", email("m3", "eu-west-1"));
|
||||
|
||||
assertEquals(2, service.countInRegion(REGION));
|
||||
assertEquals(1, service.countInRegion("eu-west-1"));
|
||||
assertEquals(0, service.countInRegion("ap-northeast-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void record_sameMessageId_isOverwrittenNotDuplicated() {
|
||||
service.record(REGION, "m1", email("m1", REGION));
|
||||
service.record(REGION, "m1", email("m1", REGION));
|
||||
assertEquals(1, service.countInRegion(REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clear_removesEverything() {
|
||||
service.record(REGION, "m1", email("m1", REGION));
|
||||
service.record("eu-west-1", "m2", email("m2", "eu-west-1"));
|
||||
|
||||
service.clear();
|
||||
assertTrue(service.listAll().isEmpty());
|
||||
assertEquals(0, service.countInRegion(REGION));
|
||||
}
|
||||
}
|
||||
+9
-12
@@ -51,19 +51,16 @@ class SesServiceDkimLookupCacheTest {
|
||||
clock.reset();
|
||||
service = new SesService(
|
||||
identityStore,
|
||||
new InMemoryStorage<String, SentEmail>(),
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new SesSentEmailService(new InMemoryStorage<String, SentEmail>()),
|
||||
new SesAccountService(new InMemoryStorage<String, Boolean>(), new InMemoryStorage<String, AccountVdmAttributes>()),
|
||||
new SesTemplateService(new InMemoryStorage<String, EmailTemplate>()),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
new InMemoryStorage<String, SuppressedDestination>(),
|
||||
new InMemoryStorage<String, AccountSuppressionAttributes>(),
|
||||
new InMemoryStorage<String, AccountVdmAttributes>(),
|
||||
new InMemoryStorage<String, DedicatedIpPool>(),
|
||||
new InMemoryStorage<String, ContactList>(),
|
||||
new InMemoryStorage<String, Contact>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, ReceiptRuleSet>(),
|
||||
new InMemoryStorage<String, CustomVerificationEmailTemplate>(),
|
||||
new SesSuppressionService(new InMemoryStorage<String, SuppressedDestination>(), new InMemoryStorage<String, AccountSuppressionAttributes>()),
|
||||
new SesDedicatedIpService(new InMemoryStorage<String, DedicatedIpPool>()),
|
||||
new SesContactService(new InMemoryStorage<String, ContactList>(), new InMemoryStorage<String, Contact>(), clock),
|
||||
new SesPolicyService(new InMemoryStorage<String, String>(), new ObjectMapper()),
|
||||
new SesReceiptRuleService(new InMemoryStorage<String, ReceiptRuleSet>(), clock),
|
||||
new SesCvetService(new InMemoryStorage<String, CustomVerificationEmailTemplate>()),
|
||||
mock(SmtpRelay.class),
|
||||
new ObjectMapper(),
|
||||
route53Service,
|
||||
|
||||
+9
-12
@@ -40,19 +40,16 @@ class SesServiceLegacyDkimTokensTest {
|
||||
identityStore = new InMemoryStorage<>();
|
||||
service = new SesService(
|
||||
identityStore,
|
||||
new InMemoryStorage<String, SentEmail>(),
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new SesSentEmailService(new InMemoryStorage<String, SentEmail>()),
|
||||
new SesAccountService(new InMemoryStorage<String, Boolean>(), new InMemoryStorage<String, AccountVdmAttributes>()),
|
||||
new SesTemplateService(new InMemoryStorage<String, EmailTemplate>()),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
new InMemoryStorage<String, SuppressedDestination>(),
|
||||
new InMemoryStorage<String, AccountSuppressionAttributes>(),
|
||||
new InMemoryStorage<String, AccountVdmAttributes>(),
|
||||
new InMemoryStorage<String, DedicatedIpPool>(),
|
||||
new InMemoryStorage<String, ContactList>(),
|
||||
new InMemoryStorage<String, Contact>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, ReceiptRuleSet>(),
|
||||
new InMemoryStorage<String, CustomVerificationEmailTemplate>(),
|
||||
new SesSuppressionService(new InMemoryStorage<String, SuppressedDestination>(), new InMemoryStorage<String, AccountSuppressionAttributes>()),
|
||||
new SesDedicatedIpService(new InMemoryStorage<String, DedicatedIpPool>()),
|
||||
new SesContactService(new InMemoryStorage<String, ContactList>(), new InMemoryStorage<String, Contact>(), Clock.systemUTC()),
|
||||
new SesPolicyService(new InMemoryStorage<String, String>(), new ObjectMapper()),
|
||||
new SesReceiptRuleService(new InMemoryStorage<String, ReceiptRuleSet>(), Clock.systemUTC()),
|
||||
new SesCvetService(new InMemoryStorage<String, CustomVerificationEmailTemplate>()),
|
||||
mock(SmtpRelay.class),
|
||||
new ObjectMapper(),
|
||||
Clock.systemUTC());
|
||||
|
||||
+9
-12
@@ -60,19 +60,16 @@ class SesServiceListManagementTest {
|
||||
contactStore = new InMemoryStorage<>();
|
||||
service = new SesService(
|
||||
new InMemoryStorage<String, Identity>(),
|
||||
new InMemoryStorage<String, SentEmail>(),
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new SesSentEmailService(new InMemoryStorage<String, SentEmail>()),
|
||||
new SesAccountService(new InMemoryStorage<String, Boolean>(), new InMemoryStorage<String, AccountVdmAttributes>()),
|
||||
new SesTemplateService(new InMemoryStorage<String, EmailTemplate>()),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
new InMemoryStorage<String, SuppressedDestination>(),
|
||||
new InMemoryStorage<String, AccountSuppressionAttributes>(),
|
||||
new InMemoryStorage<String, AccountVdmAttributes>(),
|
||||
new InMemoryStorage<String, DedicatedIpPool>(),
|
||||
new InMemoryStorage<String, ContactList>(),
|
||||
contactStore,
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, ReceiptRuleSet>(),
|
||||
new InMemoryStorage<String, CustomVerificationEmailTemplate>(),
|
||||
new SesSuppressionService(new InMemoryStorage<String, SuppressedDestination>(), new InMemoryStorage<String, AccountSuppressionAttributes>()),
|
||||
new SesDedicatedIpService(new InMemoryStorage<String, DedicatedIpPool>()),
|
||||
new SesContactService(new InMemoryStorage<String, ContactList>(), contactStore, Clock.systemUTC()),
|
||||
new SesPolicyService(new InMemoryStorage<String, String>(), new ObjectMapper()),
|
||||
new SesReceiptRuleService(new InMemoryStorage<String, ReceiptRuleSet>(), Clock.systemUTC()),
|
||||
new SesCvetService(new InMemoryStorage<String, CustomVerificationEmailTemplate>()),
|
||||
smtpRelay,
|
||||
new ObjectMapper(),
|
||||
Clock.systemUTC());
|
||||
|
||||
@@ -39,19 +39,16 @@ class SesServiceSmtpTest {
|
||||
emailStore = new InMemoryStorage<>();
|
||||
service = new SesService(
|
||||
new InMemoryStorage<String, Identity>(),
|
||||
emailStore,
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new SesSentEmailService(emailStore),
|
||||
new SesAccountService(new InMemoryStorage<String, Boolean>(), new InMemoryStorage<String, AccountVdmAttributes>()),
|
||||
new SesTemplateService(new InMemoryStorage<String, EmailTemplate>()),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
new InMemoryStorage<String, SuppressedDestination>(),
|
||||
new InMemoryStorage<String, AccountSuppressionAttributes>(),
|
||||
new InMemoryStorage<String, AccountVdmAttributes>(),
|
||||
new InMemoryStorage<String, DedicatedIpPool>(),
|
||||
new InMemoryStorage<String, ContactList>(),
|
||||
new InMemoryStorage<String, Contact>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, ReceiptRuleSet>(),
|
||||
new InMemoryStorage<String, CustomVerificationEmailTemplate>(),
|
||||
new SesSuppressionService(new InMemoryStorage<String, SuppressedDestination>(), new InMemoryStorage<String, AccountSuppressionAttributes>()),
|
||||
new SesDedicatedIpService(new InMemoryStorage<String, DedicatedIpPool>()),
|
||||
new SesContactService(new InMemoryStorage<String, ContactList>(), new InMemoryStorage<String, Contact>(), Clock.systemUTC()),
|
||||
new SesPolicyService(new InMemoryStorage<String, String>(), new ObjectMapper()),
|
||||
new SesReceiptRuleService(new InMemoryStorage<String, ReceiptRuleSet>(), Clock.systemUTC()),
|
||||
new SesCvetService(new InMemoryStorage<String, CustomVerificationEmailTemplate>()),
|
||||
smtpRelay,
|
||||
new ObjectMapper(),
|
||||
Clock.systemUTC());
|
||||
|
||||
+9
-12
@@ -47,19 +47,16 @@ class SesServiceSuppressionLegacyKeyTest {
|
||||
suppressionStore = new InMemoryStorage<>();
|
||||
service = new SesService(
|
||||
new InMemoryStorage<String, Identity>(),
|
||||
new InMemoryStorage<String, SentEmail>(),
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new SesSentEmailService(new InMemoryStorage<String, SentEmail>()),
|
||||
new SesAccountService(new InMemoryStorage<String, Boolean>(), new InMemoryStorage<String, AccountVdmAttributes>()),
|
||||
new SesTemplateService(new InMemoryStorage<String, EmailTemplate>()),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
suppressionStore,
|
||||
new InMemoryStorage<String, AccountSuppressionAttributes>(),
|
||||
new InMemoryStorage<String, AccountVdmAttributes>(),
|
||||
new InMemoryStorage<String, DedicatedIpPool>(),
|
||||
new InMemoryStorage<String, ContactList>(),
|
||||
new InMemoryStorage<String, Contact>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, ReceiptRuleSet>(),
|
||||
new InMemoryStorage<String, CustomVerificationEmailTemplate>(),
|
||||
new SesSuppressionService(suppressionStore, new InMemoryStorage<String, AccountSuppressionAttributes>()),
|
||||
new SesDedicatedIpService(new InMemoryStorage<String, DedicatedIpPool>()),
|
||||
new SesContactService(new InMemoryStorage<String, ContactList>(), new InMemoryStorage<String, Contact>(), Clock.systemUTC()),
|
||||
new SesPolicyService(new InMemoryStorage<String, String>(), new ObjectMapper()),
|
||||
new SesReceiptRuleService(new InMemoryStorage<String, ReceiptRuleSet>(), Clock.systemUTC()),
|
||||
new SesCvetService(new InMemoryStorage<String, CustomVerificationEmailTemplate>()),
|
||||
mock(SmtpRelay.class),
|
||||
new ObjectMapper(),
|
||||
Clock.systemUTC());
|
||||
|
||||
+9
-12
@@ -47,19 +47,16 @@ class SesServiceSuppressionReasonTest {
|
||||
accountSuppressionStore = new InMemoryStorage<>();
|
||||
service = new SesService(
|
||||
new InMemoryStorage<String, Identity>(),
|
||||
new InMemoryStorage<String, SentEmail>(),
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new SesSentEmailService(new InMemoryStorage<String, SentEmail>()),
|
||||
new SesAccountService(new InMemoryStorage<String, Boolean>(), new InMemoryStorage<String, AccountVdmAttributes>()),
|
||||
new SesTemplateService(new InMemoryStorage<String, EmailTemplate>()),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
suppressionStore,
|
||||
accountSuppressionStore,
|
||||
new InMemoryStorage<String, AccountVdmAttributes>(),
|
||||
new InMemoryStorage<String, DedicatedIpPool>(),
|
||||
new InMemoryStorage<String, ContactList>(),
|
||||
new InMemoryStorage<String, Contact>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, ReceiptRuleSet>(),
|
||||
new InMemoryStorage<String, CustomVerificationEmailTemplate>(),
|
||||
new SesSuppressionService(suppressionStore, accountSuppressionStore),
|
||||
new SesDedicatedIpService(new InMemoryStorage<String, DedicatedIpPool>()),
|
||||
new SesContactService(new InMemoryStorage<String, ContactList>(), new InMemoryStorage<String, Contact>(), Clock.systemUTC()),
|
||||
new SesPolicyService(new InMemoryStorage<String, String>(), new ObjectMapper()),
|
||||
new SesReceiptRuleService(new InMemoryStorage<String, ReceiptRuleSet>(), Clock.systemUTC()),
|
||||
new SesCvetService(new InMemoryStorage<String, CustomVerificationEmailTemplate>()),
|
||||
mock(SmtpRelay.class),
|
||||
new ObjectMapper(),
|
||||
Clock.systemUTC());
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.SuppressedDestination;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted suppression domain. New facet: this closes the
|
||||
* shared-helper deferral from the account step — account suppression and the suppression list both
|
||||
* live here and share the (now private) reason validation, exercised by both paths below. Two stores,
|
||||
* one service.
|
||||
*/
|
||||
class SesSuppressionServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesSuppressionService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesSuppressionService(new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountSuppression_defaultsToBounceAndComplaint() {
|
||||
assertEquals(List.of("BOUNCE", "COMPLAINT"),
|
||||
service.getAccountSuppressionAttributes(REGION).getSuppressedReasons());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putAccountSuppression_rejectsInvalidReason() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.putAccountSuppressionAttributes(REGION, List.of("NONSENSE")));
|
||||
assertEquals("BadRequestException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void suppressedDestination_putGetDelete_roundTrips() {
|
||||
service.putSuppressedDestination(REGION, "a@example.com", "BOUNCE");
|
||||
SuppressedDestination got = service.getSuppressedDestination(REGION, "a@example.com");
|
||||
assertEquals("BOUNCE", got.getReason());
|
||||
|
||||
service.deleteSuppressedDestination(REGION, "a@example.com");
|
||||
assertTrue(service.findSuppressedDestination(REGION, "a@example.com").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putSuppressedDestination_rejectsInvalidReason() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.putSuppressedDestination(REGION, "a@example.com", "NONSENSE"));
|
||||
assertEquals("BadRequestException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findSuppressedDestination_normalizesDomainCase() {
|
||||
service.putSuppressedDestination(REGION, "User@Example.COM", "COMPLAINT");
|
||||
// Domain is canonicalized to lower case, so a differently-cased domain resolves the entry.
|
||||
assertTrue(service.findSuppressedDestination(REGION, "User@example.com").isPresent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for the extracted email-template domain: CRUD plus the template-shape validation and
|
||||
* duplicate/not-found handling. The service is constructed with just its own store — no 14-argument
|
||||
* SesService needed.
|
||||
*/
|
||||
class SesTemplateServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private SesTemplateService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new SesTemplateService(new InMemoryStorage<>());
|
||||
}
|
||||
|
||||
private static EmailTemplate template(String name) {
|
||||
return new EmailTemplate(name, "Subject", "text body", "<p>html</p>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_thenGet_roundTrips() {
|
||||
EmailTemplate created = service.createTemplate(template("welcome"), REGION);
|
||||
assertNotNull(created.getCreatedTimestamp());
|
||||
assertNotNull(created.getLastUpdatedTimestamp());
|
||||
|
||||
EmailTemplate fetched = service.getTemplate("welcome", REGION);
|
||||
assertEquals("Subject", fetched.getSubject());
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsDuplicate() {
|
||||
service.createTemplate(template("welcome"), REGION);
|
||||
assertThrows(AwsException.class, () -> service.createTemplate(template("welcome"), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsBlankName() {
|
||||
assertThrows(AwsException.class, () -> service.createTemplate(template(" "), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsEmptyBody() {
|
||||
assertThrows(AwsException.class,
|
||||
() -> service.createTemplate(new EmailTemplate("empty", null, null, null), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void get_missingThrows() {
|
||||
assertThrows(AwsException.class, () -> service.getTemplate("ghost", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_preservesCreatedTimestamp_missingThrows() {
|
||||
EmailTemplate created = service.createTemplate(template("welcome"), REGION);
|
||||
|
||||
EmailTemplate update = template("welcome");
|
||||
update.setSubject("Updated");
|
||||
EmailTemplate updated = service.updateTemplate(update, REGION);
|
||||
assertEquals(created.getCreatedTimestamp(), updated.getCreatedTimestamp());
|
||||
assertEquals("Updated", service.getTemplate("welcome", REGION).getSubject());
|
||||
|
||||
assertThrows(AwsException.class, () -> service.updateTemplate(template("ghost"), REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_removesTemplate_missingThrows() {
|
||||
service.createTemplate(template("welcome"), REGION);
|
||||
service.deleteTemplate("welcome", REGION);
|
||||
assertThrows(AwsException.class, () -> service.getTemplate("welcome", REGION));
|
||||
assertThrows(AwsException.class, () -> service.deleteTemplate("welcome", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_isSortedByCreationAndPerRegion() {
|
||||
service.createTemplate(template("a"), REGION);
|
||||
service.createTemplate(template("b"), REGION);
|
||||
service.createTemplate(template("other"), "eu-west-1");
|
||||
|
||||
List<EmailTemplate> list = service.listTemplates(REGION);
|
||||
assertEquals(2, list.size());
|
||||
assertEquals("a", list.get(0).getTemplateName());
|
||||
assertEquals("b", list.get(1).getTemplateName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findAndSave_supportFacadeTagging() {
|
||||
service.createTemplate(template("welcome"), REGION);
|
||||
assertTrue(service.find("ghost", REGION).isEmpty());
|
||||
|
||||
EmailTemplate found = service.find("welcome", REGION).orElseThrow();
|
||||
found.setTags(List.of(new Tag("team", "ses")));
|
||||
service.save(found, REGION);
|
||||
|
||||
EmailTemplate reloaded = service.find("welcome", REGION).orElseThrow();
|
||||
assertEquals(1, reloaded.getTags().size());
|
||||
assertEquals("team", reloaded.getTags().get(0).key());
|
||||
assertEquals("ses", reloaded.getTags().get(0).value());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user