Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ses): apply the ListTenants filter (#5060)
Kenshin Okinakadb40361a3c2f
diff --git a/docs/services/ses.md b/docs/services/ses.mdindex 40a0a3ff53..f090685123 100644--- a/docs/services/ses.md+++ b/docs/services/ses.md@@ -448,7 +448,7 @@ Identity, identity-policy, template, custom-verification-template, configurationThe template, identity, configuration-set, custom-verification-template and export-job lists page with `PageSize` (`MaxItems` on v1, `MaxResults` for v1 custom verification templates) and `NextToken`, with the page-size bounds and error messages real SES answers (probed 2026-09-25 to 2026-09-27). Templates and export jobs are listed newest first; identities, configuration sets and custom verification templates by name, since SES's own identity order varies between calls and its custom verification template order could not be observed. A token belongs to the kind of resource listed, as on AWS: a v1 token continues the v2 list of the same resources and the other way round, while any other list, and the same list in another region, refuses it. Without a page size the template lists serve 10, `ListEmailIdentities` 25, and the configuration-set and custom-verification-template lists 50, and a v1 page size outside the bound is served 100 on `ListTemplates` and 50 on `ListConfigurationSets` and `ListCustomVerificationEmailTemplates` rather than refused, all as on AWS. Floci's own choices, where AWS documents no default and none could be measured: v1 `ListIdentities` without `MaxItems` serves up to 1000, and `ListExportJobs` without a `PageSize` serves 100. `ListEmailIdentities` and `ListConfigurationSets` answer on both bindings: the `GET` older SDKs send, and the `POST` that SDKs send since the `Filter` member was added (AWS SDK for Java 2.55.8, botocore 1.43.105). The filter follows real SES (probed 2026-10-03) in what it matches, its messages and their precedence, and is applied before the page is cut; as on SES, a token continues only the filter it was taken with.-The tenant lists (`ListTenants`, `ListTenantResources`, `ListResourceTenants`) and `ListImportJobs` page the same way, within 1 to 100. The tenant lists follow real SES (probed 2026-09-25 and 2026-10-02): tenants are listed by name, a tenant's resources by ARN, and a resource's tenants in association order; the tenant or resource is looked up and the filter checked before the page size and token; a page size outside the bound and an empty `NextToken` are reported together in one Smithy validation message; and a token continues only the request it came from, so another tenant, resource or filter refuses it. Floci's own choices, where nothing could be measured: without a `PageSize` the four lists serve up to 100, and `ListImportJobs`, which refuses sandbox accounts and could not be probed at all, is modelled on the tenant lists with jobs listed oldest first.+The tenant lists (`ListTenants`, `ListTenantResources`, `ListResourceTenants`) and `ListImportJobs` page the same way, within 1 to 100. The tenant lists follow real SES (probed 2026-09-25 and 2026-10-02): tenants are listed by name, a tenant's resources by ARN, and a resource's tenants in association order; the tenant or resource is looked up and the `ListTenantResources` filter checked before the page size and token; a page size outside the bound and an empty `NextToken` are reported together in one Smithy validation message; and a token continues only the request it came from, so another tenant, resource or filter refuses it. `ListTenants` applies its `Filter` before the page is cut, matching real SES (probed 2026-10-03) in what it matches and its messages; the page size and an empty token are checked before the filter's values. Floci's own choices, where nothing could be measured: without a `PageSize` the four lists serve up to 100, and `ListImportJobs`, which refuses sandbox accounts and could not be probed at all, is modelled on the tenant lists with jobs listed oldest first.The contact lists (`ListContactLists`, `ListContacts`), the dedicated-IP lists (`ListDedicatedIpPools`, `GetDedicatedIps`) and `ListSuppressedDestinations` page the same way, within 1 to 1000. They follow real SES (probed 2026-09-25 and 2026-10-01) in their messages and in the treatment of an empty `NextToken`, refused on the contact and suppressed-destination lists and treated as absent on the dedicated-IP lists. `ListContacts` serves 50 without a `PageSize` and reads the page size and token before it looks the contact list up. A `ListSuppressedDestinations` token continues only the `Reason` filter and tenant it was taken with, and the filter is applied before the page is cut. Floci's own choices: where the SES order is not stable (the pool order changes with the page size, the suppressed-destination order between two identical calls, and contacts follow no recognisable order), Floci lists contacts by address, pools by name and suppressed destinations oldest first; a `ListContacts` page holds exactly `PageSize` contacts, where SES treats the size as a hint and may return a few more or fewer; and without a `PageSize` the contact-list, pool, dedicated-IP and suppressed-destination lists serve up to 1000, since no default could be measured. `ListContacts` applies its `Filter` before the page is cut, so a filtered page is exact too, where SES cuts the page first and may return it short or empty; as on SES, a token is not tied to the filter it was taken with. v1 `ListReceiptRuleSets` has no size member and serves 100 rule sets a page, the figure the AWS model documents; an empty `NextToken` is treated as absent, as on SES. SES lists rule sets by name, while Floci keeps the creation order its unpaged list already had. SES allows 40 rule sets per region, so a second page could not be observed there.diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.javaindex d5fbde60f4..2f5c19e1cc 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java@@ -155,7 +155,7 @@ public class SesConfigurationSetService {return list(region, paging, pageSize, nextToken);}// Validated here as well as in page() so the size error wins over the name's length.- paging.pageSize(pageSize);+ paging.checkRequest(pageSize, nextToken);int length = nameContains.codePointCount(0, nameContains.length());if (length < 3 || length > 64) {throw new AwsException("BadRequestException",diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.javaindex 47b6c1d3a4..57f8c0425b 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java@@ -26,17 +26,16 @@ import jakarta.ws.rs.core.MediaType;import jakarta.ws.rs.core.Response;import org.jboss.logging.Logger;-import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;+import static io.github.hectorvent.floci.services.ses.SesV2Json.filterValues;import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;-import static io.github.hectorvent.floci.services.ses.SesV2Json.requireFilterKeysAndValues;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;@@ -155,15 +154,7 @@ public class SesIdentityController {Map<String, String> filter = stringMapMemberOrAbsent(request, "Filter");Integer pageSize = intMemberOrAbsent(request, "PageSize");String nextToken = stringMemberOrAbsent(request, "NextToken");- Map<String, String> present = new LinkedHashMap<>();- if (filter != null) {- requireFilterKeysAndValues(filter, IDENTITY_FILTER_KEYS);- filter.forEach((key, value) -> {- if (value != null) {- present.put(key, value);- }- });- }+ Map<String, String> present = filterValues(filter, IDENTITY_FILTER_KEYS);return emailIdentitiesPage(region, present, pageSize, nextToken);}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.javaindex 791648b567..d958145b44 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java@@ -220,7 +220,7 @@ public class SesIdentityService {? SesListPaging.V2_LIST_EMAIL_IDENTITIES: SesListPaging.V2_LIST_EMAIL_IDENTITIES_FILTERED;// Validated here as well as in page() so the size error wins over the filter's values.- paging.pageSize(pageSize);+ paging.checkRequest(pageSize, nextToken);String name = v2FilterName(filter.get("IDENTITY_NAME_CONTAINS"));String type = v2FilterType(filter.get("IDENTITY_TYPE"));String status = v2FilterStatus(filter.get("VERIFICATION_STATUS"));diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.javaindex 7911a65fb1..0b250aea72 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java@@ -236,6 +236,18 @@ public enum SesListPaging {*/<T> PaginatedResult<T> page(String region, String scope, List<T> all, Function<T, String> cursorOf,Integer pageSize, String nextToken) {+ int limit = checkRequest(pageSize, nextToken);+ String boundTo = scope.isEmpty() ? "" : "#" + scope.length() + "#" + scope;+ return Pagination.paginate(all, cursorOf, limit, nextToken, namespace + "@" + region + boundTo,+ invalidToken);+ }++ /**+ * What SES checks before anything else in the request: the page size and an empty token, which+ * the tenant-style lists report together. Returns the page size to serve. {@link #page} runs it+ * too, so a service calls it first only when its own checks must come after these.+ */+ int checkRequest(Integer pageSize, String nextToken) {boolean emptyToken = nextToken != null && nextToken.isEmpty() && emptyTokenInvalid;if (emptyToken && sizeAndEmptyTokenInvalid != null && pageSize != null&& (pageSize < 1 || pageSize > maxPageSize)) {@@ -245,9 +257,7 @@ public enum SesListPaging {if (emptyToken) {throw invalidToken.apply(nextToken);}- String boundTo = scope.isEmpty() ? "" : "#" + scope.length() + "#" + scope;- return Pagination.paginate(all, cursorOf, limit, nextToken, namespace + "@" + region + boundTo,- invalidToken);+ return limit;}int pageSize(Integer requested) {diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.javaindex 49ca25ffc4..365820c87c 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantController.java@@ -23,13 +23,16 @@ import jakarta.ws.rs.core.Response;import org.jboss.logging.Logger;import java.util.List;+import java.util.Map;+import static io.github.hectorvent.floci.services.ses.SesV2Json.filterValues;import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringArrayOrAbsent;+import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;/**@@ -47,6 +50,9 @@ public class SesTenantController {private static final Logger LOG = Logger.getLogger(SesTenantController.class);+ /** In the order SES prints them when it refuses a key. */+ private static final List<String> TENANT_FILTER_KEYS = List.of("SENDING_STATUS", "TENANT_NAME_CONTAINS");+private final SesTenantService tenantService;private final SesService sesService;private final RegionResolver regionResolver;@@ -123,10 +129,11 @@ public class SesTenantController {? objectMapper.createObjectNode(): objectMapper.readTree(body);requireJsonObject(request);+ Map<String, String> filter = stringMapMemberOrAbsent(request, "Filter");Integer pageSize = intMemberOrAbsent(request, "PageSize");String nextToken = stringMemberOrAbsent(request, "NextToken");- PaginatedResult<Tenant> page = tenantService.listTenants(region, SesListPaging.V2_LIST_TENANTS,- pageSize, nextToken);+ Map<String, String> present = filterValues(filter, TENANT_FILTER_KEYS);+ PaginatedResult<Tenant> page = tenantService.listTenants(region, present, pageSize, nextToken);ObjectNode result = objectMapper.createObjectNode();ArrayNode tenants = result.putArray("Tenants");for (Tenant t : page.items()) {diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.javaindex 9f02e492bf..d003c3d471 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java@@ -19,8 +19,9 @@ import java.time.Clock;import java.time.Instant;import java.util.ArrayList;import java.util.Comparator;-import java.util.List;import java.util.HashSet;+import java.util.List;+import java.util.Locale;import java.util.Map;import java.util.Objects;import java.util.Optional;@@ -148,6 +149,50 @@ public class SesTenantService {.toList();}+ /**+ * ListTenants with a {@code Filter}, probed 2026-10-03. The controller has already checked the+ * filter's keys and values; SES then checks the page size and an empty token, the filter's+ * values, and last the token. The name is not trimmed and is found anywhere in a tenant's name+ * without regard to case, the keys combine, and a token is bound to the filter it came from.+ * Whether SES checks the name or the status first could not be observed.+ */+ public PaginatedResult<Tenant> listTenants(String region, Map<String, String> filter, Integer pageSize,+ String nextToken) {+ SesListPaging paging = SesListPaging.V2_LIST_TENANTS;+ paging.checkRequest(pageSize, nextToken);+ String name = filterName(filter.get("TENANT_NAME_CONTAINS"));+ String status = filterSendingStatus(filter.get("SENDING_STATUS"));+ List<Tenant> matching = listTenants(region).stream()+ .filter(t -> name == null || t.tenantName().toLowerCase(Locale.ROOT).contains(name))+ .filter(t -> status == null || status.equals(t.sendingStatus()))+ .toList();+ // The status goes first: its values never hold the separator, so no name can pass for+ // another filter.+ String scope = filter.isEmpty() ? "" : Objects.toString(status, "") + "/" + Objects.toString(name, "");+ return paging.page(region, scope, matching, Tenant::tenantName, pageSize, nextToken);+ }++ /** SES sets no upper bound short of the name's own: 65 characters were accepted. */+ private static String filterName(String value) {+ if (value == null) {+ return null;+ }+ if (value.codePointCount(0, value.length()) < 3) {+ throw new AwsException("BadRequestException", "TENANT_NAME_CONTAINS must be at least 3 characters.", 400);+ }+ return value.toLowerCase(Locale.ROOT);+ }++ private static String filterSendingStatus(String value) {+ if (value == null) {+ return null;+ }+ return switch (value) {+ case "ENABLED", "REINSTATED", "DISABLED" -> value;+ default -> throw new AwsException("BadRequestException", "Invalid sending status <" + value + ">.", 400);+ };+ }+public void deleteTenant(String tenantName, String region) {deleteTenant(tenantName, region, tenant -> { });}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.javaindex 5566e04853..24133a200b 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@@ -201,11 +201,15 @@ final class SesV2Json {}/**- * The model's own constraints on a {@code Filter} map, as the SES validation layer reports them:- * every key in the enum, listed in the order SES prints it, and no empty value. A key is checked- * before a value.+ * A {@code Filter} map checked against the model's own constraints, as the SES validation layer+ * reports them: every key in the enum, listed in the order SES prints it, and no empty value, a+ * key being checked before a value. Returns the entries that carry a value; an absent filter is+ * an empty one.*/- static void requireFilterKeysAndValues(Map<String, String> filter, List<String> keys) {+ static Map<String, String> filterValues(Map<String, String> filter, List<String> keys) {+ if (filter == null) {+ return Map.of();+ }if (!keys.containsAll(filter.keySet())) {throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' "+ "failed to satisfy constraint: Map keys must satisfy constraint: "@@ -216,6 +220,13 @@ final class SesV2Json {+ "failed to satisfy constraint: Map value must satisfy constraint: "+ "[Member must have length greater than or equal to 1]", 400);}+ Map<String, String> values = new LinkedHashMap<>();+ filter.forEach((key, value) -> {+ if (value != null) {+ values.put(key, value);+ }+ });+ return values;}static AwsException unexpectedStartError(JsonNode node) {diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.javaindex cd14ae6a4b..be9ae5cb23 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesListFilterV2IntegrationTest.java@@ -12,11 +12,12 @@ import static org.hamcrest.Matchers.equalTo;import static org.hamcrest.Matchers.nullValue;/**- * The POST bindings of ListEmailIdentities and ListConfigurationSets that SDKs use since the- * {@code Filter} member was added, beside the GET bindings older SDKs still send: body parsing, the- * model's checks on the filter map, and what each list does with a key it does not know. The match- * rules, the precedence and the token binding are covered by {@code SesIdentityListFilterServiceTest}- * and {@code SesConfigurationSetListFilterServiceTest}.+ * The {@code Filter} of ListEmailIdentities, ListConfigurationSets and ListTenants on the wire: the+ * POST bindings the first two moved to when the member was added, beside the GET bindings older SDKs+ * still send, body parsing, the model's checks on the filter map, and what each list does with a key+ * it does not know. The match rules, the precedence and the token binding are covered by+ * {@code SesIdentityListFilterServiceTest}, {@code SesConfigurationSetListFilterServiceTest} and+ * {@code SesTenantListFilterServiceTest}.*/@QuarkusTest@TestInstance(TestInstance.Lifecycle.PER_CLASS)@@ -27,6 +28,7 @@ class SesListFilterV2IntegrationTest {"AWS4-HMAC-SHA256 Credential=AKID/20260101/" + REGION + "/ses/aws4_request";private static final String LIST_IDENTITIES = "/v2/email/list-identities";private static final String LIST_CONFIGURATION_SETS = "/v2/email/list-configuration-sets";+ private static final String LIST_TENANTS = "/v2/email/tenants/list";private boolean created;@@ -42,6 +44,9 @@ class SesListFilterV2IntegrationTest {for (String name : new String[] {"Filter-Alpha", "filter-beta", "unrelated"}) {send("/v2/email/configuration-sets", "{\"ConfigurationSetName\": \"" + name + "\"}").statusCode(200);}+ for (String name : new String[] {"Filter-Alpha", "filter-beta", "unrelated"}) {+ send("/v2/email/tenants", "{\"TenantName\": \"" + name + "\"}").statusCode(200);+ }created = true;}@@ -153,6 +158,35 @@ class SesListFilterV2IntegrationTest {.body("__type", equalTo("SerializationException"));}+ @Test+ void listTenants_filtersAndPages() {+ String token = send(LIST_TENANTS, "{\"Filter\": {\"TENANT_NAME_CONTAINS\": \"FILTER\", "+ + "\"SENDING_STATUS\": \"ENABLED\"}, \"PageSize\": 1}").statusCode(200)+ .body("Tenants.TenantName", contains("Filter-Alpha"))+ .extract().path("NextToken");+ send(LIST_TENANTS, "{\"Filter\": {\"TENANT_NAME_CONTAINS\": \"filter\", \"SENDING_STATUS\": "+ + "\"ENABLED\"}, \"PageSize\": 1, \"NextToken\": \"" + token + "\"}").statusCode(200)+ .body("Tenants.TenantName", contains("filter-beta"))+ .body("NextToken", nullValue());+ send(LIST_TENANTS, "{\"Filter\": {}}").statusCode(200)+ .body("Tenants.TenantName", contains("Filter-Alpha", "filter-beta", "unrelated"));+ }++ @Test+ void listTenants_refusesAKeyItDoesNotKnow_andAnEmptyValue() {+ send(LIST_TENANTS, "{\"Filter\": {\"BOGUS\": null}, \"PageSize\": 0}").statusCode(400)+ .body("__type", equalTo("BadRequestException"))+ .body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy "+ + "constraint: Map keys must satisfy constraint: [Member must satisfy enum value set: "+ + "[SENDING_STATUS, TENANT_NAME_CONTAINS]]"));+ send(LIST_TENANTS, "{\"Filter\": {\"SENDING_STATUS\": \"\"}}").statusCode(400)+ .body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy "+ + "constraint: Map value must satisfy constraint: "+ + "[Member must have length greater than or equal to 1]"));+ send(LIST_TENANTS, "{\"Filter\": {\"SENDING_STATUS\": \"enabled\"}}").statusCode(400)+ .body("message", equalTo("Invalid sending status <enabled>."));+ }+private static ValidatableResponse send(String path, String body) {return given().contentType("application/json").header("Authorization", AUTH).body(body).when().post(path).then();diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantListFilterServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantListFilterServiceTest.javanew file mode 100644index 0000000000..7bc841aa75--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantListFilterServiceTest.java@@ -0,0 +1,127 @@+package io.github.hectorvent.floci.services.ses;++import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.common.PaginatedResult;+import io.github.hectorvent.floci.core.storage.InMemoryStorage;+import io.github.hectorvent.floci.services.ses.model.Tenant;+import org.junit.jupiter.api.BeforeEach;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.function.Executable;++import java.security.SecureRandom;+import java.time.Clock;+import java.time.Instant;+import java.util.List;+import java.util.Map;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertNull;+import static org.junit.jupiter.api.Assertions.assertThrows;++/**+ * The ListTenants {@code Filter}. Every message and precedence below is what SES v2 answered in+ * us-west-2 on 2026-10-03, except the order of the name and status checks, which SES never showed.+ */+class SesTenantListFilterServiceTest {++ private static final String REGION = "us-east-1";+ private static final String ACCOUNT = "000000000000";++ private InMemoryStorage<String, Tenant> tenantStore;+ private SesTenantService service;++ @BeforeEach+ void setUp() {+ tenantStore = new InMemoryStorage<>();+ service = new SesTenantService(tenantStore, new InMemoryStorage<>(), Clock.systemUTC(), new SecureRandom());+ for (String name : List.of("Filter-Alpha", "filter-beta", "unrelated")) {+ service.createTenant(name, List.of(), ACCOUNT, REGION);+ }+ tenantStore.put("tenant::" + REGION + "::other-FILTER-gamma", new Tenant("other-FILTER-gamma",+ "tn-gamma", "arn", Instant.now(), List.of(), "DISABLED", null));+ }++ @Test+ void name_isMatchedAnywhereWithoutCase_butNotTrimmed() {+ assertEquals(List.of("Filter-Alpha", "filter-beta", "other-FILTER-gamma"),+ names(Map.of("TENANT_NAME_CONTAINS", "FILTER")));+ assertEquals(List.of("Filter-Alpha"), names(Map.of("TENANT_NAME_CONTAINS", "alpha")));+ assertEquals(List.of(), names(Map.of("TENANT_NAME_CONTAINS", " alpha ")));+ }++ @Test+ void sendingStatus_selectsTheStatus_andKeysCombine() {+ assertEquals(List.of("Filter-Alpha", "filter-beta", "unrelated"),+ names(Map.of("SENDING_STATUS", "ENABLED")));+ assertEquals(List.of("other-FILTER-gamma"), names(Map.of("SENDING_STATUS", "DISABLED")));+ assertEquals(List.of(), names(Map.of("SENDING_STATUS", "REINSTATED")));+ assertEquals(List.of("filter-beta"),+ names(Map.of("TENANT_NAME_CONTAINS", "beta", "SENDING_STATUS", "ENABLED")));+ assertEquals(List.of(), names(Map.of("TENANT_NAME_CONTAINS", "beta", "SENDING_STATUS", "DISABLED")));+ }++ @Test+ void name_needsThreeCharacters_andHasNoUpperBoundOfItsOwn() {+ assertRefused("TENANT_NAME_CONTAINS must be at least 3 characters.",+ () -> list(Map.of("TENANT_NAME_CONTAINS", "ab"), null, null));+ assertRefused("TENANT_NAME_CONTAINS must be at least 3 characters.",+ () -> list(Map.of("TENANT_NAME_CONTAINS", "ππ"), null, null));+ assertEquals(List.of(), names(Map.of("TENANT_NAME_CONTAINS", "a".repeat(65))));+ }++ @Test+ void sendingStatus_isCaseSensitive() {+ assertRefused("Invalid sending status <enabled>.",+ () -> list(Map.of("SENDING_STATUS", "enabled"), null, null));+ assertRefused("Invalid sending status <BOGUS>.", () -> list(Map.of("SENDING_STATUS", "BOGUS"), null, null));+ }++ @Test+ void precedence_pageSizeAndEmptyTokenComeBeforeTheFilter() {+ assertRefused("1 validation error detected: Value '0' at 'pageSize' failed to satisfy constraint: "+ + "Member must have value greater than or equal to 1",+ () -> list(Map.of("SENDING_STATUS", "BOGUS"), 0, null));+ assertRefused("1 validation error detected: Value '' at 'nextToken' failed to satisfy constraint: "+ + "Member must have length greater than or equal to 1",+ () -> list(Map.of("TENANT_NAME_CONTAINS", "ab"), null, ""));+ assertRefused("Invalid sending status <BOGUS>.",+ () -> list(Map.of("SENDING_STATUS", "BOGUS"), null, "garbage"));+ }++ @Test+ void filteredPages_areExact_andTheTokenIgnoresTheNamesCase() {+ PaginatedResult<Tenant> first = list(Map.of("TENANT_NAME_CONTAINS", "filter"), 2, null);+ assertEquals(List.of("Filter-Alpha", "filter-beta"), names(first));+ PaginatedResult<Tenant> second = list(Map.of("TENANT_NAME_CONTAINS", "FILTER"), 2, first.nextToken());+ assertEquals(List.of("other-FILTER-gamma"), names(second));+ assertNull(second.nextToken());+ }++ @Test+ void token_isBoundToTheFilter_bothWays() {+ String filtered = list(Map.of("TENANT_NAME_CONTAINS", "filter"), 1, null).nextToken();+ assertRefused("Invalid Next Token", () -> list(Map.of(), 1, filtered));+ assertRefused("Invalid Next Token", () -> list(Map.of("SENDING_STATUS", "ENABLED"), 1, filtered));+ String unfiltered = list(Map.of(), 1, null).nextToken();+ assertRefused("Invalid Next Token", () -> list(Map.of("TENANT_NAME_CONTAINS", "filter"), 1, unfiltered));+ assertEquals(List.of("filter-beta"), names(list(Map.of(), 1, unfiltered)));+ }++ private PaginatedResult<Tenant> list(Map<String, String> filter, Integer pageSize, String nextToken) {+ return service.listTenants(REGION, filter, pageSize, nextToken);+ }++ private List<String> names(Map<String, String> filter) {+ return names(list(filter, null, null));+ }++ private static List<String> names(PaginatedResult<Tenant> page) {+ return page.items().stream().map(Tenant::tenantName).toList();+ }++ private static void assertRefused(String message, Executable call) {+ AwsException e = assertThrows(AwsException.class, call);+ assertEquals("BadRequestException", e.getErrorCode());+ assertEquals(message, e.getMessage());+ }+}