use of org.motechproject.admin.domain.NotificationRule in project motech by motech.
the class StatusMessageServiceTest method shouldSaveNotificationRules.
@Test
public void shouldSaveNotificationRules() {
NotificationRule notificationRule1 = new NotificationRule("rec1", ActionType.EMAIL, Level.CRITICAL, "admin");
NotificationRule notificationRule2 = new NotificationRule("rec2", ActionType.SMS, Level.CRITICAL, "admin");
NotificationRule notificationRule3 = new NotificationRule("rec3", ActionType.SMS, Level.CRITICAL, "admin");
notificationRule2.setId(1L);
notificationRule3.setId(1L);
when(notificationRulesDataService.findById(1L)).thenReturn(notificationRule3);
statusMessageService.saveNotificationRules(asList(notificationRule1, notificationRule2));
ArgumentCaptor<TransactionCallback> transactionCaptor = ArgumentCaptor.forClass(TransactionCallback.class);
verify(notificationRulesDataService, times(2)).doInTransaction(transactionCaptor.capture());
transactionCaptor.getAllValues().get(0).doInTransaction(null);
transactionCaptor.getAllValues().get(1).doInTransaction(null);
ArgumentCaptor<NotificationRule> captor = ArgumentCaptor.forClass(NotificationRule.class);
verify(notificationRulesDataService).create(captor.capture());
assertNull(captor.getValue().getId());
assertEquals("rec1", captor.getValue().getRecipient());
assertEquals(ActionType.EMAIL, captor.getValue().getActionType());
verify(notificationRulesDataService).findById(1L);
verify(notificationRulesDataService).update(captor.capture());
assertEquals(1L, captor.getValue().getId().longValue());
assertEquals("rec2", captor.getValue().getRecipient());
assertEquals(ActionType.SMS, captor.getValue().getActionType());
}
use of org.motechproject.admin.domain.NotificationRule in project motech by motech.
the class StatusMessageServiceTest method shouldSaveANewRule.
@Test
public void shouldSaveANewRule() {
NotificationRule notificationRule = new NotificationRule("rec", ActionType.SMS, Level.CRITICAL, "admin");
statusMessageService.saveRule(notificationRule);
ArgumentCaptor<NotificationRule> captor = ArgumentCaptor.forClass(NotificationRule.class);
verify(notificationRulesDataService).create(captor.capture());
verify(notificationRulesDataService, never()).update(any(NotificationRule.class));
assertNull(captor.getValue().getId());
assertEquals("rec", captor.getValue().getRecipient());
assertEquals(ActionType.SMS, captor.getValue().getActionType());
}
use of org.motechproject.admin.domain.NotificationRule in project motech by motech.
the class StatusMessageServiceTest method shouldSendNotifications.
@Test
public void shouldSendNotifications() throws EmailSendException {
NotificationRule notificationRuleEmail1 = new NotificationRule("e@ma.il", ActionType.EMAIL, Level.CRITICAL, null);
NotificationRule notificationRuleEmail2 = new NotificationRule("e2@ma.il", ActionType.EMAIL, Level.DEBUG, "module");
NotificationRule notificationRuleSms1 = new NotificationRule("1111", ActionType.SMS, Level.CRITICAL, "module");
NotificationRule notificationRuleSms2 = new NotificationRule("2222", ActionType.SMS, Level.INFO, "");
NotificationRule notificationRuleNotCatched = new NotificationRule("3333", ActionType.SMS, Level.CRITICAL, "other-module");
when(notificationRulesDataService.retrieveAll()).thenReturn(asList(notificationRuleEmail1, notificationRuleSms1, notificationRuleSms2, notificationRuleEmail2, notificationRuleNotCatched));
StatusMessage statusMessage = new StatusMessage("text", "module", Level.CRITICAL);
statusMessageService.postMessage(statusMessage);
verify(statusMessagesDataService).create(statusMessage);
verify(notificationRulesDataService).retrieveAll();
verify(emailNotifier).send(statusMessage, "e@ma.il");
verify(emailNotifier).send(statusMessage, "e2@ma.il");
ArgumentCaptor<MotechEvent> captor = ArgumentCaptor.forClass(MotechEvent.class);
verify(eventRelay).sendEventMessage(captor.capture());
assertEquals("send_sms", captor.getValue().getSubject());
assertEquals(asList("1111", "2222"), captor.getValue().getParameters().get("recipients"));
assertEquals("Motech CRITICAL message: [module] text", captor.getValue().getParameters().get("message"));
verify(uiFrameworkService).moduleNeedsAttention("admin", "messages", "");
verify(uiFrameworkService).moduleNeedsAttention("module", "text");
}
use of org.motechproject.admin.domain.NotificationRule in project motech by motech.
the class StatusMessageServiceTest method shouldRemoveANotificationRule.
@Test
public void shouldRemoveANotificationRule() {
NotificationRule notificationRule = mock(NotificationRule.class);
when(notificationRulesDataService.findById(1L)).thenReturn(notificationRule);
statusMessageService.removeNotificationRule(1L);
verify(notificationRulesDataService).delete(notificationRule);
}
use of org.motechproject.admin.domain.NotificationRule in project motech by motech.
the class StatusMessageServiceTest method shouldUpdateAnExistingRule.
@Test
public void shouldUpdateAnExistingRule() {
NotificationRule notificationRule = new NotificationRule("rec", ActionType.SMS, Level.CRITICAL, "admin");
NotificationRule existing = new NotificationRule("rec2", ActionType.EMAIL, Level.CRITICAL, "admin");
notificationRule.setId(1L);
existing.setId(1L);
when(notificationRulesDataService.findById(1L)).thenReturn(existing);
statusMessageService.saveRule(notificationRule);
ArgumentCaptor<NotificationRule> captor = ArgumentCaptor.forClass(NotificationRule.class);
verify(notificationRulesDataService).update(captor.capture());
assertEquals(1L, captor.getValue().getId().longValue());
assertEquals("rec", captor.getValue().getRecipient());
assertEquals(ActionType.SMS, captor.getValue().getActionType());
}
Aggregations