use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateRequest_withExtension_modifiesUpdateExpression.
@Test
public void generateRequest_withExtension_modifiesUpdateExpression() {
FakeItem fakeItem = createUniqueFakeItem();
Map<String, AttributeValue> baseMap = new HashMap<>(FakeItem.getTableSchema().itemToMap(fakeItem, true));
Map<String, AttributeValue> fakeMap = new HashMap<>(baseMap);
fakeMap.put("subclass_attribute", AttributeValue.builder().s("1").build());
when(mockDynamoDbEnhancedClientExtension.beforeWrite(any(DynamoDbExtensionContext.BeforeWrite.class))).thenReturn(WriteModification.builder().transformedItem(fakeMap).build());
UpdateItemOperation<FakeItem> updateItemOperation = UpdateItemOperation.create(UpdateItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).ignoreNulls(true).build());
UpdateItemRequest request = updateItemOperation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, mockDynamoDbEnhancedClientExtension);
assertThat(request.updateExpression(), is("SET " + SUBCLASS_ATTRIBUTE_NAME + " = " + SUBCLASS_ATTRIBUTE_VALUE));
assertThat(request.expressionAttributeValues(), hasEntry(SUBCLASS_ATTRIBUTE_VALUE, AttributeValue.builder().s("1").build()));
assertThat(request.expressionAttributeNames(), hasEntry(SUBCLASS_ATTRIBUTE_NAME, "subclass_attribute"));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateTransactWriteItem_basicRequest.
@Test
public void generateTransactWriteItem_basicRequest() {
FakeItem fakeItem = createUniqueFakeItem();
Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, true);
UpdateItemOperation<FakeItem> updateItemOperation = spy(UpdateItemOperation.create(UpdateItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).build()));
OperationContext context = DefaultOperationContext.create(TABLE_NAME, TableMetadata.primaryIndexName());
String updateExpression = "update-expression";
Map<String, AttributeValue> attributeValues = Collections.singletonMap("key", stringValue("value1"));
Map<String, String> attributeNames = Collections.singletonMap("key", "value2");
UpdateItemRequest updateItemRequest = UpdateItemRequest.builder().tableName(TABLE_NAME).key(fakeItemMap).updateExpression(updateExpression).expressionAttributeValues(attributeValues).expressionAttributeNames(attributeNames).build();
doReturn(updateItemRequest).when(updateItemOperation).generateRequest(any(), any(), any());
TransactWriteItem actualResult = updateItemOperation.generateTransactWriteItem(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
TransactWriteItem expectedResult = TransactWriteItem.builder().update(Update.builder().key(fakeItemMap).tableName(TABLE_NAME).updateExpression(updateExpression).expressionAttributeNames(attributeNames).expressionAttributeValues(attributeValues).build()).build();
assertThat(actualResult, is(expectedResult));
verify(updateItemOperation).generateRequest(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method transformResponse_mapsAttributesReturnedInResponse.
@Test
public void transformResponse_mapsAttributesReturnedInResponse() {
FakeItem fakeItem1 = FakeItem.createUniqueFakeItem();
FakeItem fakeItem2 = FakeItem.createUniqueFakeItem();
Map<String, AttributeValue> fakeItem2Attributes = FakeItem.getTableSchema().itemToMap(fakeItem2, true);
UpdateItemOperation<FakeItem> updateItemOperation = UpdateItemOperation.create(UpdateItemEnhancedRequest.builder(FakeItem.class).item(fakeItem1).build());
FakeItem result = updateItemOperation.transformResponse(UpdateItemResponse.builder().attributes(fakeItem2Attributes).build(), FakeItem.getTableSchema(), PRIMARY_CONTEXT, null).attributes();
assertThat(result, is(fakeItem2));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem in project aws-sdk-java-v2 by aws.
the class UpdateItemOperationTest method generateTransactWriteItem_conditionalRequest.
@Test
public void generateTransactWriteItem_conditionalRequest() {
FakeItem fakeItem = createUniqueFakeItem();
Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, true);
UpdateItemOperation<FakeItem> updateItemOperation = spy(UpdateItemOperation.create(UpdateItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).build()));
OperationContext context = DefaultOperationContext.create(TABLE_NAME, TableMetadata.primaryIndexName());
String updateExpression = "update-expression";
String conditionExpression = "condition-expression";
Map<String, AttributeValue> attributeValues = Collections.singletonMap("key", stringValue("value1"));
Map<String, String> attributeNames = Collections.singletonMap("key", "value2");
UpdateItemRequest updateItemRequest = UpdateItemRequest.builder().tableName(TABLE_NAME).key(fakeItemMap).updateExpression(updateExpression).conditionExpression(conditionExpression).expressionAttributeValues(attributeValues).expressionAttributeNames(attributeNames).build();
doReturn(updateItemRequest).when(updateItemOperation).generateRequest(any(), any(), any());
TransactWriteItem actualResult = updateItemOperation.generateTransactWriteItem(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
TransactWriteItem expectedResult = TransactWriteItem.builder().update(Update.builder().key(fakeItemMap).tableName(TABLE_NAME).updateExpression(updateExpression).conditionExpression(conditionExpression).expressionAttributeNames(attributeNames).expressionAttributeValues(attributeValues).build()).build();
assertThat(actualResult, is(expectedResult));
verify(updateItemOperation).generateRequest(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem in project aws-sdk-java-v2 by aws.
the class VersionedRecordExtensionTest method beforeRead_doesNotTransformObject.
@Test
public void beforeRead_doesNotTransformObject() {
FakeItem fakeItem = createUniqueFakeItem();
Map<String, AttributeValue> fakeItemMap = FakeItem.getTableSchema().itemToMap(fakeItem, true);
ReadModification result = versionedRecordExtension.afterRead(DefaultDynamoDbExtensionContext.builder().items(fakeItemMap).tableMetadata(FakeItem.getTableMetadata()).operationContext(PRIMARY_CONTEXT).build());
assertThat(result, is(ReadModification.builder().build()));
}
Aggregations