use of org.motechproject.admin.domain.StatusMessage in project motech by motech.
the class StatusMessagesDataServiceBundleIT method shouldRetrieveMessagesInRange.
@Test
public void shouldRetrieveMessagesInRange() {
final DateTime now = DateUtil.now();
StatusMessage inactiveMsg = new StatusMessage("inactive", "inactiveModule", Level.INFO, now.minusDays(1));
StatusMessage activeMsq = new StatusMessage("active", "activeModule", Level.ERROR, now.plusDays(1));
StatusMessage activeMsq2 = new StatusMessage("active2", "activeModule", Level.ERROR, now.plusDays(2));
dataService.create(activeMsq);
dataService.create(activeMsq2);
dataService.create(inactiveMsg);
List<StatusMessage> result = dataService.findByTimeout(new Range<>(now, null));
List<String> actual = extract(result, on(StatusMessage.class).getText());
assertThat(actual, hasItems("active", "active2"));
}
use of org.motechproject.admin.domain.StatusMessage 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");
}
Aggregations