Search in sources :

Example 6 with StatusMessage

use of org.motechproject.admin.domain.StatusMessage in project motech by motech.

the class EmailNotifierTest method shouldSendNotification.

@Test
public void shouldSendNotification() throws Exception {
    String text = "Mail msg";
    DateTime datetime = new DateTime(2010, 12, 20, 10, 50);
    String moduleName = "admin";
    StatusMessage statusMessage = statusMessage(text, datetime, moduleName);
    when(motechSettings.getServerUrl()).thenReturn("http://serverurl");
    when(motechSettings.getServerHost()).thenReturn("serverurl");
    EmailNotifier emailNotifierSpy = spy(emailNotifier);
    ArgumentCaptor<Map> velocityArgumentCaptor = ArgumentCaptor.forClass(Map.class);
    doReturn(text).when(emailNotifierSpy).mergeTemplateIntoString(velocityArgumentCaptor.capture());
    emailNotifierSpy.send(statusMessage, "recipients");
    assertEquals(text, velocityArgumentCaptor.getValue().get("msg"));
    assertEquals(Level.WARN, velocityArgumentCaptor.getValue().get("level"));
    String msgLink = "http://serverurl/module/server/?moduleName=admin#/messages";
    assertEquals(msgLink, velocityArgumentCaptor.getValue().get("msgLink"));
    Assert.assertTrue(velocityArgumentCaptor.getValue().get("dateTime").toString().matches("^(12[./]20|20[./]12)[./]10 10:50(| AM)$"));
    assertEquals(moduleName, velocityArgumentCaptor.getValue().get("module"));
    Mockito.verify(emailSenderService).send("noreply@serverurl", "recipients", "WARN notification raised in Motech", "Mail msg");
}
Also used : Map(java.util.Map) DateTime(org.joda.time.DateTime) StatusMessage(org.motechproject.admin.domain.StatusMessage) Test(org.junit.Test)

Example 7 with StatusMessage

use of org.motechproject.admin.domain.StatusMessage in project motech by motech.

the class EmailNotifierTest method statusMessage.

private StatusMessage statusMessage(String text, DateTime datetime, String moduleName) {
    StatusMessage statusMessage = new StatusMessage(text, moduleName, Level.WARN);
    statusMessage.setDate(datetime);
    return statusMessage;
}
Also used : StatusMessage(org.motechproject.admin.domain.StatusMessage)

Example 8 with StatusMessage

use of org.motechproject.admin.domain.StatusMessage in project motech by motech.

the class StatusMessageServiceImpl method postMessage.

@Override
@Transactional
public void postMessage(String text, String moduleName, Level level) {
    StatusMessage message = new StatusMessage(text, moduleName, level, defaultTimeout());
    postMessage(message);
}
Also used : StatusMessage(org.motechproject.admin.domain.StatusMessage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with StatusMessage

use of org.motechproject.admin.domain.StatusMessage in project motech by motech.

the class StatusMessageServiceImpl method postMessage.

@Override
@Transactional
public void postMessage(String text, String moduleName, Level level, DateTime timeout) {
    StatusMessage message = new StatusMessage(text, moduleName, level, timeout);
    postMessage(message);
}
Also used : StatusMessage(org.motechproject.admin.domain.StatusMessage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with StatusMessage

use of org.motechproject.admin.domain.StatusMessage in project motech by motech.

the class StatusMessagesDataServiceBundleIT method shouldPerformCrudOperations.

@Test
public void shouldPerformCrudOperations() {
    StatusMessage statusMessage1 = new StatusMessage("test", "module", Level.ERROR);
    StatusMessage statusMessage2 = new StatusMessage("test2", "module2", Level.INFO);
    dataService.create(statusMessage1);
    dataService.create(statusMessage2);
    List<StatusMessage> result = dataService.retrieveAll();
    List<String> actual = extract(result, on(StatusMessage.class).getText());
    assertThat(actual, hasItems("test", "test2"));
    actual = extract(result, on(StatusMessage.class).getModuleName());
    assertThat(actual, hasItems("module", "module2"));
    List<Level> actualLevels = extract(result, on(StatusMessage.class).getLevel());
    assertThat(actualLevels, hasItems(Level.ERROR, Level.INFO));
    statusMessage1.setText("test_changed");
    dataService.update(statusMessage1);
    dataService.delete(statusMessage2);
    result = dataService.retrieveAll();
    assertEquals(asList("test_changed"), extract(result, on(StatusMessage.class).getText()));
    assertEquals(asList("module"), extract(result, on(StatusMessage.class).getModuleName()));
    assertEquals(asList(Level.ERROR), extract(result, on(StatusMessage.class).getLevel()));
}
Also used : Level(org.motechproject.admin.messages.Level) 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