Search in sources :

Example 21 with NotificationTemplate

use of com.epam.pipeline.entity.notification.NotificationTemplate in project cloud-pipeline by epam.

the class NotificationSettingsManagerTest method createTemplate.

private NotificationTemplate createTemplate(Long id, String name) {
    NotificationTemplate template = new NotificationTemplate(id);
    template.setName(name);
    template.setBody("//");
    template.setSubject("//");
    notificationTemplateDao.createNotificationTemplate(template);
    return template;
}
Also used : NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate)

Example 22 with NotificationTemplate

use of com.epam.pipeline.entity.notification.NotificationTemplate in project cloud-pipeline by epam.

the class NotificationSettingsManagerTest method testCreateWithoutThresholdAndResendDelay.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCreateWithoutThresholdAndResendDelay() {
    NotificationTemplate template = createTemplate(1L, "template");
    NotificationSettings settings = createSettings(NotificationType.LONG_RUNNING, template.getId(), null, null);
    notificationSettingsManager.createOrUpdate(settings);
    NotificationSettings loaded = notificationSettingsManager.load(NotificationType.LONG_RUNNING);
    Assert.assertEquals(-1, loaded.getThreshold().longValue());
    Assert.assertEquals(-1, loaded.getResendDelay().longValue());
}
Also used : NotificationSettings(com.epam.pipeline.entity.notification.NotificationSettings) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with NotificationTemplate

use of com.epam.pipeline.entity.notification.NotificationTemplate in project cloud-pipeline by epam.

the class NotificationSettingsManagerTest method testDelete.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testDelete() {
    NotificationTemplate template = createTemplate(1L, "template");
    NotificationSettings settings = createSettings(NotificationType.LONG_RUNNING, template.getId(), 1L, 1L);
    notificationSettingsManager.createOrUpdate(settings);
    NotificationSettings loaded = notificationSettingsManager.load(NotificationType.LONG_RUNNING);
    Assert.assertNotNull(loaded);
    notificationSettingsManager.delete(loaded.getId());
    loaded = notificationSettingsManager.load(NotificationType.LONG_RUNNING);
    Assert.assertNull(loaded);
}
Also used : NotificationSettings(com.epam.pipeline.entity.notification.NotificationSettings) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with NotificationTemplate

use of com.epam.pipeline.entity.notification.NotificationTemplate in project cloud-pipeline by epam.

the class SMTPNotificationManagerTest method testEmailSendingWithParams.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testEmailSendingWithParams() {
    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_WITH_PARAM);
    message.setTemplate(template);
    message.setTemplateParameters(Collections.singletonMap("name", USER_NAME));
    message.setToUserId(user.getId());
    message.setCopyUserIds(Collections.singletonList(user.getId()));
    smtpNotificationManager.notifySubscribers(message);
    MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
    assertTrue(receivedMessages.length == 2);
    String filledMessage = PARSED_MESSAGE_BODY_WITH_PARAM.replace("$templateParameters.get(\"name\")", USER_NAME);
    assertTrue(GreenMailUtil.getBody(receivedMessages[0]).contains(filledMessage));
}
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)

Aggregations

NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)24 Transactional (org.springframework.transaction.annotation.Transactional)17 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)13 NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)12 Test (org.junit.Test)12 NotificationSettings (com.epam.pipeline.entity.notification.NotificationSettings)8 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)5 ExtendedRole (com.epam.pipeline.entity.user.ExtendedRole)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)3 MimeMessage (javax.mail.internet.MimeMessage)3 Before (org.junit.Before)3 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)2 Issue (com.epam.pipeline.entity.issue.Issue)2 IssueComment (com.epam.pipeline.entity.issue.IssueComment)2 NotificationType (com.epam.pipeline.entity.notification.NotificationSettings.NotificationType)2 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)2 PipelineRunMapper (com.epam.pipeline.mapper.PipelineRunMapper)2 Arrays (java.util.Arrays)2