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