Search in sources :

Example 1 with ConditionCheck

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

the class ConditionCheckTest method hashCode_maximal.

@Test
public void hashCode_maximal() {
    FakeItem fakeItem = FakeItem.createUniqueFakeItem();
    String returnValues = "ALL_OLD";
    Expression conditionExpression = Expression.builder().expression("expression").expressionNames(singletonMap("key1", "value1")).expressionValues(singletonMap("key2", stringValue("value2"))).build();
    ConditionCheck<FakeItem> builtObject = ConditionCheck.builder().key(k -> k.partitionValue(fakeItem.getId())).conditionExpression(conditionExpression).returnValuesOnConditionCheckFailure(returnValues).build();
    ConditionCheck<Object> copiedObject = builtObject.toBuilder().build();
    assertThat(builtObject.hashCode(), equalTo(copiedObject.hashCode()));
}
Also used : ReturnValuesOnConditionCheckFailure(software.amazon.awssdk.services.dynamodb.model.ReturnValuesOnConditionCheckFailure) TransactWriteItem(software.amazon.awssdk.services.dynamodb.model.TransactWriteItem) Mock(org.mockito.Mock) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Matchers.not(org.hamcrest.Matchers.not) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) ConditionCheck(software.amazon.awssdk.enhanced.dynamodb.model.ConditionCheck) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AttributeValues.stringValue(software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.stringValue) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Example 2 with ConditionCheck

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

the class ConditionCheckTest method equals_maximal.

@Test
public void equals_maximal() {
    FakeItem fakeItem = FakeItem.createUniqueFakeItem();
    String returnValues = "ALL_OLD";
    Expression conditionExpression = Expression.builder().expression("expression").expressionNames(singletonMap("key1", "value1")).expressionValues(singletonMap("key2", stringValue("value2"))).build();
    ConditionCheck<FakeItem> builtObject = ConditionCheck.builder().key(k -> k.partitionValue(fakeItem.getId())).conditionExpression(conditionExpression).returnValuesOnConditionCheckFailure(returnValues).build();
    ConditionCheck<Object> copiedObject = builtObject.toBuilder().build();
    assertThat(builtObject, equalTo(copiedObject));
}
Also used : ReturnValuesOnConditionCheckFailure(software.amazon.awssdk.services.dynamodb.model.ReturnValuesOnConditionCheckFailure) TransactWriteItem(software.amazon.awssdk.services.dynamodb.model.TransactWriteItem) Mock(org.mockito.Mock) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Matchers.not(org.hamcrest.Matchers.not) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) ConditionCheck(software.amazon.awssdk.enhanced.dynamodb.model.ConditionCheck) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AttributeValues.stringValue(software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.stringValue) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Example 3 with ConditionCheck

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

the class ConditionCheckTest method builder_maximal.

@Test
public void builder_maximal() {
    FakeItem fakeItem = FakeItem.createUniqueFakeItem();
    String returnValues = "ALL_OLD";
    Expression conditionExpression = Expression.builder().expression("expression").expressionNames(singletonMap("key1", "value1")).expressionValues(singletonMap("key2", stringValue("value2"))).build();
    ConditionCheck<FakeItem> builtObject = ConditionCheck.builder().key(k -> k.partitionValue(fakeItem.getId())).conditionExpression(conditionExpression).returnValuesOnConditionCheckFailure(returnValues).build();
    assertThat(builtObject.conditionExpression(), is(conditionExpression));
    assertThat(builtObject.returnValuesOnConditionCheckFailure(), is(ReturnValuesOnConditionCheckFailure.ALL_OLD));
    assertThat(builtObject.returnValuesOnConditionCheckFailureAsString(), is(returnValues));
}
Also used : ReturnValuesOnConditionCheckFailure(software.amazon.awssdk.services.dynamodb.model.ReturnValuesOnConditionCheckFailure) TransactWriteItem(software.amazon.awssdk.services.dynamodb.model.TransactWriteItem) Mock(org.mockito.Mock) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Matchers.not(org.hamcrest.Matchers.not) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) ConditionCheck(software.amazon.awssdk.enhanced.dynamodb.model.ConditionCheck) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AttributeValues.stringValue(software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.stringValue) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Example 4 with ConditionCheck

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

the class ConditionCheckTest method generateTransactWriteItem.

@Test
public void generateTransactWriteItem() {
    FakeItem fakeItem = FakeItem.createUniqueFakeItem();
    Map<String, AttributeValue> keyMap = singletonMap("id", stringValue(fakeItem.getId()));
    String returnValues = "return-values";
    Expression conditionExpression = Expression.builder().expression("expression").expressionNames(singletonMap("key1", "value1")).expressionValues(singletonMap("key2", stringValue("value2"))).build();
    ConditionCheck<FakeItem> operation = ConditionCheck.builder().key(k -> k.partitionValue(fakeItem.getId())).conditionExpression(conditionExpression).returnValuesOnConditionCheckFailure(returnValues).build();
    OperationContext context = DefaultOperationContext.create("table-name", TableMetadata.primaryIndexName());
    TransactWriteItem result = operation.generateTransactWriteItem(FakeItem.getTableSchema(), context, mockDynamoDbEnhancedClientExtension);
    TransactWriteItem expectedResult = TransactWriteItem.builder().conditionCheck(software.amazon.awssdk.services.dynamodb.model.ConditionCheck.builder().tableName("table-name").key(keyMap).conditionExpression(conditionExpression.expression()).expressionAttributeValues(conditionExpression.expressionValues()).expressionAttributeNames(conditionExpression.expressionNames()).returnValuesOnConditionCheckFailure(returnValues).build()).build();
    assertThat(result, is(expectedResult));
    verifyNoMoreInteractions(mockDynamoDbEnhancedClientExtension);
}
Also used : ReturnValuesOnConditionCheckFailure(software.amazon.awssdk.services.dynamodb.model.ReturnValuesOnConditionCheckFailure) TransactWriteItem(software.amazon.awssdk.services.dynamodb.model.TransactWriteItem) Mock(org.mockito.Mock) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Matchers.not(org.hamcrest.Matchers.not) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) ConditionCheck(software.amazon.awssdk.enhanced.dynamodb.model.ConditionCheck) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Collections.singletonMap(java.util.Collections.singletonMap) Matchers.is(org.hamcrest.Matchers.is) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AttributeValues.stringValue(software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.stringValue) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) TransactWriteItem(software.amazon.awssdk.services.dynamodb.model.TransactWriteItem) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) Test(org.junit.Test)

Aggregations

Collections.singletonMap (java.util.Collections.singletonMap)4 Map (java.util.Map)4 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.equalTo (org.hamcrest.Matchers.equalTo)4 Matchers.is (org.hamcrest.Matchers.is)4 Matchers.not (org.hamcrest.Matchers.not)4 Matchers.nullValue (org.hamcrest.Matchers.nullValue)4 Test (org.junit.Test)4 RunWith (org.junit.runner.RunWith)4 Mock (org.mockito.Mock)4 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)4 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)4 DynamoDbEnhancedClientExtension (software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension)4 Expression (software.amazon.awssdk.enhanced.dynamodb.Expression)4 Key (software.amazon.awssdk.enhanced.dynamodb.Key)4 OperationContext (software.amazon.awssdk.enhanced.dynamodb.OperationContext)4 TableMetadata (software.amazon.awssdk.enhanced.dynamodb.TableMetadata)4 FakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem)4 AttributeValues.stringValue (software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.stringValue)4 ConditionCheck (software.amazon.awssdk.enhanced.dynamodb.model.ConditionCheck)4