refactor(core): share Smithy length validation messages (#6449)

This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-24 18:31:10 -04:00
1 parent ed21e67cd4
commit a16478cd91
7 files changed
+50 -21

No files matched your search

@@ -5,6 +5,7 @@ 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.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
class SmithyValidationErrorsTest {
@@ -49,4 +50,19 @@ class SmithyValidationErrorsTest {
void noViolations_isAProgrammingError() {
assertThrows(IllegalArgumentException.class, () -> SmithyValidationErrors.message(List.of()));
}
@Test
void lengthBoundsPreserveValuesAndIncludeEndpoints() {
assertEquals("Value '' at 'name' failed to satisfy constraint: "
+ "Member must have length greater than or equal to 1",
SmithyValidationErrors.lengthOutOfRange("name", "", 1, 3));
assertEquals("Value 'abcd' at 'name' failed to satisfy constraint: "
+ "Member must have length less than or equal to 3",
SmithyValidationErrors.lengthOutOfRange("name", "abcd", 1, 3));
assertNull(SmithyValidationErrors.lengthOutOfRange("name", "a", 1, 3));
assertNull(SmithyValidationErrors.lengthOutOfRange("name", "abc", 1, 3));
assertNull(SmithyValidationErrors.lengthOutOfRange("name", " ", 1, 3));
assertEquals("Value ' ' at 'name' failed to satisfy constraint: "
+ "Member must have length greater than or equal to 1",
SmithyValidationErrors.lengthTooShort("name", " ", 1));
}
}
@@ -111,14 +111,14 @@ class CompositeAlarmIntegrationTest {
for (String field : List.of("AlarmName", "AlarmRule")) {
int maximum = "AlarmName".equals(field) ? 255 : 10240;
String path = "AlarmName".equals(field) ? "alarmName" : "alarmRule";
for (String value : List.of("", "x".repeat(maximum + 1))) {
for (String value : List.of("", " ", "x".repeat(maximum + 1), " ".repeat(maximum + 1))) {
Map<String, String> request = new LinkedHashMap<>(Map.of("AlarmName", "length-validation", "AlarmRule", "TRUE"));
request.put(field, value);
Response error = call(json, "PutCompositeAlarm", request);
error.then().statusCode(400);
assertEquals("1 validation error detected: Value '" + value + "' at '" + path
+ "' failed to satisfy constraint: Member must have length "
+ (value.isEmpty() ? "greater than or equal to 1" : "less than or equal to " + maximum),
+ (value.length() <= maximum ? "greater than or equal to 1" : "less than or equal to " + maximum),
errorMessage(json, error));
}
}