diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java index b6998da274..03ac0bf9c8 100644 --- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java +++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidator.java @@ -56,11 +56,13 @@ final class DynamoDbAccessPathValidator { String select, String projectionExpression, JsonNode attributesToGet, JsonNode expressionAttributeNames) { if (projectionExpression != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) { - throw validationException("Cannot specify the ProjectionExpression when choosing to get " + throw validationException("1 validation error detected: " + + "Cannot specify the ProjectionExpression when choosing to get " + ("COUNT".equals(select) ? "only the Count" : select)); } if ("ALL_PROJECTED_ATTRIBUTES".equals(select) && !accessPath.isIndex()) { - throw validationException("ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName"); + throw validationException("1 validation error detected: " + + "ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName"); } if (attributesToGet != null && select != null && !"SPECIFIC_ATTRIBUTES".equals(select)) { throw validationException("Cannot use both Select and AttributesToGet unless Select is SPECIFIC_ATTRIBUTES"); diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java index 8cef2bb31f..afa0d3e4b8 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbAccessPathValidatorTest.java @@ -392,13 +392,15 @@ class DynamoDbAccessPathValidatorTest { AwsException allAttributes = assertThrows(AwsException.class, () -> DynamoDbAccessPathValidator.validateSelection( table, tablePath, "ALL_ATTRIBUTES", "sk", null, null)); - assertEquals("Cannot specify the ProjectionExpression when choosing to get ALL_ATTRIBUTES", + assertEquals("1 validation error detected: " + + "Cannot specify the ProjectionExpression when choosing to get ALL_ATTRIBUTES", allAttributes.getMessage()); AwsException count = assertThrows(AwsException.class, () -> DynamoDbAccessPathValidator.validateSelection( table, tablePath, "COUNT", "sk", null, null)); - assertEquals("Cannot specify the ProjectionExpression when choosing to get only the Count", + assertEquals("1 validation error detected: " + + "Cannot specify the ProjectionExpression when choosing to get only the Count", count.getMessage()); } @@ -407,13 +409,15 @@ class DynamoDbAccessPathValidatorTest { AwsException both = assertThrows(AwsException.class, () -> DynamoDbAccessPathValidator.validateSelection( table, tablePath, "ALL_PROJECTED_ATTRIBUTES", "sk", null, null)); - assertEquals("Cannot specify the ProjectionExpression when choosing to get ALL_PROJECTED_ATTRIBUTES", + assertEquals("1 validation error detected: " + + "Cannot specify the ProjectionExpression when choosing to get ALL_PROJECTED_ATTRIBUTES", both.getMessage()); AwsException indexOnly = assertThrows(AwsException.class, () -> DynamoDbAccessPathValidator.validateSelection( table, tablePath, "ALL_PROJECTED_ATTRIBUTES", null, null, null)); - assertEquals("ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName", + assertEquals("1 validation error detected: " + + "ALL_PROJECTED_ATTRIBUTES can be used only when Querying using an IndexName", indexOnly.getMessage()); } diff --git a/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java index f5bd5cf7d5..a3d21cba65 100644 --- a/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandlerTest.java @@ -1121,6 +1121,44 @@ class NativeDynamoDbJsonHandlerTest { + "when choosing to get SPECIFIC_ATTRIBUTES", ex.getMessage()); } + @Test + void scanPrefixesTheSelectConflicts() { + createUsersTable("eu-west-1"); + + AwsException count = expectValidationException("Scan", json(""" + {"TableName": "Users", "Select": "COUNT", "ProjectionExpression": "userId"} + """)); + assertEquals("1 validation error detected: Cannot specify the ProjectionExpression " + + "when choosing to get only the Count", count.getMessage()); + + AwsException allProjected = expectValidationException("Scan", json(""" + {"TableName": "Users", "Select": "ALL_PROJECTED_ATTRIBUTES"} + """)); + assertEquals("1 validation error detected: ALL_PROJECTED_ATTRIBUTES can be used only " + + "when Querying using an IndexName", allProjected.getMessage()); + } + + @Test + void queryPrefixesTheSelectConflicts() { + createUsersTable("eu-west-1"); + + AwsException allAttributes = expectValidationException("Query", json(""" + {"TableName": "Users", "KeyConditionExpression": "userId = :u", + "ExpressionAttributeValues": {":u": {"S": "a"}}, + "Select": "ALL_ATTRIBUTES", "ProjectionExpression": "userId"} + """)); + assertEquals("1 validation error detected: Cannot specify the ProjectionExpression " + + "when choosing to get ALL_ATTRIBUTES", allAttributes.getMessage()); + + AwsException allProjected = expectValidationException("Query", json(""" + {"TableName": "Users", "KeyConditionExpression": "userId = :u", + "ExpressionAttributeValues": {":u": {"S": "a"}}, + "Select": "ALL_PROJECTED_ATTRIBUTES"} + """)); + assertEquals("1 validation error detected: ALL_PROJECTED_ATTRIBUTES can be used only " + + "when Querying using an IndexName", allProjected.getMessage()); + } + @Test void scanAcceptsSegmentsAtTheBounds() throws Exception { createUsersTable("eu-west-1");