Search in sources :

Example 1 with FakeItemWithIndices

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()));
}
Also used : QueryRequest(software.amazon.awssdk.services.dynamodb.model.QueryRequest) FakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices) FakeItemWithIndices.createUniqueFakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices.createUniqueFakeItemWithIndices) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with FakeItemWithIndices

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"));
}
Also used : ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) FakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices) Test(org.junit.Test)

Example 3 with FakeItemWithIndices

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()))));
}
Also used : FakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Test(org.junit.Test)

Example 4 with FakeItemWithIndices

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()))));
}
Also used : FakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices) Key(software.amazon.awssdk.enhanced.dynamodb.Key) Test(org.junit.Test)

Example 5 with FakeItemWithIndices

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"));
}
Also used : FakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices) Arrays(java.util.Arrays) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Expression(software.amazon.awssdk.enhanced.dynamodb.Expression) Map(java.util.Map) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) SdkIterable(software.amazon.awssdk.core.pagination.sync.SdkIterable) Set(java.util.Set) ReadModification(software.amazon.awssdk.enhanced.dynamodb.extensions.ReadModification) QueryResponse(software.amazon.awssdk.services.dynamodb.model.QueryResponse) QueryPublisher(software.amazon.awssdk.services.dynamodb.paginators.QueryPublisher) Collectors(java.util.stream.Collectors) DefaultDynamoDbExtensionContext(software.amazon.awssdk.enhanced.dynamodb.internal.extensions.DefaultDynamoDbExtensionContext) List(java.util.List) DynamoDbEnhancedClientExtension(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientExtension) TableMetadata(software.amazon.awssdk.enhanced.dynamodb.TableMetadata) 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) QueryEnhancedRequest(software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest) QueryIterable(software.amazon.awssdk.services.dynamodb.paginators.QueryIterable) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) QueryRequest(software.amazon.awssdk.services.dynamodb.model.QueryRequest) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) FakeItemWithSort(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithSort) HashSet(java.util.HashSet) FakeItem.createUniqueFakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem.createUniqueFakeItem) Collections.singletonMap(java.util.Collections.singletonMap) FakeItem(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) QueryConditional.keyEqualTo(software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional.keyEqualTo) FakeItemWithIndices.createUniqueFakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices.createUniqueFakeItemWithIndices) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryConditional(software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional) InOrder(org.mockito.InOrder) Test(org.junit.Test) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) OperationContext(software.amazon.awssdk.enhanced.dynamodb.OperationContext) Page(software.amazon.awssdk.enhanced.dynamodb.model.Page) DynamoDbExtensionContext(software.amazon.awssdk.enhanced.dynamodb.DynamoDbExtensionContext) AttributeValues.stringValue(software.amazon.awssdk.enhanced.dynamodb.internal.AttributeValues.stringValue) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryRequest(software.amazon.awssdk.services.dynamodb.model.QueryRequest) FakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices) FakeItemWithIndices.createUniqueFakeItemWithIndices(software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices.createUniqueFakeItemWithIndices) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 FakeItemWithIndices (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItemWithIndices)10 Key (software.amazon.awssdk.enhanced.dynamodb.Key)4 CreateTableRequest (software.amazon.awssdk.services.dynamodb.model.CreateTableRequest)3 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.is (org.hamcrest.Matchers.is)2 RunWith (org.junit.runner.RunWith)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Mock (org.mockito.Mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)2 OperationContext (software.amazon.awssdk.enhanced.dynamodb.OperationContext)2 TableMetadata (software.amazon.awssdk.enhanced.dynamodb.TableMetadata)2 FakeItem (software.amazon.awssdk.enhanced.dynamodb.functionaltests.models.FakeItem)2 EnhancedGlobalSecondaryIndex (software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex)2