Search in sources :

Example 11 with StatusMessage

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"));
}
Also used : DateTime(org.joda.time.DateTime) StatusMessage(org.motechproject.admin.domain.StatusMessage) Test(org.junit.Test)

Example 12 with StatusMessage

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");
}
Also used : NotificationRule(org.motechproject.admin.domain.NotificationRule) MotechEvent(org.motechproject.event.MotechEvent) StatusMessage(org.motechproject.admin.domain.StatusMessage) Test(org.junit.Test)

Aggregations

StatusMessage (org.motechproject.admin.domain.StatusMessage)12 Test (org.junit.Test)8 Transactional (org.springframework.transaction.annotation.Transactional)3 DateTime (org.joda.time.DateTime)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 NotificationRule (org.motechproject.admin.domain.NotificationRule)1 Level (org.motechproject.admin.messages.Level)1 MotechEvent (org.motechproject.event.MotechEvent)1