use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method getSurveyIncludeElementsByIdentifer.
@Test
public void getSurveyIncludeElementsByIdentifer() {
DynamoSurvey survey = new DynamoSurvey();
survey.setAppId(TEST_APP_ID);
survey.setGuid(GUID);
survey.setIdentifier(SURVEY_ID);
survey.setCreatedOn(CREATED_ON);
mockSurveyMapper(survey);
// There is a question that should be retrieved.
DynamoSurveyQuestion element = new DynamoSurveyQuestion();
element.setType(SurveyElementConstants.SURVEY_QUESTION_TYPE);
element.setUiHint(UIHint.BLOODPRESSURE);
element.setConstraints(new BloodPressureConstraints());
when(mockSurveyElementMapper.queryPage(eq(DynamoSurveyElement.class), any())).thenReturn(mockElementResultsPage);
when(mockElementResultsPage.getResults()).thenReturn(ImmutableList.of(element));
Survey result = dao.getSurvey(TEST_APP_ID, SURVEY_IDENTIFIER_KEYS, true);
assertSame(result, survey);
assertEquals(result.getElements().size(), 1);
verify(mockSurveyMapper).queryPage(eq(DynamoSurvey.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoSurvey> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getAppId(), TEST_APP_ID);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("identifier");
assertEquals(rangeKeyCondition.getComparisonOperator(), EQ.name());
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getS(), SURVEY_ID);
assertEquals(query.getQueryFilter().size(), 1);
verifyCreatedOnQueryCondition(query);
verify(mockSurveyElementMapper).queryPage(eq(DynamoSurveyElement.class), elementQueryCaptor.capture());
DynamoDBQueryExpression<DynamoSurveyElement> elementQuery = elementQueryCaptor.getValue();
assertEquals(elementQuery.getHashKeyValues().getSurveyCompoundKey(), GUID + ":" + CREATED_ON);
}
use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method getSurveyMostRecentVersionByIdentifier.
@Test
public void getSurveyMostRecentVersionByIdentifier() {
// Survey 1A
DynamoSurvey survey1A = new DynamoSurvey();
survey1A.setGuid(GUID);
survey1A.setIdentifier(SURVEY_ID);
survey1A.setCreatedOn(CREATED_ON);
// Survey 1B
DynamoSurvey survey1B = new DynamoSurvey();
survey1B.setGuid(GUID);
survey1B.setIdentifier(SURVEY_ID);
survey1B.setCreatedOn(CREATED_ON - 2000L);
mockSurveyMapper(survey1B, survey1A);
mockSurveyElementMapper();
Survey survey = dao.getSurveyMostRecentVersion(TEST_APP_ID, SURVEY_IDENTIFIER);
assertSame(survey, survey1A);
verify(mockSurveyMapper).queryPage(eq(DynamoSurvey.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoSurvey> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getAppId(), TEST_APP_ID);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("identifier");
assertEquals(rangeKeyCondition.getComparisonOperator(), EQ.name());
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getS(), SURVEY_ID);
assertEquals(query.getQueryFilter().size(), 1);
verifyIsDeletedQueryCondition(query);
}
use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoSurveyDaoTest method getSurveyAllVersionsIncludeDeletedByIdentifier.
@Test
public void getSurveyAllVersionsIncludeDeletedByIdentifier() {
// Survey 1A
DynamoSurvey survey1A = new DynamoSurvey();
survey1A.setGuid(GUID);
survey1A.setIdentifier(SURVEY_ID);
survey1A.setCreatedOn(CREATED_ON);
survey1A.setDeleted(true);
// Survey 1B
DynamoSurvey survey1B = new DynamoSurvey();
survey1B.setGuid(GUID);
survey1B.setIdentifier(SURVEY_ID);
survey1B.setCreatedOn(CREATED_ON - 2000L);
survey1B.setDeleted(true);
mockSurveyMapper(survey1B, survey1A);
mockSurveyElementMapper();
List<Survey> results = dao.getSurveyAllVersions(TEST_APP_ID, SURVEY_IDENTIFIER, true);
assertEquals(results, ImmutableList.of(survey1A, survey1B));
verify(mockSurveyMapper).queryPage(eq(DynamoSurvey.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoSurvey> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getAppId(), TEST_APP_ID);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("identifier");
assertEquals(rangeKeyCondition.getComparisonOperator(), EQ.name());
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getS(), SURVEY_ID);
assertNull(query.getQueryFilter());
}
use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoHealthDataDaoTest method getRecordsByHealthCodeCreatedOnSchemaId.
@Test
public void getRecordsByHealthCodeCreatedOnSchemaId() {
// Mock mapper with record.
DynamoHealthDataRecord record = new DynamoHealthDataRecord();
record.setHealthCode(TEST_HEALTH_CODE);
record.setId("test ID");
record.setCreatedOn(TEST_CREATED_ON);
record.setSchemaId(TEST_SCHEMA_ID);
QueryResultPage<DynamoHealthDataRecord> resultPage = new QueryResultPage<>();
resultPage.setResults(ImmutableList.of(record));
DynamoDBMapper mockMapper = mock(DynamoDBMapper.class);
when(mockMapper.queryPage(eq(DynamoHealthDataRecord.class), any())).thenReturn(resultPage);
DynamoHealthDataDao dao = new DynamoHealthDataDao();
dao.setMapper(mockMapper);
// Execute and validate.
List<HealthDataRecord> retVal = dao.getRecordsByHealthCodeCreatedOn(TEST_HEALTH_CODE, TEST_CREATED_ON, TEST_CREATED_ON_END);
assertEquals(retVal.size(), 1);
assertSame(retVal.get(0), record);
// Verify query.
ArgumentCaptor<DynamoDBQueryExpression> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
verify(mockMapper).queryPage(eq(DynamoHealthDataRecord.class), queryCaptor.capture());
DynamoDBQueryExpression<DynamoHealthDataRecord> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getHealthCode(), TEST_HEALTH_CODE);
assertFalse(query.isConsistentRead());
assertEquals(query.getLimit().intValue(), BridgeConstants.DUPE_RECORDS_MAX_COUNT);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("createdOn");
assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.BETWEEN.toString());
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getN(), String.valueOf(TEST_CREATED_ON));
assertEquals(rangeKeyCondition.getAttributeValueList().get(1).getN(), String.valueOf(TEST_CREATED_ON_END));
}
use of com.amazonaws.services.dynamodbv2.document.RangeKeyCondition in project BridgeServer2 by Sage-Bionetworks.
the class DynamoHealthDataDocumentationDaoTest method getDocumentationForParentId.
@SuppressWarnings("unchecked")
@Test
public void getDocumentationForParentId() {
// mock dependencies
DynamoHealthDataDocumentation doc = new DynamoHealthDataDocumentation();
doReturn(ImmutableList.of(doc)).when(dao).queryHelper(any());
// execute
ForwardCursorPagedResourceList<HealthDataDocumentation> resultList = dao.getDocumentationForParentId(TEST_APP_ID, API_DEFAULT_PAGE_SIZE, OFFSET_KEY);
assertEquals(resultList.getItems().size(), 1);
assertSame(resultList.getItems().get(0), doc);
assertNull(resultList.getNextPageOffsetKey());
// validate
ArgumentCaptor<DynamoDBQueryExpression<DynamoHealthDataDocumentation>> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
verify(dao).queryHelper(queryCaptor.capture());
DynamoDBQueryExpression<DynamoHealthDataDocumentation> query = queryCaptor.getValue();
assertEquals(query.getHashKeyValues().getParentId(), TEST_APP_ID);
assertEquals(query.getLimit().intValue(), API_DEFAULT_PAGE_SIZE + 1);
assertEquals(query.getRangeKeyConditions().size(), 1);
Condition rangeKeyCondition = query.getRangeKeyConditions().get("identifier");
assertEquals(rangeKeyCondition.getComparisonOperator(), ComparisonOperator.GE.toString());
assertEquals(rangeKeyCondition.getAttributeValueList().size(), 1);
assertEquals(rangeKeyCondition.getAttributeValueList().get(0).getS(), OFFSET_KEY);
}
Aggregations