Search in sources :

Example 6 with NotificationMessage

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"));
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with NotificationMessage

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());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with NotificationMessage

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));
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractSpringTest(com.epam.pipeline.notifier.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with NotificationMessage

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);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractSpringTest(com.epam.pipeline.notifier.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with NotificationMessage

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));
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractSpringTest(com.epam.pipeline.notifier.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)26 Transactional (org.springframework.transaction.annotation.Transactional)25 Test (org.junit.Test)18 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)15 NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)14 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)8 NotificationSettings (com.epam.pipeline.entity.notification.NotificationSettings)7 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)6 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)6 NotificationMessageVO (com.epam.pipeline.controller.vo.notification.NotificationMessageVO)5 ExtendedRole (com.epam.pipeline.entity.user.ExtendedRole)5 Collections (java.util.Collections)5 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)4 Issue (com.epam.pipeline.entity.issue.Issue)4 IssueComment (com.epam.pipeline.entity.issue.IssueComment)4 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)4 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)4 Arrays (java.util.Arrays)4 List (java.util.List)4 Map (java.util.Map)4