Skip to content

armgit / floci

Public Imported from GitHub
0

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

refactor(ses): keep single-caller SesV2Json member helpers private (#5932)

Kenshin Okinaka83bc2bd2bfef
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
index 10860f81a1..3d21346fc5 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
@@ -37,6 +37,7 @@ import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -44,7 +45,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrF
import static io.github.hectorvent.floci.services.ses.SesV2Json.expectedNullError;
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseOptionString;
-import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSuppressedReasons;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
@@ -403,6 +403,21 @@ public class SesConfigurationSetController {
return dest;
}
+ /**
+ * Reads a {@code SuppressedReasons} member whose type {@link SesV2RequestShapes} has already
+ * checked; reason values are validated by the service layer. A {@code null} element is kept, so
+ * that validation rejects it as AWS does (verified against real AWS SES V2 on 2026-06-13).
+ * Missing / null yields an empty list for the PUT path, which AWS treats as an explicit empty
+ * override.
+ */
+ private static List<String> parseSuppressedReasons(JsonNode reasonsNode) {
+ List<String> reasons = new ArrayList<>();
+ for (JsonNode r : reasonsNode) {
+ reasons.add(r.textValue());
+ }
+ return reasons;
+ }
+
private static TrackingOptions parseTrackingOptions(JsonNode node) {
requireOptionObject(node);
TrackingOptions t = new TrackingOptions();
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
index 74e857bf8c..1e671c7765 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
@@ -148,7 +148,7 @@ final class SesV2Json {
* A structure member as the AWS deserializer reads it: absent or null is returned as is, an
* array is "Start of list found where not expected" and any other non-object "Expected null".
*/
- static JsonNode structureMemberOrAbsent(JsonNode parent, String field) {
+ private static JsonNode structureMemberOrAbsent(JsonNode parent, String field) {
JsonNode node = parent.path(field);
if (node.isMissingNode() || node.isNull() || node.isObject()) {
return node;
@@ -160,7 +160,7 @@ final class SesV2Json {
}
/** A string member with the AWS deserializer's message for each wrong JSON type. */
- static String typedStringMemberOrAbsent(JsonNode parent, String field) {
+ private static String typedStringMemberOrAbsent(JsonNode parent, String field) {
JsonNode node = parent.path(field);
if (node.isMissingNode() || node.isNull()) {
return null;
@@ -309,21 +309,6 @@ final class SesV2Json {
return node.asText();
}
- /**
- * Reads a {@code SuppressedReasons} member whose type {@link SesV2RequestShapes} has already
- * checked; reason values are validated by the service layer. A {@code null} element is kept, so
- * that validation rejects it as AWS does (verified against real AWS SES V2 on 2026-06-13).
- * Missing / null yields an empty list for the PUT path, which AWS treats as an explicit empty
- * override.
- */
- static List<String> parseSuppressedReasons(JsonNode reasonsNode) {
- List<String> reasons = new ArrayList<>();
- for (JsonNode r : reasonsNode) {
- reasons.add(r.textValue());
- }
- return reasons;
- }
-
/**
* An optional SES v2 boolean member whose absence means {@code false}: a missing member is
* {@code false}, and a present value, {@code null} included, goes through
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java
index 91d30fd67c..45b6e4998a 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java
@@ -202,6 +202,30 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {
.body("SuppressionOptions.SuppressedReasons", empty());
}
+ @Test
+ @Order(11)
+ void putSuppressionOptions_nullSuppressedReasons_treatedAsEmptyList() {
+ // Start from a non-empty override so an ignored null would leave BOUNCE behind.
+ configSetService.putSuppressionOptions(CS, List.of("BOUNCE"), REGION);
+
+ given()
+ .contentType("application/json")
+ .header("Authorization", AUTH)
+ .body("{\"SuppressedReasons\":null}")
+ .when()
+ .put("/v2/email/configuration-sets/" + CS + "/suppression-options")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("Authorization", AUTH)
+ .when()
+ .get("/v2/email/configuration-sets/" + CS)
+ .then()
+ .statusCode(200)
+ .body("SuppressionOptions.SuppressedReasons", empty());
+ }
+
// ─── getEffectiveSuppressedReasons helper (forward-looking integration with #1109) ───
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java
index e3ed177a46..4dfbe4d369 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java
@@ -9,8 +9,9 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import java.time.Instant;
-import java.util.Arrays;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -165,35 +166,34 @@ class SesV2JsonTest {
}
@Test
- void structureMemberOrAbsent_rejectsANonObjectTheWayAwsDoes() {
- JsonNode node = json("{\"o\":{},\"n\":null,\"a\":[],\"s\":\"x\",\"i\":1}");
- assertTrue(SesV2Json.structureMemberOrAbsent(node, "o").isObject());
- assertTrue(SesV2Json.structureMemberOrAbsent(node, "n").isNull());
- assertTrue(SesV2Json.structureMemberOrAbsent(node, "missing").isMissingNode());
+ void stringMapMemberOrAbsent_rejectsANonObjectTheWayAwsDoes() {
+ JsonNode node = json("{\"n\":null,\"a\":[],\"s\":\"x\",\"i\":1}");
+ assertNull(SesV2Json.stringMapMemberOrAbsent(node, "n"));
+ assertNull(SesV2Json.stringMapMemberOrAbsent(node, "missing"));
assertEquals("Start of list found where not expected", assertAws("SerializationException", 400,
- () -> SesV2Json.structureMemberOrAbsent(node, "a")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(node, "a")).getMessage());
assertEquals("Expected null", assertAws("SerializationException", 400,
- () -> SesV2Json.structureMemberOrAbsent(node, "s")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(node, "s")).getMessage());
assertEquals("Expected null", assertAws("SerializationException", 400,
- () -> SesV2Json.structureMemberOrAbsent(node, "i")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(node, "i")).getMessage());
}
@Test
- void typedStringMemberOrAbsent_namesTheWrongType() {
- JsonNode node = json("{\"s\":\"x\",\"n\":null,\"i\":1,\"t\":true,\"f\":false,\"o\":{},\"a\":[]}");
- assertEquals("x", SesV2Json.typedStringMemberOrAbsent(node, "s"));
- assertNull(SesV2Json.typedStringMemberOrAbsent(node, "n"));
- assertNull(SesV2Json.typedStringMemberOrAbsent(node, "missing"));
+ void stringMapMemberOrAbsent_keepsNullValues_andNamesTheWrongValueType() {
+ Map<String, String> expected = new LinkedHashMap<>();
+ expected.put("s", "x");
+ expected.put("n", null);
+ assertEquals(expected, SesV2Json.stringMapMemberOrAbsent(json("{\"m\":{\"s\":\"x\",\"n\":null}}"), "m"));
assertEquals("NUMBER_VALUE can not be converted to a String", assertAws("SerializationException", 400,
- () -> SesV2Json.typedStringMemberOrAbsent(node, "i")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(json("{\"m\":{\"i\":1}}"), "m")).getMessage());
assertEquals("TRUE_VALUE can not be converted to a String", assertAws("SerializationException", 400,
- () -> SesV2Json.typedStringMemberOrAbsent(node, "t")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(json("{\"m\":{\"t\":true}}"), "m")).getMessage());
assertEquals("FALSE_VALUE can not be converted to a String", assertAws("SerializationException", 400,
- () -> SesV2Json.typedStringMemberOrAbsent(node, "f")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(json("{\"m\":{\"f\":false}}"), "m")).getMessage());
assertEquals("Start of structure or map found where not expected.", assertAws("SerializationException",
- 400, () -> SesV2Json.typedStringMemberOrAbsent(node, "o")).getMessage());
+ 400, () -> SesV2Json.stringMapMemberOrAbsent(json("{\"m\":{\"o\":{}}}"), "m")).getMessage());
assertEquals("Start of list found where not expected", assertAws("SerializationException", 400,
- () -> SesV2Json.typedStringMemberOrAbsent(node, "a")).getMessage());
+ () -> SesV2Json.stringMapMemberOrAbsent(json("{\"m\":{\"a\":[]}}"), "m")).getMessage());
}
@Test
@@ -248,18 +248,6 @@ class SesV2JsonTest {
}
}
- @Test
- void parseSuppressedReasons_absentIsEmpty_keepsNullElements() {
- 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]")));
- }
-
@Test
void coerceBooleanOrFalse_missingIsFalse_otherwiseCoerces() {
assertFalse(SesV2Json.coerceBooleanOrFalse(json("{}").path("SendingEnabled")));