Search in sources :

Example 1 with ReturnConsumedCapacity

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

the class UpdateItemEnhancedRequestTest 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();
    ReturnConsumedCapacity returnConsumedCapacity = ReturnConsumedCapacity.TOTAL;
    ReturnItemCollectionMetrics returnItemCollectionMetrics = ReturnItemCollectionMetrics.SIZE;
    UpdateItemEnhancedRequest<FakeItem> builtObject = UpdateItemEnhancedRequest.builder(FakeItem.class).item(fakeItem).ignoreNulls(true).conditionExpression(conditionExpression).returnConsumedCapacity(returnConsumedCapacity).returnItemCollectionMetrics(returnItemCollectionMetrics).build();
    UpdateItemEnhancedRequest<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) 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 ReturnConsumedCapacity

use of software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity 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 3 with ReturnConsumedCapacity

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

the class DeleteItemEnhancedRequestTest method hashCode_includesReturnConsumedCapacity.

@Test
public void hashCode_includesReturnConsumedCapacity() {
    DeleteItemEnhancedRequest emptyRequest = DeleteItemEnhancedRequest.builder().build();
    ReturnConsumedCapacity returnConsumedCapacity = ReturnConsumedCapacity.TOTAL;
    DeleteItemEnhancedRequest containsKey = DeleteItemEnhancedRequest.builder().returnConsumedCapacity(returnConsumedCapacity).build();
    assertThat(containsKey.hashCode(), not(equalTo(emptyRequest.hashCode())));
}
Also used : ReturnConsumedCapacity(software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity) Test(org.junit.Test)

Example 4 with ReturnConsumedCapacity

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

the class DeleteItemEnhancedRequestTest method builder_maximal.

@Test
public void builder_maximal() {
    Key key = Key.builder().partitionValue("key").build();
    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();
    ReturnConsumedCapacity returnConsumedCapacity = ReturnConsumedCapacity.TOTAL;
    ReturnItemCollectionMetrics returnItemCollectionMetrics = ReturnItemCollectionMetrics.SIZE;
    DeleteItemEnhancedRequest builtObject = DeleteItemEnhancedRequest.builder().key(key).conditionExpression(conditionExpression).returnConsumedCapacity(returnConsumedCapacity).returnItemCollectionMetrics(returnItemCollectionMetrics).build();
    assertThat(builtObject.key(), is(key));
    assertThat(builtObject.conditionExpression(), is(conditionExpression));
    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) Key(software.amazon.awssdk.enhanced.dynamodb.Key) ReturnItemCollectionMetrics(software.amazon.awssdk.services.dynamodb.model.ReturnItemCollectionMetrics) Test(org.junit.Test)

Example 5 with ReturnConsumedCapacity

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

the class UpdateItemOperationTest method generateRequest_withReturnConsumedCapacity_knownValue_generatesCorrectRequest.

@Test
public void generateRequest_withReturnConsumedCapacity_knownValue_generatesCorrectRequest() {
    FakeItem item = createUniqueFakeItem();
    ReturnConsumedCapacity returnConsumedCapacity = ReturnConsumedCapacity.TOTAL;
    UpdateItemOperation<FakeItem> updateItemOperation = UpdateItemOperation.create(requestFakeItem(item, b -> b.ignoreNulls(true).returnConsumedCapacity(returnConsumedCapacity)));
    UpdateItemRequest request = updateItemOperation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null);
    UpdateItemRequest expectedRequest = ddbRequest(ddbKey(item.getId()), b -> b.returnConsumedCapacity(returnConsumedCapacity));
    assertThat(request, is(expectedRequest));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Matchers.either(org.hamcrest.Matchers.either) AttributeValues.numberValue(software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.numberValue) Mock(org.mockito.Mock) UpdateItemRequest(software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest) RunWith(org.junit.runner.RunWith) FakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort) HashMap(java.util.HashMap) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) Collections.singletonList(java.util.Collections.singletonList) UpdateExpression(software.amazon.awssdk.enhanced.dynamodb.update.UpdateExpression) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Assert.fail(org.junit.Assert.fail) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) ReadModification(software.amazon.awssdk.enhanced.dynamodb.extensions.ReadModification) ReturnConsumedCapacity(software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) WriteModification(software.amazon.awssdk.enhanced.dynamodb.extensions.WriteModification) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) UpdateItemEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedRequest) Consumer(java.util.function.Consumer) DefaultDynamoDbExtensionContext(software.amazon.awssdk.enhanced.dynamodb.internal.extensions.DefaultDynamoDbExtensionContext) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) Stream(java.util.stream.Stream) DeleteAction(software.amazon.awssdk.enhanced.dynamodb.update.DeleteAction) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) FakeItemWithSort.createUniqueFakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort.createUniqueFakeItemWithSort) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Matchers.is(org.hamcrest.Matchers.is) DynamoDbExtensionContext(software.amazon.awssdk.enhanced.dynamodb.DynamoDbExtensionContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ReturnValue(software.amazon.awssdk.services.dynamodb.model.ReturnValue) ReturnItemCollectionMetrics(software.amazon.awssdk.services.dynamodb.model.ReturnItemCollectionMetrics) UpdateItemResponse(software.amazon.awssdk.services.dynamodb.model.UpdateItemResponse) UpdateItemRequest(software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest) ReturnConsumedCapacity(software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 ReturnConsumedCapacity (software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity)15 ReturnItemCollectionMetrics (software.amazon.awssdk.services.dynamodb.model.ReturnItemCollectionMetrics)11 Expression (software.amazon.awssdk.enhanced.dynamodb.Expression)10 FakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem)9 FakeItem.createUniqueFakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem)9 ReturnValue (software.amazon.awssdk.services.dynamodb.model.ReturnValue)6 HashMap (java.util.HashMap)5 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)5 Collections (java.util.Collections)4 Collections.singletonList (java.util.Collections.singletonList)4 Map (java.util.Map)4 UUID (java.util.UUID)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.is (org.hamcrest.Matchers.is)4 Matchers.nullValue (org.hamcrest.Matchers.nullValue)4 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)4 RunWith (org.junit.runner.RunWith)4 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)4 Mock (org.mockito.Mock)4