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));
}
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));
}
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));
}
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));
}
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");
}
Aggregations