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));
}
Aggregations