use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices in project aws-sdk-java-v2 by aws.
the class QueryOperationTest method generateRequest_secondaryIndex_exclusiveStartKeyUsesPrimaryAndSecondaryIndex.
@Test
public void generateRequest_secondaryIndex_exclusiveStartKeyUsesPrimaryAndSecondaryIndex() {
FakeItemWithIndices exclusiveStartKey = createUniqueFakeItemWithIndices();
Set<String> keyFields = new HashSet<>(FakeItemWithIndices.getTableSchema().tableMetadata().primaryKeys());
keyFields.addAll(FakeItemWithIndices.getTableSchema().tableMetadata().indexKeys("gsi_1"));
QueryOperation<FakeItemWithIndices> queryToTest = QueryOperation.create(QueryEnhancedRequest.builder().queryConditional(keyEqualTo(k -> k.partitionValue(keyItem.getId()))).exclusiveStartKey(FakeItemWithIndices.getTableSchema().itemToMap(exclusiveStartKey, keyFields)).build());
QueryRequest queryRequest = queryToTest.generateRequest(FakeItemWithIndices.getTableSchema(), GSI_1_CONTEXT, null);
assertThat(queryRequest.exclusiveStartKey(), hasEntry("id", AttributeValue.builder().s(exclusiveStartKey.getId()).build()));
assertThat(queryRequest.exclusiveStartKey(), hasEntry("sort", AttributeValue.builder().s(exclusiveStartKey.getSort()).build()));
assertThat(queryRequest.exclusiveStartKey(), hasEntry("gsi_id", AttributeValue.builder().s(exclusiveStartKey.getGsiId()).build()));
assertThat(queryRequest.exclusiveStartKey(), hasEntry("gsi_sort", AttributeValue.builder().s(exclusiveStartKey.getGsiSort()).build()));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices in project aws-sdk-java-v2 by aws.
the class ScanOperationTest method generateRequest_knowsHowToUseAnIndex.
@Test
public void generateRequest_knowsHowToUseAnIndex() {
ScanOperation<FakeItemWithIndices> operation = ScanOperation.create(ScanEnhancedRequest.builder().build());
ScanRequest scanRequest = operation.generateRequest(FakeItemWithIndices.getTableSchema(), GSI_1_CONTEXT, null);
assertThat(scanRequest.indexName(), is("gsi_1"));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices in project aws-sdk-java-v2 by aws.
the class DefaultDynamoDbAsyncIndexTest method keyFrom_secondaryIndex_partitionAndSort.
@Test
public void keyFrom_secondaryIndex_partitionAndSort() {
FakeItemWithIndices item = FakeItemWithIndices.createUniqueFakeItemWithIndices();
DefaultDynamoDbAsyncIndex<FakeItemWithIndices> dynamoDbMappedIndex = new DefaultDynamoDbAsyncIndex<>(mockDynamoDbAsyncClient, mockDynamoDbEnhancedClientExtension, FakeItemWithIndices.getTableSchema(), "test_table", "gsi_1");
Key key = dynamoDbMappedIndex.keyFrom(item);
assertThat(key.partitionKeyValue(), is(stringValue(item.getGsiId())));
assertThat(key.sortKeyValue(), is(Optional.of(stringValue(item.getGsiSort()))));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices in project aws-sdk-java-v2 by aws.
the class DefaultDynamoDbIndexTest method keyFrom_secondaryIndex_partitionAndSort.
@Test
public void keyFrom_secondaryIndex_partitionAndSort() {
FakeItemWithIndices item = FakeItemWithIndices.createUniqueFakeItemWithIndices();
DefaultDynamoDbIndex<FakeItemWithIndices> dynamoDbMappedIndex = new DefaultDynamoDbIndex<>(mockDynamoDbClient, mockDynamoDbEnhancedClientExtension, FakeItemWithIndices.getTableSchema(), "test_table", "gsi_1");
Key key = dynamoDbMappedIndex.keyFrom(item);
assertThat(key.partitionKeyValue(), is(stringValue(item.getGsiId())));
assertThat(key.sortKeyValue(), is(Optional.of(stringValue(item.getGsiSort()))));
}
use of software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices in project aws-sdk-java-v2 by aws.
the class QueryOperationTest method generateRequest_knowsHowToUseAnIndex.
@Test
public void generateRequest_knowsHowToUseAnIndex() {
FakeItemWithIndices fakeItem = createUniqueFakeItemWithIndices();
QueryOperation<FakeItemWithIndices> queryToTest = QueryOperation.create(QueryEnhancedRequest.builder().queryConditional(keyEqualTo(k -> k.partitionValue(fakeItem.getGsiId()))).build());
QueryRequest queryRequest = queryToTest.generateRequest(FakeItemWithIndices.getTableSchema(), GSI_1_CONTEXT, null);
assertThat(queryRequest.indexName(), is("gsi_1"));
}
Aggregations