Search in sources :

Example 1 with HealthDataRecordEx3

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));
}
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 HealthDataRecordEx3

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));
}
Also used : HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 3 with HealthDataRecordEx3

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));
}
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 4 with HealthDataRecordEx3

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);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3) Test(org.testng.annotations.Test)

Example 5 with HealthDataRecordEx3

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;
}
Also used : HealthDataRecordEx3(org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3)

Aggregations

HealthDataRecordEx3 (org.sagebionetworks.bridge.models.healthdata.HealthDataRecordEx3)35 Test (org.testng.annotations.Test)28 App (org.sagebionetworks.bridge.models.apps.App)6 Condition (com.amazonaws.services.dynamodbv2.model.Condition)4 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)4 Account (org.sagebionetworks.bridge.models.accounts.Account)4 Upload (org.sagebionetworks.bridge.models.upload.Upload)4 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)3 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)3 Metrics (org.sagebionetworks.bridge.models.Metrics)3 SendMessageResult (com.amazonaws.services.sqs.model.SendMessageResult)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ParticipantVersion (org.sagebionetworks.bridge.models.accounts.ParticipantVersion)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 RequestContext (org.sagebionetworks.bridge.RequestContext)1 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)1 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)1