Skip to content

Functional Test Cases for Document DDB API and Surface API Review 2 comments #3843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static Builder builder() {
* <p>
* <b>Retrieving String Type for a document</b>
* {@snippet :
* Custom resultCustom = document.get("key", EnhancedType.of(String.class));
* String resultCustom = document.get("key", EnhancedType.of(String.class));
* }
* <b>Retrieving Custom Type for which Convertor Provider was defined while creating the document</b>
* {@snippet :
Expand Down Expand Up @@ -172,7 +172,7 @@ static Builder builder() {
* <p>
* <b>Retrieving String Type for a document</b>
* {@snippet :
* Custom resultCustom = document.get("key", String.class);
* String resultCustom = document.get("key", String.class);
* }
* <b>Retrieving Custom Type for which Convertor Provider was defined while creating the document</b>
* {@snippet :
Expand Down Expand Up @@ -238,7 +238,7 @@ static Builder builder() {
* Gets the Set of String values of the given attribute in the current document.
* @param attributeName Name of the attribute.
* @return value of the specified attribute in the current document as a set of SdkBytes;
* or null if the attribute either doesn't exist.
* or null if the attribute doesn't exist.
*/
Set<SdkBytes> getBytesSet(String attributeName);

Expand Down Expand Up @@ -301,7 +301,7 @@ static Builder builder() {
* @param attributeName Name of the attribute.
* @return value of the specified attribute in the current document as a List of {@link AttributeValue}
*/
List<AttributeValue> getListOfUnknownList(String attributeName);
List<AttributeValue> getListOfUnknownType(String attributeName);

/**
* Retrieves a Map with String keys and corresponding AttributeValue objects as values for a specified attribute in a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public boolean getBoolean(String attributeName) {
}

@Override
public List<AttributeValue> getListOfUnknownList(String attributeName) {
public List<AttributeValue> getListOfUnknownType(String attributeName) {
AttributeValue attributeValue = attributeValueMap.getValue().get(attributeName);
if (attributeValue == null) {
return null;
Expand Down Expand Up @@ -403,6 +403,8 @@ public Builder putJson(String attributeName, String json) {

@Override
public Builder remove(String attributeName) {
Validate.isTrue(!(attributeName == null || attributeName.trim().length() == 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we use StringUtils.isEmpty()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"Attribute name must not be null or empty");
nonAttributeValueMap.remove(attributeName);
return this;
}
Expand Down Expand Up @@ -492,9 +494,9 @@ public int hashCode() {
private static void checkAndValidateClass(Class<?> type, boolean isPut) {
Validate.paramNotNull(type, "type");
Validate.isTrue(!type.isAssignableFrom(List.class),
String.format(VALIDATE_TYPE_ERROR, List.class.getSimpleName(), isPut ? "put" : "get", "List"));
String.format(VALIDATE_TYPE_ERROR, "List", isPut ? "put" : "get", "List"));
Validate.isTrue(!type.isAssignableFrom(Map.class),
String.format(VALIDATE_TYPE_ERROR, Map.class.getSimpleName(), isPut ? "put" : "get", "Map"));
String.format(VALIDATE_TYPE_ERROR, "Map", isPut ? "put" : "get", "Map"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ public Map<String, AttributeValue> itemToMap(EnhancedDocument item, boolean igno
}

private List<AttributeConverterProvider> mergeAttributeConverterProviders(EnhancedDocument item) {
Set<AttributeConverterProvider> providers = new LinkedHashSet<>();
if (item.attributeConverterProviders() != null) {
if (item.attributeConverterProviders() != null && !item.attributeConverterProviders().isEmpty()) {
Set<AttributeConverterProvider> providers = new LinkedHashSet<>();
providers.addAll(item.attributeConverterProviders());
providers.addAll(attributeConverterProviders);
return providers.stream().collect(Collectors.toList());
}
providers.addAll(attributeConverterProviders);
return providers.stream().collect(Collectors.toList());
return attributeConverterProviders;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ void removeParameterFromDocument() {
assertThat(removedAttributesDoc.isNull("nullKey")).isFalse();
assertThat(removedAttributesDoc.isPresent("numberKey")).isFalse();
assertThat(removedAttributesDoc.getString("stringKey")).isEqualTo("stringValue");

assertThatIllegalArgumentException().isThrownBy(
() -> removedAttributesDoc.toBuilder().remove(""))
.withMessage("Attribute name must not be null or empty");


assertThatIllegalArgumentException().isThrownBy(
() -> removedAttributesDoc.toBuilder().remove(null))
.withMessage("Attribute name must not be null or empty");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ void validateGetterMethodsOfDefaultDocument(TestData testData) {
break;
case N:
assertThat(enhancedAttributeValue.asNumber()).isEqualTo(enhancedDocument.getNumber(key).stringValue());
assertThat(enhancedAttributeValue.asNumber()).isEqualTo(enhancedDocument.get(key, SdkNumber.class));
assertThat(enhancedAttributeValue.asNumber()).isEqualTo(enhancedDocument.get(key, EnhancedType.of(SdkNumber.class)));

assertThat(enhancedAttributeValue.asNumber()).isEqualTo(String.valueOf(enhancedDocument.get(key,
SdkNumber.class)));
assertThat(enhancedAttributeValue.asNumber()).isEqualTo(enhancedDocument.get(key,
EnhancedType.of(SdkNumber.class)).toString());
break;
case B:
assertThat(enhancedAttributeValue.asBytes()).isEqualTo(enhancedDocument.getBytes(key));
Expand Down Expand Up @@ -139,7 +140,7 @@ void validateGetterMethodsOfDefaultDocument(TestData testData) {
throw new IllegalStateException("Converter not found for " + enhancedType);
}
assertThat(converter.transformTo(value)).isEqualTo(enhancedDocument.getList(key, enhancedType));
assertThat(enhancedDocument.getListOfUnknownList(key)).isEqualTo(value.l());
assertThat(enhancedDocument.getListOfUnknownType(key)).isEqualTo(value.l());
break;
case M:
EnhancedType keyType = enhancedTypeMap.get(key).get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void putThenDeleteItem_usingShortcutForm() {

Map<String, AttributeValue> key = simpleKey();

docMappedtable.putItem(r -> r.item(enhancedDocument));
docMappedtable.putItem(r -> r.item(enhancedDocument)).join();
GetItemResponse lowLevelGetBeforeDelete = lowLevelClient.getItem(r -> r.key(key).tableName(tableName)).join();


Expand Down Expand Up @@ -261,7 +261,7 @@ public void putThenDeleteItem_usingKeyItemForm() {
.putString("attribute3", "three")
.build();

docMappedtable.putItem(enhancedDocument);
docMappedtable.putItem(enhancedDocument).join();
EnhancedDocument beforeDeleteResult =
docMappedtable.deleteItem(enhancedDocument).join();
EnhancedDocument afterDeleteResult =
Expand Down Expand Up @@ -394,7 +394,7 @@ public void updateOverwriteCompleteRecord_usingShortcutForm() {
.putString(ATTRIBUTE_NAME_WITH_SPECIAL_CHARACTERS, "three")
.build();

docMappedtable.putItem(enhancedDocument);
docMappedtable.putItem(enhancedDocument).join();
// Updating new Items other than the one present in testData
EnhancedDocument.Builder updateDocBuilder = EnhancedDocument.builder()
.attributeConverterProviders(defaultProvider())
Expand Down