use of com.nilhcem.fakesmtp.model.EmailModel in project CzechIdMng by bcvsolutions.
the class NotificationSmtpTest method A_sendEmailViaSmtpByManager.
@Test
public void A_sendEmailViaSmtpByManager() throws InterruptedException, BindPortException, OutOfRangePortException {
// in first test start smtp server
if (!this.isRunning()) {
this.startSmtpServer();
}
// create config
NotificationConfigurationDto config = new NotificationConfigurationDto();
config.setTopic(TOPIC);
config.setLevel(NotificationLevel.SUCCESS);
config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
config = notificationConfigurationService.save(config);
// init observer for this test only
NotificationObserver observer = new NotificationObserver(1);
this.addObserver(observer);
int currentEmails = observer.getEmails().size();
assertTrue(this.isRunning());
String textHtml = "textHtml-" + System.currentTimeMillis();
String textText = "textText-" + System.currentTimeMillis();
String subject = "subject-" + System.currentTimeMillis();
IdmIdentityDto identity = helper.createIdentity();
identity.setEmail("example@example.tld");
identity = identityService.save(identity);
notificationManager.send(TOPIC, new IdmMessageDto.Builder().setTextMessage(textText).setHtmlMessage(textHtml).setSubject(subject).setLevel(NotificationLevel.SUCCESS).build(), identity);
// email is send by apache camel asynchronously
if (observer.getEmails().size() == currentEmails) {
observer.waitForMails();
}
assertEquals(currentEmails + 1, observer.getEmails().size());
assertTrue(this.isRunning());
for (EmailModel email : observer.getEmails()) {
assertEquals(FROM, email.getFrom());
assertTrue(email.getEmailStr().contains(textHtml));
assertEquals(subject, email.getSubject());
assertEquals(identity.getEmail(), email.getTo());
}
notificationConfigurationService.delete(config);
}
use of com.nilhcem.fakesmtp.model.EmailModel in project CzechIdMng by bcvsolutions.
the class NotificationSmtpTest method B_sendEmailViaSmtpByWf.
@Test
public void B_sendEmailViaSmtpByWf() throws InterruptedException, BindPortException, OutOfRangePortException {
assertTrue(this.isRunning());
// init observer for this test only
NotificationObserver observer = new NotificationObserver(2);
this.addObserver(observer);
int currentEmails = observer.getEmails().size();
IdmIdentityDto identity = identityService.getByUsername(TO_WF);
if (identity == null) {
identity = helper.createIdentity(TO_WF);
}
identity.setEmail("example@example.tld");
identity = identityService.save(identity);
processInstanceService.startProcess(WF_NAME, null, InitTestData.TEST_USER_1, null, null);
// email is send by apache camel asynchronously
if (observer.getEmails().size() == currentEmails) {
observer.waitForMails();
}
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(identity.getUsername());
filter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
//
assertEquals(2, notifications.size());
assertTrue(this.isRunning());
assertEquals(currentEmails + 2, observer.getEmails().size());
for (EmailModel email : observer.getEmails()) {
assertEquals(FROM, email.getFrom());
assertEquals(identity.getEmail(), email.getTo());
}
// in last test stop smtp server
this.stopSmtpServer();
}
Aggregations