use of software.amazon.awssdk.enhanced.dynamodb.update.DeleteAction in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_withExtensions_conditionAndUpdateExpression.
@Test
public void generateRequest_withExtensions_conditionAndUpdateExpression() {
FakeItem baseFakeItem = createUniqueFakeItem();
FakeItem fakeItem = createUniqueFakeItem();
Map<String, AttributeValue> fakeMap = FakeItem.getTableSchema().itemToMap(fakeItem, true);
Expression condition = Expression.builder().expression("condition").expressionValues(fakeMap).build();
Map<String, AttributeValue> deleteActionMap = singletonMap(":val", AttributeValue.builder().s("s").build());
DeleteAction deleteAction = DeleteAction.builder().path("attr1").value(":val").expressionValues(deleteActionMap).build();
UpdateExpression updateExpression = UpdateExpression.builder().addAction(deleteAction).build();
when(mockDynamoDbEnhancedClientExtension.beforeWrite(any(DynamoDbExtensionContext.BeforeWrite.class))).thenReturn(WriteModification.builder().additionalConditionalExpression(condition).updateExpression(updateExpression).build());
UpdateItemOperation<FakeItem> updateItemOperation = UpdateItemOperation.create(requestFakeItem(baseFakeItem, b -> b.ignoreNulls(true)));
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, mockDynamoDbEnhancedClientExtension);
assertThat(request.conditionExpression(), is("condition"));
assertThat(request.updateExpression(), is("DELETE attr1 :val"));
assertThat(request.expressionAttributeValues(), is(Expression.joinValues(fakeMap, deleteActionMap)));
}
use of software.amazon.awssdk.enhanced.dynamodb.update.DeleteAction in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_withExtensions_singleUpdateExpression.
@Test
public void generateRequest_withExtensions_singleUpdateExpression() {
Map<String, AttributeValue> deleteActionMap = singletonMap(":val", AttributeValue.builder().s("s").build());
DeleteAction deleteAction = DeleteAction.builder().path("attr1").value(":val").expressionValues(deleteActionMap).build();
UpdateExpression updateExpression = UpdateExpression.builder().addAction(deleteAction).build();
FakeItem item = createUniqueFakeItem();
when(mockDynamoDbEnhancedClientExtension.beforeWrite(any(DynamoDbExtensionContext.BeforeWrite.class))).thenReturn(WriteModification.builder().updateExpression(updateExpression).build());
UpdateItemOperation<FakeItem> updateItemOperation = UpdateItemOperation.create(requestFakeItem(item, b -> b.ignoreNulls(true)));
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, mockDynamoDbEnhancedClientExtension);
assertThat(request.updateExpression(), is("DELETE attr1 :val"));
assertThat(request.expressionAttributeValues(), is(deleteActionMap));
}
Aggregations