Search in sources :

Example 26 with NotificationMessage

use of com.epam.pipeline.entity.notification.NotificationMessage 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

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