use of org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3 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 org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3 in project BridgeServer2 by Sage-Bionetworks.
the class DynamoHealthDataEx3DaoTest method createOrUpdateRecord_UpdateRecord.
@Test
public void createOrUpdateRecord_UpdateRecord() {
HealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
record.setId(RECORD_ID);
HealthDataRecordEx3 returnedRecord = dao.createOrUpdateRecord(record);
assertSame(returnedRecord, record);
assertEquals(record.getId(), RECORD_ID);
verify(mockMapper).save(same(record));
}
use of org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3 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 org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3 in project BridgeServer2 by Sage-Bionetworks.
the class DynamoHealthDataRecordEx3Test method jsonSerialization.
@Test
public void jsonSerialization() throws Exception {
// Make record.
HealthDataRecordEx3 record = new DynamoHealthDataRecordEx3();
record.setId(RECORD_ID);
record.setAppId(TestConstants.TEST_APP_ID);
record.setStudyId(STUDY_ID);
record.setHealthCode(TestConstants.HEALTH_CODE);
record.setParticipantVersion(PARTICIPANT_VERSION);
record.setCreatedOn(TestConstants.CREATED_ON.getMillis());
record.setClientInfo(CLIENT_INFO_STRING);
record.setExported(true);
record.setExportedOn(TestConstants.EXPORTED_ON.getMillis());
record.setMetadata(METADATA_MAP);
record.setSharingScope(SharingScope.SPONSORS_AND_PARTNERS);
record.setVersion(VERSION);
// Convert to JsonNode.
JsonNode jsonNode = BridgeObjectMapper.get().convertValue(record, JsonNode.class);
assertEquals(jsonNode.size(), 13);
assertEquals(jsonNode.get("id").textValue(), RECORD_ID);
assertEquals(jsonNode.get("appId").textValue(), TestConstants.TEST_APP_ID);
assertEquals(jsonNode.get("studyId").textValue(), STUDY_ID);
assertEquals(jsonNode.get("healthCode").textValue(), TestConstants.HEALTH_CODE);
assertEquals(jsonNode.get("participantVersion").intValue(), PARTICIPANT_VERSION);
assertEquals(jsonNode.get("createdOn").textValue(), TestConstants.CREATED_ON.toString());
assertEquals(jsonNode.get("clientInfo").textValue(), CLIENT_INFO_STRING);
assertTrue(jsonNode.get("exported").booleanValue());
assertEquals(jsonNode.get("exportedOn").textValue(), TestConstants.EXPORTED_ON.toString());
assertEquals(jsonNode.get("sharingScope").textValue(), "sponsors_and_partners");
assertEquals(jsonNode.get("version").longValue(), VERSION);
assertEquals(jsonNode.get("type").textValue(), "HealthDataRecordEx3");
JsonNode metadataMapNode = jsonNode.get("metadata");
assertEquals(metadataMapNode.size(), 1);
assertEquals(metadataMapNode.get("foo").textValue(), "bar");
// Convert back to POJO.
record = BridgeObjectMapper.get().treeToValue(jsonNode, HealthDataRecordEx3.class);
assertEquals(record.getId(), RECORD_ID);
assertEquals(record.getAppId(), TestConstants.TEST_APP_ID);
assertEquals(record.getStudyId(), STUDY_ID);
assertEquals(record.getHealthCode(), TestConstants.HEALTH_CODE);
assertEquals(record.getParticipantVersion().intValue(), PARTICIPANT_VERSION);
assertEquals(record.getCreatedOn().longValue(), TestConstants.CREATED_ON.getMillis());
assertEquals(record.getClientInfo(), CLIENT_INFO_STRING);
assertTrue(record.isExported());
assertEquals(record.getExportedOn().longValue(), TestConstants.EXPORTED_ON.getMillis());
assertEquals(record.getSharingScope(), SharingScope.SPONSORS_AND_PARTNERS);
assertEquals(record.getMetadata(), METADATA_MAP);
assertEquals(record.getVersion().longValue(), VERSION);
}
use of org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3 in project BridgeServer2 by Sage-Bionetworks.
the class HealthDataEx3ServiceTest method makeValidRecord.
private static HealthDataRecordEx3 makeValidRecord() {
HealthDataRecordEx3 record = HealthDataRecordEx3.create();
record.setAppId(TestConstants.TEST_APP_ID);
record.setHealthCode(TestConstants.HEALTH_CODE);
record.setCreatedOn(TestConstants.CREATED_ON.getMillis());
return record;
}
Aggregations