Skip to content

Commit e99df4c

Browse files
committed
Add fixture tests to cover binary handling edge cases
1 parent 60e7fe6 commit e99df4c

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

.changes/next-release/feature-AmazonDynamoDBEnhancedClient-798234c.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"type": "feature",
33
"category": "Amazon DynamoDB Enhanced Client",
44
"contributor": "",
5-
"description": "Optimize implementation of the toJson() and getJson() used by the DDB Enhanced Client Serialization codepaths"
5+
"description": "Optimize implementation of the `EnhancedDocument#toJson()` and `EnhancedDocument#getJson()`."
66
}

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/document/EnhancedDocumentTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
import com.fasterxml.jackson.core.JsonProcessingException;
2727
import com.fasterxml.jackson.databind.JsonNode;
2828
import com.fasterxml.jackson.databind.ObjectMapper;
29+
import java.io.IOException;
2930
import java.math.BigDecimal;
31+
import java.nio.charset.StandardCharsets;
32+
import java.nio.file.Files;
33+
import java.nio.file.Paths;
3034
import java.time.LocalDate;
3135
import java.util.ArrayList;
3236
import java.util.Arrays;
@@ -46,6 +50,7 @@
4650
import org.junit.jupiter.params.provider.ValueSource;
4751
import software.amazon.awssdk.core.SdkBytes;
4852
import software.amazon.awssdk.core.SdkNumber;
53+
import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
4954
import software.amazon.awssdk.enhanced.dynamodb.DefaultAttributeConverterProvider;
5055
import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
5156
import software.amazon.awssdk.enhanced.dynamodb.converters.document.CustomAttributeForDocumentConverterProvider;
@@ -679,4 +684,33 @@ void getJson_nonExistentAttribute() {
679684
assertThat(result).isNull();
680685
}
681686

687+
@Test
688+
void toJson_fixtureFile_largeData() throws IOException {
689+
String largeDataJson = new String(Files.readAllBytes(
690+
Paths.get("src/test/resources/large_data_input.json")));
691+
692+
EnhancedDocument doc = EnhancedDocument.fromJson(largeDataJson);
693+
String actualOutput = doc.toJson();
694+
695+
// This fixture file is generated after running legacy toJson()
696+
String goldenOutput = new String(Files.readAllBytes(
697+
Paths.get("src/test/resources/large_data_fixture.json")));
698+
699+
assertThat(actualOutput).isEqualTo(goldenOutput);
700+
}
701+
702+
@Test
703+
void toJson_fixtureFile_binaryEdgeCases() throws IOException {
704+
String inputJson = new String(Files.readAllBytes(
705+
Paths.get("src/test/resources/binary_edge_cases_input.json")), StandardCharsets.UTF_8);
706+
707+
EnhancedDocument doc = EnhancedDocument.fromJson(inputJson);
708+
String actualOutput = doc.toJson();
709+
710+
// This fixture file is generated after running legacy toJson()
711+
String goldenOutput = new String(Files.readAllBytes(
712+
Paths.get("src/test/resources/binary_edge_cases_fixture.json")), StandardCharsets.UTF_8);
713+
714+
assertThat(actualOutput).isEqualTo(goldenOutput);
715+
}
682716
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"empty_bytes":"","one_byte":"AQ==","two_bytes":"AQI=","three_bytes":"AQID","four_bytes":"AQIDBA==","five_bytes":"AQIDBAU=","plus_slash_bytes":"++//","large_blob":"AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==","bs_set":["AQ==","","AgME"],"nested":{"bytes_in_map":"AQIDBA=="},"list_with_bytes":["AQ==","AQI=","AQID"]}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"empty_bytes": "",
3+
"one_byte": "AQ==",
4+
"two_bytes": "AQI=",
5+
"three_bytes": "AQID",
6+
"four_bytes": "AQIDBA==",
7+
"five_bytes": "AQIDBAU=",
8+
"plus_slash_bytes": "++//",
9+
"large_blob": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXp7fH1+fw==",
10+
"bs_set": ["AQ==", "", "AgME"],
11+
"nested": {
12+
"bytes_in_map": "AQIDBA=="
13+
},
14+
"list_with_bytes": ["AQ==", "AQI=", "AQID"]
15+
}

services-custom/dynamodb-enhanced/src/test/resources/large_data_fixture.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

services-custom/dynamodb-enhanced/src/test/resources/large_data_input.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)