Skip to content

Commit 20db684

Browse files
committed
Update in test cases
1 parent 54d081b commit 20db684

File tree

4 files changed

+122
-111
lines changed

4 files changed

+122
-111
lines changed

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
import software.amazon.awssdk.core.SdkBytes;
2525

2626
public class CustomClassForDocumentAPI {
27-
public String string() {
28-
return string;
27+
28+
public boolean aBoolean() {
29+
return aBoolean;
2930
}
3031

31-
public Set<String> stringSet() {
32-
return stringSet;
32+
public BigDecimal bigDecimal() {
33+
return bigDecimal;
34+
}
35+
36+
public Set<BigDecimal> bigDecimalSet() {
37+
return bigDecimalSet;
3338
}
3439

3540
public SdkBytes binary() {
@@ -40,32 +45,28 @@ public Set<byte[]> binarySet() {
4045
return binarySet;
4146
}
4247

43-
public boolean aBoolean() {
44-
return aBoolean;
45-
}
4648

4749
public Set<Boolean> booleanSet() {
4850
return booleanSet;
4951
}
5052

53+
public List<CustomClassForDocumentAPI> customClassList() {
54+
return customClassForDocumentAPIList;
55+
}
56+
5157
public Long longNumber() {
5258
return longNumber;
5359
}
5460

5561
public Set<Long> longSet() {
5662
return longSet;
5763
}
58-
59-
public BigDecimal bigDecimal() {
60-
return bigDecimal;
61-
}
62-
63-
public Set<BigDecimal> bigDecimalSet() {
64-
return bigDecimalSet;
64+
public String string() {
65+
return string;
6566
}
6667

67-
public List<CustomClassForDocumentAPI> customClassList() {
68-
return customClassForDocumentAPIList;
68+
public Set<String> stringSet() {
69+
return stringSet;
6970
}
7071

7172
public List<Instant> instantList() {
@@ -80,7 +81,6 @@ public CustomClassForDocumentAPI innerCustomClass() {
8081
return innerCustomClassForDocumentAPI;
8182
}
8283

83-
private final String string;
8484
private final Set<String> stringSet;
8585
private final SdkBytes binary;
8686
private final Set<byte[]> binarySet;
@@ -95,6 +95,9 @@ public CustomClassForDocumentAPI innerCustomClass() {
9595
private final Map<String, CustomClassForDocumentAPI> customClassMap;
9696
private final CustomClassForDocumentAPI innerCustomClassForDocumentAPI;
9797

98+
private final String string;
99+
100+
98101
public static Builder builder(){
99102
return new Builder();
100103
}
@@ -214,20 +217,20 @@ public CustomClassForDocumentAPI build() {
214217
@Override
215218
public String toString() {
216219
return "CustomClassForDocumentAPI{" +
217-
"string='" + string + '\'' +
218-
", stringSet=" + stringSet +
220+
"aBoolean=" + aBoolean +
221+
", bigDecimal=" + bigDecimal +
222+
", bigDecimalSet=" + bigDecimalSet +
219223
", binary=" + binary +
220224
", binarySet=" + binarySet +
221-
", aBoolean=" + aBoolean +
222225
", booleanSet=" + booleanSet +
223-
", longNumber=" + longNumber +
224-
", longSet=" + longSet +
225-
", bigDecimal=" + bigDecimal +
226-
", bigDecimalSet=" + bigDecimalSet +
227226
", customClassForDocumentAPIList=" + customClassForDocumentAPIList +
228-
", instantList=" + instantList +
229227
", customClassMap=" + customClassMap +
230228
", innerCustomClassForDocumentAPI=" + innerCustomClassForDocumentAPI +
229+
", instantList=" + instantList +
230+
", longNumber=" + longNumber +
231+
", longSet=" + longSet +
232+
", string='" + string + '\'' +
233+
", stringSet=" + stringSet +
231234
'}';
232235
}
233236

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

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.time.Instant;
1919
import java.util.HashMap;
20+
import java.util.LinkedHashMap;
2021
import java.util.List;
2122
import java.util.Map;
2223
import java.util.stream.Collectors;
@@ -46,42 +47,33 @@ public AttributeValue transformFrom(CustomClassForDocumentAPI input) {
4647
if(input == null){
4748
return null;
4849
}
49-
Map<String, AttributeValue> attributeValueMap = new HashMap<>();
50-
51-
if(input.string() != null){
52-
attributeValueMap.put("string", AttributeValue.fromS(input.string()));
53-
}
54-
55-
56-
57-
if(input.longNumber() != null){
58-
attributeValueMap.put("longNumber", AttributeValue.fromN(input.longNumber().toString()));
59-
}
60-
61-
if(input.stringSet() != null){
62-
attributeValueMap.put("stringSet", AttributeValue.fromSs(input.stringSet().stream().collect(Collectors.toList())));
63-
}
64-
50+
Map<String, AttributeValue> attributeValueMap = new LinkedHashMap<>();
51+
// Maintain the Alphabetical Order ,so that expected json matches
6552
if(input.booleanSet() != null){
6653
attributeValueMap.put("booleanSet",
6754
AttributeValue.fromL(input.booleanSet().stream().map(b -> AttributeValue.fromBool(b)).collect(Collectors.toList())));
6855
}
69-
70-
if(input.bigDecimalSet() != null){
71-
attributeValueMap.put("stringSet",
72-
AttributeValue.fromNs(input.bigDecimalSet().stream().map(b -> b.toString()).collect(Collectors.toList())));
73-
}
74-
7556
if(input.customClassList() != null){
7657
attributeValueMap.put("customClassList", convertCustomList(input.customClassList()));
7758
}
78-
59+
if (input.innerCustomClass() != null){
60+
attributeValueMap.put("innerCustomClass", transformFrom(input.innerCustomClass()));
61+
}
7962
if(input.instantList() != null){
8063
attributeValueMap.put("instantList", convertInstantList(input.instantList()));
8164
}
82-
83-
if (input.innerCustomClass() != null){
84-
attributeValueMap.put("innerCustomClass", transformFrom(input.innerCustomClass()));
65+
if(input.longNumber() != null){
66+
attributeValueMap.put("longNumber", AttributeValue.fromN(input.longNumber().toString()));
67+
}
68+
if(input.string() != null){
69+
attributeValueMap.put("string", AttributeValue.fromS(input.string()));
70+
}
71+
if(input.stringSet() != null){
72+
attributeValueMap.put("stringSet", AttributeValue.fromSs(input.stringSet().stream().collect(Collectors.toList())));
73+
}
74+
if(input.bigDecimalSet() != null){
75+
attributeValueMap.put("stringSet",
76+
AttributeValue.fromNs(input.bigDecimalSet().stream().map(b -> b.toString()).collect(Collectors.toList())));
8577
}
8678
return EnhancedAttributeValue.fromMap(attributeValueMap).toAttributeValue();
8779
}
@@ -105,46 +97,25 @@ public CustomClassForDocumentAPI transformTo(AttributeValue input) {
10597

10698
CustomClassForDocumentAPI.Builder builder = CustomClassForDocumentAPI.builder();
10799

108-
if (customAttr.get("string") != null) {
109-
builder.string(StringAttributeConverter.create().transformTo(customAttr.get("string")));
100+
if (customAttr.get("aBoolean") != null) {
101+
builder.aBoolean(BooleanAttributeConverter.create().transformTo(customAttr.get("aBoolean")));
110102
}
111-
if (customAttr.get("stringSet") != null) {
112-
builder.stringSet(SetAttributeConverter.setConverter(StringAttributeConverter.create()).transformTo(customAttr.get(
113-
"stringSet")));
103+
if (customAttr.get("bigDecimal") != null) {
104+
builder.bigDecimal(BigDecimalAttributeConverter.create().transformTo(customAttr.get("bigDecimal")));
114105
}
115-
116-
if (customAttr.get("binary") != null) {
117-
builder.binary(SdkBytes.fromByteArray(ByteArrayAttributeConverter.create().transformTo(customAttr.get("binary"))));
106+
if (customAttr.get("bigDecimalSet") != null) {
107+
builder.bigDecimalSet(SetAttributeConverter.setConverter(BigDecimalAttributeConverter.create()).transformTo(customAttr.get("bigDecimalSet")));
118108
}
119-
120109
if (customAttr.get("binarySet") != null) {
121110
builder.binarySet(SetAttributeConverter.setConverter(ByteArrayAttributeConverter.create()).transformTo(customAttr.get("binarySet")));
122111
}
123-
124-
if (customAttr.get("aBoolean") != null) {
125-
builder.aBoolean(BooleanAttributeConverter.create().transformTo(customAttr.get("aBoolean")));
112+
if (customAttr.get("binary") != null) {
113+
builder.binary(SdkBytes.fromByteArray(ByteArrayAttributeConverter.create().transformTo(customAttr.get("binary"))));
126114
}
127-
128115
if (customAttr.get("booleanSet") != null) {
129116
builder.booleanSet(SetAttributeConverter.setConverter(BooleanAttributeConverter.create()).transformTo(customAttr.get(
130117
"booleanSet")));
131118
}
132-
133-
if (customAttr.get("longNumber") != null) {
134-
builder.longNumber(LongAttributeConverter.create().transformTo(customAttr.get("longNumber")));
135-
}
136-
137-
if (customAttr.get("longSet") != null) {
138-
builder.longSet(SetAttributeConverter.setConverter(LongAttributeConverter.create()).transformTo(customAttr.get(
139-
"longSet")));
140-
}
141-
142-
if (customAttr.get("bigDecimal") != null) {
143-
builder.bigDecimal(BigDecimalAttributeConverter.create().transformTo(customAttr.get("bigDecimal")));
144-
}
145-
if (customAttr.get("bigDecimalSet") != null) {
146-
builder.bigDecimalSet(SetAttributeConverter.setConverter(BigDecimalAttributeConverter.create()).transformTo(customAttr.get("bigDecimalSet")));
147-
}
148119
if (customAttr.get("customClassList") != null) {
149120
builder.customClassList(ListAttributeConverter.create(create()).transformTo(customAttr.get("customClassList")));
150121
}
@@ -155,6 +126,20 @@ public CustomClassForDocumentAPI transformTo(AttributeValue input) {
155126
if (customAttr.get("innerCustomClass") != null) {
156127
builder.innerCustomClass(create().transformTo(customAttr.get("innerCustomClass")));
157128
}
129+
if (customAttr.get("longNumber") != null) {
130+
builder.longNumber(LongAttributeConverter.create().transformTo(customAttr.get("longNumber")));
131+
}
132+
if (customAttr.get("longSet") != null) {
133+
builder.longSet(SetAttributeConverter.setConverter(LongAttributeConverter.create()).transformTo(customAttr.get(
134+
"longSet")));
135+
}
136+
if (customAttr.get("string") != null) {
137+
builder.string(StringAttributeConverter.create().transformTo(customAttr.get("string")));
138+
}
139+
if (customAttr.get("stringSet") != null) {
140+
builder.stringSet(SetAttributeConverter.setConverter(StringAttributeConverter.create()).transformTo(customAttr.get(
141+
"stringSet")));
142+
}
158143
return builder.build();
159144
}
160145

0 commit comments

Comments
 (0)