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");
}
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;
}
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);
}
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);
}
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()));
}
Aggregations