use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManagerTest method testNotifyIdleRun.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIdleRun() {
PipelineRun run1 = new PipelineRun();
run1.setOwner(testUser1.getUserName());
run1.setStartDate(DateUtils.now());
run1.setId(1L);
PipelineRun run2 = new PipelineRun();
run2.setStartDate(DateUtils.now());
run2.setOwner(testUser2.getUserName());
run2.setId(2L);
notificationManager.notifyIdleRuns(Arrays.asList(new ImmutablePair<>(run1, TEST_CPU_RATE1), new ImmutablePair<>(run2, TEST_CPU_RATE2)), NotificationType.IDLE_RUN);
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(2, messages.size());
messages.forEach(m -> Assert.assertEquals(SystemPreferences.SYSTEM_IDLE_CPU_THRESHOLD_PERCENT.getDefaultValue().doubleValue(), m.getTemplateParameters().get("idleCpuLevel")));
NotificationMessage run1Message = messages.stream().filter(m -> m.getToUserId().equals(testUser1.getId())).findFirst().get();
Assert.assertEquals(TEST_CPU_RATE1 * PERCENT, run1Message.getTemplateParameters().get("cpuRate"));
Assert.assertEquals(run1.getId().intValue(), run1Message.getTemplateParameters().get("id"));
NotificationMessage run2Message = messages.stream().filter(m -> m.getToUserId().equals(testUser2.getId())).findFirst().get();
Assert.assertEquals(TEST_CPU_RATE2 * PERCENT, run2Message.getTemplateParameters().get("cpuRate"));
Assert.assertEquals(run2.getId().intValue(), run2Message.getTemplateParameters().get("id"));
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManagerTest method testNotifyLongRunning.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyLongRunning() {
podMonitor.updateStatus();
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(1, messages.size());
Assert.assertEquals(admin.getId(), messages.get(0).getToUserId());
Assert.assertTrue(messages.get(0).getCopyUserIds().contains(admin.getId()));
Assert.assertEquals(longRunningTemplate.getId(), messages.get(0).getTemplate().getId());
ArgumentCaptor<PipelineRun> runCaptor = ArgumentCaptor.forClass(PipelineRun.class);
verify(pipelineRunManager).updatePipelineRunLastNotification(runCaptor.capture());
PipelineRun capturedRun = runCaptor.getValue();
Assert.assertNotNull(capturedRun.getLastNotificationTime());
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class SMTPNotificationManagerTest method testEmailSending.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testEmailSending() {
PipelineUser user = new PipelineUser();
user.setUserName(USER_NAME);
user.setAdmin(true);
user.setAttributes(Collections.singletonMap(EMAIL_KEY, EMAIL));
userRepository.save(user);
NotificationMessage message = new NotificationMessage();
NotificationTemplate template = new NotificationTemplate();
template.setSubject(MESSAGE_SUBJECT);
template.setBody(MESSAGE_BODY);
message.setTemplate(template);
message.setTemplateParameters(Collections.emptyMap());
message.setToUserId(user.getId());
message.setCopyUserIds(Collections.singletonList(user.getId()));
smtpNotificationManager.notifySubscribers(message);
MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertTrue(receivedMessages.length == 2);
assertTrue(GreenMailUtil.getBody(receivedMessages[0]).contains(MESSAGE_BODY));
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class SMTPNotificationManagerTest method testWontSendToOwnerIfNotConfigured.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testWontSendToOwnerIfNotConfigured() throws MessagingException {
PipelineUser user = new PipelineUser();
user.setUserName(USER_NAME);
user.setAdmin(false);
user.setAttributes(Collections.singletonMap(EMAIL_KEY, EMAIL));
userRepository.save(user);
NotificationMessage message = new NotificationMessage();
NotificationTemplate template = new NotificationTemplate();
template.setSubject(MESSAGE_SUBJECT);
template.setBody(MESSAGE_BODY_WITH_PARAM);
message.setTemplate(template);
message.setTemplateParameters(Collections.singletonMap("name", USER_NAME));
message.setToUserId(null);
message.setCopyUserIds(Collections.singletonList(user.getId()));
smtpNotificationManager.notifySubscribers(message);
MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertEquals(1, receivedMessages.length);
assertNull(receivedMessages[0].getRecipients(Message.RecipientType.TO));
assertEquals(1, receivedMessages[0].getRecipients(Message.RecipientType.CC).length);
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class SMTPNotificationManagerTest method testEmailSendingWithoutTemplate.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testEmailSendingWithoutTemplate() {
PipelineUser user = new PipelineUser();
user.setUserName(USER_NAME);
user.setAttributes(Collections.singletonMap(EMAIL_KEY, EMAIL));
userRepository.save(user);
NotificationMessage message = new NotificationMessage();
message.setSubject(MESSAGE_SUBJECT);
message.setBody(MESSAGE_BODY);
message.setToUserId(user.getId());
message.setCopyUserIds(Collections.singletonList(user.getId()));
smtpNotificationManager.notifySubscribers(message);
MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertTrue(receivedMessages.length == 2);
assertTrue(GreenMailUtil.getBody(receivedMessages[0]).contains(MESSAGE_BODY));
}
Aggregations