Search in sources :

Example 1 with ReturnValue

use of software.amazon.awssdk.services.dynamodb.model.ReturnValue in project aws-sdk-java-v2 by aws.

the class PutItemEnhancedRequestTest method builder_maximal.

@Test
public void builder_maximal() {
    FakeItem fakeItem = createUniqueFakeItem();
    Expression conditionExpression = Expression.builder().expression("#key = :value OR #key1 = :value1").putExpressionName("#key", "attribute").putExpressionName("#key1", "attribute3").putExpressionValue(":value", stringValue("wrong")).putExpressionValue(":value1", stringValue("three")).build();
    ReturnValue returnValues = ReturnValue.ALL_OLD;
    ReturnConsumedCapacity returnConsumedCapacity = ReturnConsumedCapacity.INDEXES;
    ReturnItemCollectionMetrics returnItemCollectionMetrics = ReturnItemCollectionMetrics.SIZE;
    PutItemEnhancedRequest<FakeItem> builtObject = PutItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).conditionExpression(conditionExpression).returnValues(returnValues).returnConsumedCapacity(returnConsumedCapacity).returnItemCollectionMetrics(returnItemCollectionMetrics).build();
    assertThat(builtObject.item(), is(fakeItem));
    assertThat(builtObject.conditionExpression(), is(conditionExpression));
    assertThat(builtObject.returnValues(), is(returnValues));
    assertThat(builtObject.returnValuesAsString(), is(returnValues.toString()));
    assertThat(builtObject.returnConsumedCapacity(), is(returnConsumedCapacity));
    assertThat(builtObject.returnConsumedCapacityAsString(), is(returnConsumedCapacity.toString()));
    assertThat(builtObject.returnItemCollectionMetrics(), is(returnItemCollectionMetrics));
    assertThat(builtObject.returnItemCollectionMetricsAsString(), is(returnItemCollectionMetrics.toString()));
}
Also used : Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) ReturnConsumedCapacity(software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity) ReturnValue(software.amazon.awssdk.services.dynamodb.model.ReturnValue) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) ReturnItemCollectionMetrics(software.amazon.awssdk.services.dynamodb.model.ReturnItemCollectionMetrics) Test(org.junit.Test)

Example 2 with ReturnValue

use of software.amazon.awssdk.services.dynamodb.model.ReturnValue in project aws-sdk-java-v2 by aws.

the class PutItemOperationTest method generateRequest_withReturnValues_knownValue_generatesCorrectRequest.

@Test
public void generateRequest_withReturnValues_knownValue_generatesCorrectRequest() {
    FakeItem fakeItem = createUniqueFakeItem();
    fakeItem.setSubclassAttribute("subclass-value");
    ReturnValue returnValues = ReturnValue.ALL_OLD;
    PutItemOperation<FakeItem> putItemOperation = PutItemOperation.create(PutItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).returnValues(returnValues).build());
    PutItemRequest request = putItemOperation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null);
    Map<String, AttributeValue> expectedItemMap = new HashMap<>();
    expectedItemMap.put("id", AttributeValue.builder().s(fakeItem.getId()).build());
    expectedItemMap.put("subclass_attribute", AttributeValue.builder().s("subclass-value").build());
    PutItemRequest expectedRequest = PutItemRequest.builder().tableName(TABLE_NAME).item(expectedItemMap).returnValues(returnValues).build();
    assertThat(request, is(expectedRequest));
}
Also used : AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) HashMap(java.util.HashMap) PutItemRequest(software.amazon.awssdk.services.dynamodb.model.PutItemRequest) ReturnValue(software.amazon.awssdk.services.dynamodb.model.ReturnValue) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Example 3 with ReturnValue

use of software.amazon.awssdk.services.dynamodb.model.ReturnValue in project aws-sdk-java-v2 by aws.

the class PutItemEnhancedRequestTest method toBuilder.

@Test
public void toBuilder() {
    FakeItem fakeItem = createUniqueFakeItem();
    Expression conditionExpression = Expression.builder().expression("#key = :value OR #key1 = :value1").putExpressionName("#key", "attribute").putExpressionName("#key1", "attribute3").putExpressionValue(":value", stringValue("wrong")).putExpressionValue(":value1", stringValue("three")).build();
    ReturnValue returnValues = ReturnValue.ALL_OLD;
    ReturnConsumedCapacity returnConsumedCapacity = ReturnConsumedCapacity.INDEXES;
    ReturnItemCollectionMetrics returnItemCollectionMetrics = ReturnItemCollectionMetrics.SIZE;
    PutItemEnhancedRequest<FakeItem> builtObject = PutItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).conditionExpression(conditionExpression).returnValues(returnValues).returnConsumedCapacity(returnConsumedCapacity).returnItemCollectionMetrics(returnItemCollectionMetrics).build();
    PutItemEnhancedRequest<FakeItem> copiedObject = builtObject.toBuilder().build();
    assertThat(copiedObject, is(builtObject));
}
Also used : Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) ReturnConsumedCapacity(software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity) ReturnValue(software.amazon.awssdk.services.dynamodb.model.ReturnValue) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) ReturnItemCollectionMetrics(software.amazon.awssdk.services.dynamodb.model.ReturnItemCollectionMetrics) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 FakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem)3 FakeItem.createUniqueFakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem)3 ReturnValue (software.amazon.awssdk.services.dynamodb.model.ReturnValue)3 Expression (software.amazon.awssdk.enhanced.dynamodb.Expression)2 ReturnConsumedCapacity (software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity)2 ReturnItemCollectionMetrics (software.amazon.awssdk.services.dynamodb.model.ReturnItemCollectionMetrics)2 HashMap (java.util.HashMap)1 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)1 PutItemRequest (software.amazon.awssdk.services.dynamodb.model.PutItemRequest)1