use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort in project aws-sdk-java-v2 by aws.
the class VersionedRecordExtensionTest method beforeWrite_returnsNoOpModification_ifVersionAttributeNotDefined.
@Test
public void beforeWrite_returnsNoOpModification_ifVersionAttributeNotDefined() {
FakeItemWithSort fakeItemWithSort = createUniqueFakeItemWithSort();
Map<String, AttributeValue> itemMap = new HashMap<>(FakeItemWithSort.getTableSchema().itemToMap(fakeItemWithSort, true));
WriteModification writeModification = versionedRecordExtension.beforeWrite(DefaultDynamoDbExtensionContext.builder().items(itemMap).operationContext(PRIMARY_CONTEXT).tableMetadata(FakeItemWithSort.getTableMetadata()).build());
assertThat(writeModification, is(WriteModification.builder().build()));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_multipleDeletes.
@Test
public void generateRequest_multipleDeletes() {
FakeItemWithSort item = createUniqueFakeItemWithSort();
UpdateItemOperation<FakeItemWithSort> updateItemOperation = UpdateItemOperation.create(requestFakeItemWithSort(item, b -> b.ignoreNulls(false)));
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItemWithSort.getTableSchema(), PRIMARY_CONTEXT, null);
UpdateItemRequest.Builder expectedRequestBuilder = ddbRequestBuilder(ddbKey(item.getId(), item.getSort()));
expectedRequestBuilder.expressionAttributeNames(expressionNamesFor(OTHER_ATTRIBUTE_1_NAME, OTHER_ATTRIBUTE_2_NAME));
String updateExpression1 = "REMOVE " + OTHER_ATTRIBUTE_1_NAME + ", " + OTHER_ATTRIBUTE_2_NAME;
UpdateItemRequest expectedRequest1 = expectedRequestBuilder.updateExpression(updateExpression1).build();
String updateExpression2 = "REMOVE " + OTHER_ATTRIBUTE_2_NAME + ", " + OTHER_ATTRIBUTE_1_NAME;
UpdateItemRequest expectedRequest2 = expectedRequestBuilder.updateExpression(updateExpression2).build();
assertThat(request, either(is(expectedRequest1)).or(is(expectedRequest2)));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_nullValuesNotIgnoredByDefault.
@Test
public void generateRequest_nullValuesNotIgnoredByDefault() {
FakeItemWithSort item = createUniqueFakeItemWithSort();
item.setOtherAttribute1("value-1");
UpdateItemOperation<FakeItemWithSort> updateItemOperation = UpdateItemOperation.create(requestFakeItemWithSort(item, b -> {
}));
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItemWithSort.getTableSchema(), PRIMARY_CONTEXT, null);
String expectedUpdateExpression = "SET " + OTHER_ATTRIBUTE_1_NAME + " = " + OTHER_ATTRIBUTE_1_VALUE + " REMOVE " + OTHER_ATTRIBUTE_2_NAME;
UpdateItemRequest.Builder expectedRequestBuilder = ddbRequestBuilder(ddbKey(item.getId(), item.getSort()));
expectedRequestBuilder.expressionAttributeValues(expressionValuesFor(OTHER_ATTRIBUTE_1_VALUE));
expectedRequestBuilder.expressionAttributeNames(expressionNamesFor(OTHER_ATTRIBUTE_1_NAME, OTHER_ATTRIBUTE_2_NAME));
expectedRequestBuilder.updateExpression(expectedUpdateExpression);
assertThat(request, is(expectedRequestBuilder.build()));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_multipleSetters.
@Test
public void generateRequest_multipleSetters() {
FakeItemWithSort item = createUniqueFakeItemWithSort();
item.setOtherAttribute1("value-1");
item.setOtherAttribute2("value-2");
UpdateItemOperation<FakeItemWithSort> updateItemOperation = UpdateItemOperation.create(requestFakeItemWithSort(item, b -> b.ignoreNulls(false)));
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItemWithSort.getTableSchema(), PRIMARY_CONTEXT, null);
UpdateItemRequest.Builder expectedRequestBuilder = ddbRequestBuilder(ddbKey(item.getId(), item.getSort()));
expectedRequestBuilder.expressionAttributeValues(expressionValuesFor(OTHER_ATTRIBUTE_1_VALUE, OTHER_ATTRIBUTE_2_VALUE));
expectedRequestBuilder.expressionAttributeNames(expressionNamesFor(OTHER_ATTRIBUTE_1_NAME, OTHER_ATTRIBUTE_2_NAME));
String updateExpression1 = "SET " + OTHER_ATTRIBUTE_1_NAME + " = " + OTHER_ATTRIBUTE_1_VALUE + ", " + OTHER_ATTRIBUTE_2_NAME + " = " + OTHER_ATTRIBUTE_2_VALUE;
UpdateItemRequest expectedRequest1 = expectedRequestBuilder.updateExpression(updateExpression1).build();
String updateExpression2 = "SET " + OTHER_ATTRIBUTE_2_NAME + " = " + OTHER_ATTRIBUTE_2_VALUE + ", " + OTHER_ATTRIBUTE_1_NAME + " = " + OTHER_ATTRIBUTE_1_VALUE;
UpdateItemRequest expectedRequest2 = expectedRequestBuilder.updateExpression(updateExpression2).build();
assertThat(request, either(is(expectedRequest1)).or(is(expectedRequest2)));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_canIgnoreNullValues.
@Test
public void generateRequest_canIgnoreNullValues() {
FakeItemWithSort item = createUniqueFakeItemWithSort();
item.setOtherAttribute1("value-1");
UpdateItemOperation<FakeItemWithSort> updateItemOperation = UpdateItemOperation.create(requestFakeItemWithSort(item, b -> b.ignoreNulls(true)));
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItemWithSort.getTableSchema(), PRIMARY_CONTEXT, null);
String expectedUpdateExpression = "SET " + OTHER_ATTRIBUTE_1_NAME + " = " + OTHER_ATTRIBUTE_1_VALUE;
UpdateItemRequest.Builder expectedRequestBuilder = ddbRequestBuilder(ddbKey(item.getId(), item.getSort()));
expectedRequestBuilder.expressionAttributeValues(expressionValuesFor(OTHER_ATTRIBUTE_1_VALUE));
expectedRequestBuilder.expressionAttributeNames(expressionNamesFor(OTHER_ATTRIBUTE_1_NAME));
expectedRequestBuilder.updateExpression(expectedUpdateExpression);
UpdateItemRequest expectedRequest = expectedRequestBuilder.build();
assertThat(request, is(expectedRequest));
}
Aggregations