use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManagerTest method testCreateNotificationWithExistingCopyUser.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCreateNotificationWithExistingCopyUser() {
final NotificationMessageVO message = new NotificationMessageVO();
message.setBody(BODY);
message.setSubject(SUBJECT);
message.setParameters(PARAMETERS);
message.setToUser(testUser1.getUserName());
message.setCopyUsers(Collections.singletonList(testUser2.getUserName()));
final NotificationMessage savedMessage = notificationManager.createNotification(message);
final NotificationMessage loadedMessage = monitoringNotificationDao.loadMonitoringNotification(savedMessage.getId());
Assert.assertEquals(BODY, loadedMessage.getBody());
Assert.assertEquals(SUBJECT, loadedMessage.getSubject());
Assert.assertEquals(PARAMETERS, loadedMessage.getTemplateParameters());
Assert.assertEquals(testUser1.getId(), loadedMessage.getToUserId());
Assert.assertEquals(Collections.singletonList(testUser2.getId()), loadedMessage.getCopyUserIds());
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManagerTest method testNotifyIssue.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIssue() {
Pipeline pipeline = createPipeline(testOwner);
Issue issue = createIssue(testUser2, pipeline);
notificationManager.notifyIssue(issue, pipeline, issue.getText());
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(1, messages.size());
NotificationMessage message = messages.get(0);
Assert.assertEquals(testOwner.getId(), message.getToUserId());
Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser1.getId())));
Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser2.getId())));
Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(admin.getId())));
updateKeepInformedOwner(issueSettings, false);
notificationManager.notifyIssue(issue, pipeline, issue.getText());
messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(2, messages.size());
Assert.assertNull(messages.get(1).getToUserId());
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManagerTest method testCreateNotification.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCreateNotification() {
final NotificationMessageVO message = new NotificationMessageVO();
message.setBody(BODY);
message.setSubject(SUBJECT);
message.setParameters(PARAMETERS);
message.setToUser(testUser1.getUserName());
final NotificationMessage savedMessage = notificationManager.createNotification(message);
final NotificationMessage loadedMessage = monitoringNotificationDao.loadMonitoringNotification(savedMessage.getId());
Assert.assertEquals(BODY, loadedMessage.getBody());
Assert.assertEquals(SUBJECT, loadedMessage.getSubject());
Assert.assertEquals(PARAMETERS, loadedMessage.getTemplateParameters());
Assert.assertEquals(testUser1.getId(), loadedMessage.getToUserId());
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationAspectTest method testNotifyRunStatusChanged.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyRunStatusChanged() {
PipelineRun run = new PipelineRun();
run.setStatus(TaskStatus.SUCCESS);
run.setOwner(testOwner.getUserName());
run.setStartDate(new Date());
pipelineRunManager.updatePipelineStatus(run);
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertFalse(messages.isEmpty());
NotificationMessage message = messages.get(0);
Assert.assertEquals(testOwner.getId(), message.getToUserId());
Assert.assertEquals(TaskStatus.SUCCESS.name(), message.getTemplateParameters().get("status"));
Mockito.verify(pipelineRunDao).updateRunStatus(Mockito.any());
Mockito.verify(runStatusManager).saveStatus(Mockito.any());
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationService method sendNotification.
/**
* Scheduled task to load batch of {@link NotificationMessage} from database
* and delegate it to all realizations of {@link NotificationManager}
*/
@Scheduled(fixedDelayString = "${notification.scheduler.delay}")
@Transactional(propagation = Propagation.REQUIRED)
public void sendNotification() {
LOGGER.debug("Start scheduled notification loop...");
Pageable limit = new PageRequest(0, notificationAtTime);
List<NotificationMessage> result = notificationRepository.loadNotification(limit);
result.forEach(message -> {
notificationRepository.deleteById(message.getId());
for (NotificationManager notificationManager : notificationManagers) {
CompletableFuture.runAsync(() -> notificationManager.notifySubscribers(message), notificationThreadPool).exceptionally(throwable -> {
LOGGER.warn("Exception while trying to send email", throwable);
return null;
});
}
});
LOGGER.debug("End scheduled notification loop...");
}
Aggregations