Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor(ses): clean up what the controller split left behind (#3841)

Kenshin Okinaka6e53c5275aa7
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesInspectionController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesInspectionController.java
index b1290e6035..6f45332d97 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesInspectionController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesInspectionController.java
@@ -1,9 +1,9 @@
package io.github.hectorvent.floci.services.ses;
-import io.github.hectorvent.floci.services.ses.model.SentEmail;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.services.ses.model.SentEmail;
import jakarta.inject.Inject;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
@@ -23,19 +23,20 @@ import java.util.List;
@Produces(MediaType.APPLICATION_JSON)
public class SesInspectionController {
- private final SesService sesService;
+ private final SesSentEmailService sentEmailService;
private final ObjectMapper objectMapper;
@Inject
- public SesInspectionController(SesService sesService, ObjectMapper objectMapper) {
- this.sesService = sesService;
+ public SesInspectionController(SesSentEmailService sentEmailService,
+ ObjectMapper objectMapper) {
+ this.sentEmailService = sentEmailService;
this.objectMapper = objectMapper;
}
@GET
public Response getEmails(@QueryParam("id") String messageId,
@QueryParam("email") String recipient) {
- List<SentEmail> emails = sesService.getEmails();
+ List<SentEmail> emails = sentEmailService.listAll();
ArrayNode messages = objectMapper.createArrayNode();
for (SentEmail email : emails) {
@@ -120,7 +121,7 @@ public class SesInspectionController {
@DELETE
public Response clearEmails() {
- sesService.clearEmails();
+ sentEmailService.clear();
return Response.ok().build();
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java
index 0e454f3fe1..3faa1f837e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java
@@ -1,5 +1,10 @@
package io.github.hectorvent.floci.services.ses;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
@@ -9,10 +14,6 @@ import io.github.hectorvent.floci.services.ses.model.ListManagementOptions;
import io.github.hectorvent.floci.services.ses.model.MessageHeader;
import io.github.hectorvent.floci.services.ses.model.MessageTag;
import io.github.hectorvent.floci.services.ses.model.Tag;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
@@ -372,7 +373,7 @@ public class SesSendController {
"Custom verification email template <" + templateName + "> does not exist", 404);
}
throw remapV1Exception(e);
- } catch (com.fasterxml.jackson.core.JsonProcessingException e) {
+ } catch (JsonProcessingException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java
index e9e8d95a95..41c5f012bf 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java
@@ -4,23 +4,19 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
-import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
-import io.github.hectorvent.floci.services.ses.model.CloudWatchDimensionConfiguration;
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.CustomVerificationEmailTemplate;
import io.github.hectorvent.floci.services.ses.model.DeliveryOptions;
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
-import io.github.hectorvent.floci.services.ses.model.EventDestination;
import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.services.ses.model.ListManagementOptions;
import io.github.hectorvent.floci.services.ses.model.MessageHeader;
import io.github.hectorvent.floci.services.ses.model.MessageTag;
import io.github.hectorvent.floci.services.ses.model.Topic;
import io.github.hectorvent.floci.services.ses.model.TrackingOptions;
-import io.github.hectorvent.floci.services.ses.model.VdmOptions;
import io.github.hectorvent.floci.services.ses.model.SentEmail;
import io.github.hectorvent.floci.services.ses.model.Tenant;
import io.github.hectorvent.floci.services.ses.model.TenantResourceAssociation;
@@ -39,8 +35,6 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -68,8 +62,7 @@ import java.util.UUID;
* <li>the ARN dispatch behind the tag operations, which routes one ARN to one of seven
* domains;</li>
* <li>the tenant-scoped suppression routing, which picks the tenant store or the account-wide
- * one from a {@code TenantName};</li>
- * <li>the inspection reads over recorded mail.</li>
+ * one from a {@code TenantName}.</li>
* </ul>
*
* <p>The name is historical. This is not the service for SES as a whole: SES is served by the
@@ -89,9 +82,8 @@ public class SesService {
// check, the tenant-guarded delete with its policy cascade, the default configuration set) and
// the send-path reads, reaching the store through its find/save.
private final SesIdentityService identityService;
- // Sent-email records extracted to SesSentEmailService. The send path records finished emails via
- // it; the account and v1 statistics reads go to the service directly, inspection still reads
- // back through the facade.
+ // Sent-email records extracted to SesSentEmailService. The send path records finished emails
+ // via it; every read goes to the service directly.
private final SesSentEmailService sentEmailService;
// Email templates extracted to SesTemplateService. The facade delegates; the templated-send path
// reads via it, and ARN-dispatched tagging reads/writes via its find/save.
@@ -621,13 +613,7 @@ public class SesService {
return cs;
}
- public List<SentEmail> getEmails() {
- return sentEmailService.listAll();
- }
- public void clearEmails() {
- sentEmailService.clear();
- }
// ──────────────────────────── Templates ────────────────────────────
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceDkimLookupCacheTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.java
similarity index 99%
rename from src/test/java/io/github/hectorvent/floci/services/ses/SesServiceDkimLookupCacheTest.java
rename to src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.java
index e420b3a6de..8222075c80 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceDkimLookupCacheTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityDkimLookupCacheTest.java
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-class SesServiceDkimLookupCacheTest {
+class SesIdentityDkimLookupCacheTest {
private static final String REGION = "us-east-1";
private static final String DOMAIN = "example.com";
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceLegacyDkimTokensTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityLegacyDkimTokensTest.java
similarity index 98%
rename from src/test/java/io/github/hectorvent/floci/services/ses/SesServiceLegacyDkimTokensTest.java
rename to src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityLegacyDkimTokensTest.java
index 0f455c4f2e..479bd1eac8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceLegacyDkimTokensTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityLegacyDkimTokensTest.java
@@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class SesServiceLegacyDkimTokensTest {
+class SesIdentityLegacyDkimTokensTest {
private static final String REGION = "us-east-1";
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSmtpTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSmtpTest.java
index a69f7701ee..e7b09b713f 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSmtpTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSmtpTest.java
@@ -23,6 +23,7 @@ class SesServiceSmtpTest {
private SesService service;
private SesConfigurationSetService configSets;
+ private SesSentEmailService sentEmails;
private InMemoryStorage<String, SentEmail> emailStore;
@BeforeEach
@@ -31,10 +32,11 @@ class SesServiceSmtpTest {
emailStore = builder.emailStore();
service = builder.build();
configSets = builder.configSetService();
+ sentEmails = builder.sentEmailService();
}
private SentEmail storedEmail(String messageId) {
- return service.getEmails().stream()
+ return sentEmails.listAll().stream()
.filter(e -> messageId.equals(e.getMessageId()))
.findFirst()
.orElseThrow();
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java
index af07cc726e..ad3236999e 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java
@@ -58,6 +58,7 @@ final class SesServiceTestBuilder {
private SesSuppressionService suppressionService;
private SesConfigurationSetService configSetService;
private SesIdentityService identityService;
+ private SesSentEmailService sentEmailService;
static SesServiceTestBuilder create() {
return new SesServiceTestBuilder();
@@ -134,6 +135,13 @@ final class SesServiceTestBuilder {
return configSetService;
}
+ SesSentEmailService sentEmailService() {
+ if (sentEmailService == null) {
+ throw new IllegalStateException("call build() first");
+ }
+ return sentEmailService;
+ }
+
SesIdentityService identityService() {
if (identityService == null) {
throw new IllegalStateException("call build() first");
@@ -147,9 +155,10 @@ final class SesServiceTestBuilder {
new InMemoryStorage<>());
configSetService = new SesConfigurationSetService(configSetStore);
identityService = new SesIdentityService(identityStore, route53Service, clock);
+ sentEmailService = new SesSentEmailService(emailStore);
return new SesService(
identityService,
- new SesSentEmailService(emailStore),
+ sentEmailService,
new SesTemplateService(templateStore, objectMapper, new SecureRandom()),
configSetService,
suppressionService,
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionLegacyKeyTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionLegacyKeyTest.java
similarity index 98%
rename from src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionLegacyKeyTest.java
rename to src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionLegacyKeyTest.java
index f922d66715..3477459fa7 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionLegacyKeyTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionLegacyKeyTest.java
@@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* the legacy key, and PUT migrates it onto the canonical key. Only reachable by seeding
* the store directly (the HTTP API always normalizes), so it lives at the unit layer.
*/
-class SesServiceSuppressionLegacyKeyTest {
+class SesSuppressionLegacyKeyTest {
private static final String REGION = "us-east-1";
// A pre-canonicalization entry: trim-only key with an upper-case domain.