Search in sources :

Example 1 with RangeKeyCondition

use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForApp.

@Test
public void getRecordsForApp() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    ForwardCursorPagedResourceList<HealthDataRecordEx3> resultList = dao.getRecordsForApp(TestConstants.TEST_APP_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, null);
    assertEquals(resultList.getItems().size(), 1);
    assertSame(resultList.getItems().get(0), record);
    assertNull(resultList.getNextPageOffsetKey());
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    assertFalse(query.isConsistentRead());
    assertEquals(query.getIndexName(), DynamoHealthDataRecordEx3.APPID_CREATEDON_INDEX);
    assertEquals(query.getHashKeyValues().getAppId(), TestConstants.TEST_APP_ID);
    assertEquals(query.getLimit().intValue(), BridgeConstants.API_DEFAULT_PAGE_SIZE + 1);
    assertEquals(query.getRangeKeyConditions().size(), 1);
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.BETWEEN.toString());
    assertEquals(rangeKeyCondition.getAttributeValueList().size(), 2);
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
    assertEquals(rangeKeyCondition.getAttributeValueList().get(1).getN(), String.valueOf(CREATED_ON_END));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 2 with RangeKeyCondition

use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForHealthCode.

@Test
public void getRecordsForHealthCode() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    ForwardCursorPagedResourceList<HealthDataRecordEx3> resultList = dao.getRecordsForHealthCode(TestConstants.HEALTH_CODE, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, null);
    assertEquals(resultList.getItems().size(), 1);
    assertSame(resultList.getItems().get(0), record);
    assertNull(resultList.getNextPageOffsetKey());
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    assertFalse(query.isConsistentRead());
    assertEquals(query.getIndexName(), DynamoHealthDataRecordEx3.HEALTHCODE_CREATEDON_INDEX);
    assertEquals(query.getHashKeyValues().getHealthCode(), TestConstants.HEALTH_CODE);
    assertEquals(query.getLimit().intValue(), BridgeConstants.API_DEFAULT_PAGE_SIZE + 1);
    assertEquals(query.getRangeKeyConditions().size(), 1);
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.BETWEEN.toString());
    assertEquals(rangeKeyCondition.getAttributeValueList().size(), 2);
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
    assertEquals(rangeKeyCondition.getAttributeValueList().get(1).getN(), String.valueOf(CREATED_ON_END));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 3 with RangeKeyCondition

use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForHealthCode_offsetKeyAfterCreatedOnStart.

@Test
public void getRecordsForHealthCode_offsetKeyAfterCreatedOnStart() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    dao.getRecordsForHealthCode(TestConstants.HEALTH_CODE, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, String.valueOf(CREATED_ON_START + 10000));
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START + 10000));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) Test(org.testng.annotations.Test)

Example 4 with RangeKeyCondition

use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoHealthDataEx3DaoTest method getRecordsForHealthCode_offsetKeyBeforeCreatedOnStart.

@Test
public void getRecordsForHealthCode_offsetKeyBeforeCreatedOnStart() {
    // Mock dependencies.
    DynamoHealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
    doReturn(ImmutableList.of(record)).when(dao).queryHelper(any());
    // Execute.
    dao.getRecordsForHealthCode(TestConstants.HEALTH_CODE, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, String.valueOf(CREATED_ON_START - 10000));
    // Validate.
    ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataRecordEx3>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(dao).queryHelper(queryCaptor.capture());
    DynamoDBQueryExpression<DynamoHealthDataRecordEx3> query = queryCaptor.getValue();
    Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
    assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(CREATED_ON_START));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) Test(org.testng.annotations.Test)

Example 5 with RangeKeyCondition

use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.

the class DynamoIndexHelperTest method test.

@Test
public void test() {
    RangeKeyCondition rangeKeyCondition = new RangeKeyCondition("antwerp").eq("belgium");
    mockResultsOfQuery(rangeKeyCondition);
    // execute query keys and validate
    List<Thing> keyList = helper.queryKeys(Thing.class, "test key", "test value", rangeKeyCondition);
    validateKeyObjects(keyList);
    // execute
    List<Thing> resultList = helper.query(Thing.class, "test key", "test value", rangeKeyCondition);
    // Validate intermediate "key objects". This is a List<Object>, but because of type erasure, this should work,
    // at least in the test context.
    validateKeyObjects(arg.getValue());
    // Validate final results. Because of wonkiness with maps and ordering, we'll convert the Things into a map and
    // validate the map.
    assertEquals(resultList.size(), 4);
    Map<String, String> thingMap = new HashMap<>();
    for (Thing oneThing : resultList) {
        thingMap.put(oneThing.key, oneThing.value);
    }
    assertEquals(thingMap.size(), 4);
    assertEquals(thingMap.get("foo key"), "foo value");
    assertEquals(thingMap.get("bar key"), "bar value");
    assertEquals(thingMap.get("asdf key"), "asdf value");
    assertEquals(thingMap.get("jkl; key"), "jkl; value");
}
Also used : RangeKeyCondition(com.amazonaws.services.dynamodbv2.document.RangeKeyCondition) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

Condition (com.amazonaws.services.dynamodbv2.model.Condition)17 Test (org.testng.annotations.Test)14 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)10 Survey (org.sagebionetworks.bridge.models.surveys.Survey)5 Item (com.amazonaws.services.dynamodbv2.document.Item)4 RangeKeyCondition (com.amazonaws.services.dynamodbv2.document.RangeKeyCondition)4 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 HealthDataRecordEx3 (org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)3 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)3 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)2 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)2 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 ResourceList (org.sagebionetworks.bridge.models.ResourceList)2 ScheduledActivity (org.sagebionetworks.bridge.models.schedules.ScheduledActivity)2 QueryResultPage (com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage)1