Search in sources :

Example 11 with SmsMessage

use of org.sagebionetworks.bridge.models.sms.SmsMessage in project BridgeServer2 by Sage-Bionetworks.

the class SmsServiceTest method getMostRecentMessage_NormalCase.

@Test
public void getMostRecentMessage_NormalCase() {
    SmsMessage daoOutput = makeValidSmsMessage();
    when(mockMessageDao.getMostRecentMessage(PHONE_NUMBER)).thenReturn(daoOutput);
    SmsMessage svcOutput = svc.getMostRecentMessage(PHONE_NUMBER);
    assertSame(svcOutput, daoOutput);
}
Also used : SmsMessage(org.sagebionetworks.bridge.models.sms.SmsMessage) Test(org.testng.annotations.Test)

Example 12 with SmsMessage

use of org.sagebionetworks.bridge.models.sms.SmsMessage in project BridgeServer2 by Sage-Bionetworks.

the class DynamoSmsMessageDaoTest method getMostRecentMessage.

@Test
public void getMostRecentMessage() {
    // Mock mapper.
    DynamoSmsMessage mapperOutput = new DynamoSmsMessage();
    QueryResultPage<DynamoSmsMessage> resultPage = new QueryResultPage<>();
    resultPage.setResults(ImmutableList.of(mapperOutput));
    when(mockMapper.queryPage(eq(DynamoSmsMessage.class), any())).thenReturn(resultPage);
    // Execute and validate output matches.
    SmsMessage daoOutput = dao.getMostRecentMessage(PHONE_NUMBER);
    assertSame(daoOutput, mapperOutput);
    // Verify query.
    ArgumentCaptor<DynamoDBQueryExpression> queryCaptor = ArgumentCaptor.forClass(DynamoDBQueryExpression.class);
    verify(mockMapper).queryPage(eq(DynamoSmsMessage.class), queryCaptor.capture());
    DynamoDBQueryExpression<DynamoSmsMessage> query = queryCaptor.getValue();
    assertEquals(query.getHashKeyValues().getPhoneNumber(), PHONE_NUMBER);
    assertFalse(query.isScanIndexForward());
    assertEquals(query.getLimit().intValue(), 1);
}
Also used : SmsMessage(org.sagebionetworks.bridge.models.sms.SmsMessage) DynamoDBQueryExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression) QueryResultPage(com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage) Test(org.testng.annotations.Test)

Example 13 with SmsMessage

use of org.sagebionetworks.bridge.models.sms.SmsMessage in project BridgeServer2 by Sage-Bionetworks.

the class DynamoSmsMessageDaoTest method getMostRecentMessage_EmptyList.

@Test
public void getMostRecentMessage_EmptyList() {
    // Mock mapper.
    QueryResultPage<DynamoSmsMessage> resultPage = new QueryResultPage<>();
    resultPage.setResults(ImmutableList.of());
    when(mockMapper.queryPage(eq(DynamoSmsMessage.class), any())).thenReturn(resultPage);
    // Execute and validate.
    SmsMessage daoOutput = dao.getMostRecentMessage(PHONE_NUMBER);
    assertNull(daoOutput);
// Query is already verified in previous test.
}
Also used : SmsMessage(org.sagebionetworks.bridge.models.sms.SmsMessage) QueryResultPage(com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage) Test(org.testng.annotations.Test)

Example 14 with SmsMessage

use of org.sagebionetworks.bridge.models.sms.SmsMessage in project BridgeServer2 by Sage-Bionetworks.

the class DynamoSmsMessageTest method serialize.

@Test
public void serialize() throws Exception {
    // Start with JSON.
    String jsonText = "{\n" + "   \"phoneNumber\":\"" + PHONE_NUMBER + "\",\n" + "   \"sentOn\":\"" + SENT_ON_STRING + "\",\n" + "   \"healthCode\":\"" + HEALTH_CODE + "\",\n" + "   \"messageBody\":\"" + MESSAGE_BODY + "\",\n" + "   \"messageId\":\"" + MESSAGE_ID + "\",\n" + "   \"smsType\":\"" + SmsType.PROMOTIONAL.getValue().toLowerCase() + "\",\n" + "   \"appId\":\"" + TEST_APP_ID + "\"\n" + "}";
    // Convert to POJO.
    SmsMessage smsMessage = BridgeObjectMapper.get().readValue(jsonText, SmsMessage.class);
    assertEquals(smsMessage.getPhoneNumber(), PHONE_NUMBER);
    assertEquals(smsMessage.getSentOn(), SENT_ON_MILLIS);
    assertEquals(smsMessage.getHealthCode(), HEALTH_CODE);
    assertEquals(smsMessage.getMessageBody(), MESSAGE_BODY);
    assertEquals(smsMessage.getMessageId(), MESSAGE_ID);
    assertEquals(smsMessage.getSmsType(), SmsType.PROMOTIONAL);
    assertEquals(smsMessage.getAppId(), TEST_APP_ID);
    // Convert back to JSON node.
    JsonNode jsonNode = BridgeObjectMapper.get().convertValue(smsMessage, JsonNode.class);
    assertEquals(jsonNode.get("phoneNumber").textValue(), PHONE_NUMBER);
    assertEquals(jsonNode.get("sentOn").textValue(), SENT_ON_STRING);
    assertEquals(jsonNode.get("healthCode").textValue(), HEALTH_CODE);
    assertEquals(jsonNode.get("messageBody").textValue(), MESSAGE_BODY);
    assertEquals(jsonNode.get("messageId").textValue(), MESSAGE_ID);
    assertEquals(jsonNode.get("smsType").textValue(), SmsType.PROMOTIONAL.getValue().toLowerCase());
    assertEquals(jsonNode.get("appId").textValue(), TEST_APP_ID);
}
Also used : SmsMessage(org.sagebionetworks.bridge.models.sms.SmsMessage) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 15 with SmsMessage

use of org.sagebionetworks.bridge.models.sms.SmsMessage in project BridgeServer2 by Sage-Bionetworks.

the class SmsServiceTest method makeValidSmsMessage.

private static SmsMessage makeValidSmsMessage() {
    SmsMessage message = SmsMessage.create();
    message.setPhoneNumber(PHONE_NUMBER);
    message.setSentOn(SENT_ON);
    message.setMessageId(MESSAGE_ID);
    message.setMessageBody(MESSAGE_BODY);
    message.setSmsType(SmsType.PROMOTIONAL);
    message.setAppId(TEST_APP_ID);
    return message;
}
Also used : SmsMessage(org.sagebionetworks.bridge.models.sms.SmsMessage)

Aggregations

SmsMessage (org.sagebionetworks.bridge.models.sms.SmsMessage)24 Test (org.testng.annotations.Test)20 QueryResultPage (com.amazonaws.services.dynamodbv2.datamodeling.QueryResultPage)2 DynamoDBQueryExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression)1 PublishResult (com.amazonaws.services.sns.model.PublishResult)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 DateTime (org.joda.time.DateTime)1 BridgeServiceException (org.sagebionetworks.bridge.exceptions.BridgeServiceException)1 Phone (org.sagebionetworks.bridge.models.accounts.Phone)1 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)1 App (org.sagebionetworks.bridge.models.apps.App)1 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)1 UploadValidationException (org.sagebionetworks.bridge.upload.UploadValidationException)1