refactor(ses): split the account endpoints into SesAccountController (#3782)

The six /v2/email/account endpoints and their FeatureStatus helpers move
out of SesController into SesAccountController, which injects
SesAccountService, SesSuppressionService and SesSentEmailService and
composes GetAccount from their reads without the facade. The send
endpoints in SesController and the v1 handler read the account sending
switch and the sent-mail count from those services directly too, so
SesService drops its eleven account-level delegations. The
SuppressedReasons and SendingEnabled parsers turn out to be shared with
the configuration-set endpoints and move into SesV2Json with unit tests.
The new class is registered on the SES descriptor. No wire behavior
changes.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-16 18:38:29 -04:00
1 parent 03603aeacd
commit 3f10acdb95
10 files changed
+471 -405

No files matched your search

@@ -37,6 +37,9 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {
@Inject
SesService sesService;
@Inject
SesSuppressionService suppressionService;
@Test
@Order(1)
void createConfigurationSet() {
@@ -213,7 +216,9 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {
List<String> effective = sesService.getEffectiveSuppressedReasons(csNoOverride, REGION);
// Account defaults to [BOUNCE, COMPLAINT]; matches account state when no per-CS override.
assertEquals(sesService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(), effective);
assertEquals(
suppressionService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(),
effective);
}
@Test
@@ -261,14 +266,18 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {
@Order(23)
void effectiveReasons_nullConfigSetName_returnsAccountLevel() {
List<String> effective = sesService.getEffectiveSuppressedReasons(null, REGION);
assertEquals(sesService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(), effective);
assertEquals(
suppressionService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(),
effective);
}
@Test
@Order(24)
void effectiveReasons_blankConfigSetName_returnsAccountLevel() {
List<String> effective = sesService.getEffectiveSuppressedReasons(" ", REGION);
assertEquals(sesService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(), effective);
assertEquals(
suppressionService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(),
effective);
}
@Test
@@ -25,6 +25,7 @@ class SesServiceSuppressionReasonTest {
private static final String REGION = "us-east-1";
private SesService service;
private SesSuppressionService suppression;
private InMemoryStorage<String, SuppressedDestination> suppressionStore;
private InMemoryStorage<String, AccountSuppressionAttributes> accountSuppressionStore;
@@ -34,6 +35,7 @@ class SesServiceSuppressionReasonTest {
suppressionStore = builder.suppressionStore();
accountSuppressionStore = builder.accountSuppressionStore();
service = builder.build();
suppression = builder.suppressionService();
}
@Test
@@ -54,7 +56,7 @@ class SesServiceSuppressionReasonTest {
void onListButReasonNotInAccountSettings_returnsNull() {
service.putSuppressedDestination(REGION, "complainer@example.com", "COMPLAINT");
// Narrow the account settings to BOUNCE only.
service.putAccountSuppressionAttributes(REGION, List.of("BOUNCE"));
suppression.putAccountSuppressionAttributes(REGION, List.of("BOUNCE"));
assertNull(service.resolveSuppressionReason("complainer@example.com", null, REGION));
}
@@ -62,7 +64,7 @@ class SesServiceSuppressionReasonTest {
void accountSettingsEmpty_returnsNull() {
service.putSuppressedDestination(REGION, "bouncer@example.com", "BOUNCE");
// Disable account-level suppression by passing an empty list.
service.putAccountSuppressionAttributes(REGION, new ArrayList<>());
suppression.putAccountSuppressionAttributes(REGION, new ArrayList<>());
assertNull(service.resolveSuppressionReason("bouncer@example.com", null, REGION));
}
@@ -2,9 +2,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.ses.model.AccountDetails;
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
import io.github.hectorvent.floci.services.ses.model.Contact;
import io.github.hectorvent.floci.services.ses.model.ContactList;
@@ -34,9 +32,6 @@ final class SesServiceTestBuilder {
private final InMemoryStorage<String, Identity> identityStore = new InMemoryStorage<>();
private final InMemoryStorage<String, SentEmail> emailStore = new InMemoryStorage<>();
private final InMemoryStorage<String, Boolean> accountSettingsStore = new InMemoryStorage<>();
private final InMemoryStorage<String, AccountVdmAttributes> accountVdmStore = new InMemoryStorage<>();
private final InMemoryStorage<String, AccountDetails> accountDetailsStore = new InMemoryStorage<>();
private final InMemoryStorage<String, EmailTemplate> templateStore = new InMemoryStorage<>();
private final InMemoryStorage<String, ConfigurationSet> configSetStore = new InMemoryStorage<>();
private final InMemoryStorage<String, SuppressedDestination> suppressionStore = new InMemoryStorage<>();
@@ -57,9 +52,10 @@ final class SesServiceTestBuilder {
private Route53Service route53Service = null;
private ObjectMapper objectMapper = new ObjectMapper();
private Clock clock = Clock.systemUTC();
// Built by build(); exposed so tests can seed contacts through the domain service now that the
// facade no longer forwards the contact CRUD.
// Built by build(); exposed so tests can seed contacts and account suppression through the domain
// services now that the facade no longer forwards those operations.
private SesContactService contactService;
private SesSuppressionService suppressionService;
static SesServiceTestBuilder create() {
return new SesServiceTestBuilder();
@@ -122,15 +118,23 @@ final class SesServiceTestBuilder {
return contactService;
}
SesSuppressionService suppressionService() {
if (suppressionService == null) {
throw new IllegalStateException("call build() first");
}
return suppressionService;
}
SesService build() {
contactService = new SesContactService(contactListStore, contactStore, clock);
suppressionService = new SesSuppressionService(suppressionStore, accountSuppressionStore,
new InMemoryStorage<>());
return new SesService(
new SesIdentityService(identityStore, route53Service, clock),
new SesSentEmailService(emailStore),
new SesAccountService(accountSettingsStore, accountVdmStore, accountDetailsStore),
new SesTemplateService(templateStore, objectMapper, new SecureRandom()),
new SesConfigurationSetService(configSetStore),
new SesSuppressionService(suppressionStore, accountSuppressionStore, new InMemoryStorage<>()),
suppressionService,
new SesDedicatedIpService(dedicatedIpPoolStore),
contactService,
new SesPolicyService(policyStore, objectMapper),
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.services.ses.model.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -197,4 +198,36 @@ class SesV2JsonTest {
() -> SesV2Json.readRequiredStringField(node, field)).getMessage());
}
}
@Test
void parseSuppressedReasons_absentIsEmpty_elementsFollowAwsCoercion() {
assertEquals(List.of(),
SesV2Json.parseSuppressedReasons(json("{}").path("SuppressedReasons")));
assertEquals(List.of(), SesV2Json.parseSuppressedReasons(json("null")));
assertEquals(List.of("BOUNCE", "COMPLAINT"),
SesV2Json.parseSuppressedReasons(json("[\"BOUNCE\",\"COMPLAINT\"]")));
// A null element passes deserialization and is left to the service-layer value check.
assertEquals(Arrays.asList("BOUNCE", null),
SesV2Json.parseSuppressedReasons(json("[\"BOUNCE\",null]")));
assertEquals("Expected list or null", assertAws("SerializationException", 400,
() -> SesV2Json.parseSuppressedReasons(json("\"BOUNCE\""))).getMessage());
assertEquals("NUMBER_VALUE can not be converted to a String",
assertAws("SerializationException", 400,
() -> SesV2Json.parseSuppressedReasons(json("[1]"))).getMessage());
assertEquals("TRUE_VALUE can not be converted to a String",
assertAws("SerializationException", 400,
() -> SesV2Json.parseSuppressedReasons(json("[true]"))).getMessage());
assertEquals("Start of structure or map found where not expected.",
assertAws("SerializationException", 400,
() -> SesV2Json.parseSuppressedReasons(json("[{}]"))).getMessage());
}
@Test
void parseSendingEnabled_missingIsFalse_otherwiseCoerces() {
assertFalse(SesV2Json.parseSendingEnabled(json("{}").path("SendingEnabled")));
assertTrue(SesV2Json.parseSendingEnabled(json("true")));
assertTrue(SesV2Json.parseSendingEnabled(json("\"yes\"")));
assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("null")));
assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("0")));
}
}