use of org.sagebionetworks.bridge.models.notifications.NotificationMessage in project BridgeServer2 by Sage-Bionetworks.
the class NotificationsServiceTest method sendNotificationNoRegistration.
@Test
public void sendNotificationNoRegistration() {
doReturn(Lists.newArrayList()).when(mockRegistrationDao).listRegistrations(HEALTH_CODE);
NotificationMessage message = getNotificationMessage();
try {
service.sendNotificationToUser(TEST_APP_ID, HEALTH_CODE, message);
fail("Should have thrown exception.");
} catch (BadRequestException e) {
assertEquals(e.getMessage(), "Participant has not registered to receive push notifications.");
}
}
use of org.sagebionetworks.bridge.models.notifications.NotificationMessage in project BridgeServer2 by Sage-Bionetworks.
the class NotificationsServiceTest method sendNotificationOK.
@Test
public void sendNotificationOK() {
NotificationRegistration registration = getNotificationRegistration();
registration.setEndpoint("endpointARN");
List<NotificationRegistration> list = Lists.newArrayList(registration);
doReturn(list).when(mockRegistrationDao).listRegistrations(HEALTH_CODE);
doReturn(mockPublishResult).when(mockSnsClient).publish(any());
NotificationMessage message = getNotificationMessage();
service.sendNotificationToUser(TEST_APP_ID, HEALTH_CODE, message);
verify(mockSnsClient).publish(requestCaptor.capture());
PublishRequest request = requestCaptor.getValue();
assertEquals(request.getSubject(), message.getSubject());
assertEquals(request.getMessage(), message.getMessage());
assertEquals(request.getTargetArn(), "endpointARN");
}
use of org.sagebionetworks.bridge.models.notifications.NotificationMessage in project BridgeServer2 by Sage-Bionetworks.
the class NotificationsServiceTest method sendNotificationWithPartialErrors.
// Publish to two devices, where one device fails but the other sends to the user.
// Method succeeds but returns the GUID of the failed call for reporting back to the user.
@Test
public void sendNotificationWithPartialErrors() {
NotificationRegistration reg1 = getNotificationRegistration();
NotificationRegistration reg2 = getNotificationRegistration();
reg2.setGuid("registrationGuid2");
List<NotificationRegistration> list = Lists.newArrayList(reg1, reg2);
doReturn(list).when(mockRegistrationDao).listRegistrations(HEALTH_CODE);
when(mockSnsClient.publish(any())).thenReturn(mockPublishResult).thenThrow(new InvalidParameterException("bad parameter"));
NotificationMessage message = getNotificationMessage();
Set<String> erroredNotifications = service.sendNotificationToUser(TEST_APP_ID, HEALTH_CODE, message);
assertEquals(erroredNotifications.size(), 1);
assertEquals(Iterables.getFirst(erroredNotifications, null), "registrationGuid2");
}
use of org.sagebionetworks.bridge.models.notifications.NotificationMessage in project BridgeServer2 by Sage-Bionetworks.
the class NotificationsServiceTest method sendNotificationAmazonExceptionConverted.
// Publish to two devices, where all the devices fail. This should throw an exception as nothing
// was successfully returned to the user.
@Test(expectedExceptions = BadRequestException.class)
public void sendNotificationAmazonExceptionConverted() {
NotificationRegistration reg1 = getNotificationRegistration();
NotificationRegistration reg2 = getNotificationRegistration();
// This has to be different
reg2.setGuid("registrationGuid2");
List<NotificationRegistration> list = Lists.newArrayList(reg1, reg2);
doReturn(list).when(mockRegistrationDao).listRegistrations(HEALTH_CODE);
doThrow(new InvalidParameterException("bad parameter")).when(mockSnsClient).publish(any());
NotificationMessage message = getNotificationMessage();
service.sendNotificationToUser(TEST_APP_ID, HEALTH_CODE, message);
}
use of org.sagebionetworks.bridge.models.notifications.NotificationMessage in project BridgeServer2 by Sage-Bionetworks.
the class NotificationTopicServiceTest method sendNotification.
@Test
public void sendNotification() {
NotificationMessage message = TestUtils.getNotificationMessage();
NotificationTopic topic = getNotificationTopic();
topic.setTopicARN("topicARN");
doReturn(topic).when(mockTopicDao).getTopic(TEST_APP_ID, "ABC-DEF");
service.sendNotification(TEST_APP_ID, "ABC-DEF", message);
verify(mockSnsClient).publish(publishRequestCaptor.capture());
PublishRequest request = publishRequestCaptor.getValue();
assertEquals(request.getSubject(), "a subject");
assertEquals(request.getMessage(), "a message");
assertEquals(request.getTopicArn(), "topicARN");
}
Aggregations