userTO.getMemberships().add(membershipTO);
userController.create(userTO, true);
// 3. Set number of retries
CAttr maxRetries = confDAO.find("notification.maxRetries", "5");
maxRetries.getValues().clear();
maxRetries.addValue("5", AttributableUtil.getInstance(AttributableType.CONFIGURATION));
confDAO.save(maxRetries);
confDAO.flush();
// 4. Stop mail server to force error sending mail
stopGreenMail();
// 5. force Quartz job execution multiple times
for (int i = 0; i < 10; i++) {
notificationJob.execute(null);
}
// 6. get NotificationTask, count number of executions
NotificationTask foundTask = null;
for (NotificationTask task : taskDAO.findAll(NotificationTask.class)) {
if (sender.equals(task.getSender())) {
foundTask = task;
}
}
assertNotNull(foundTask);
assertEquals(6, notificationManager.countExecutionsWithStatus(foundTask.getId(),
NotificationJob.Status.NOT_SENT.name()));
// 7. start mail server again
startGreenMail();
// 8. reset number of retries
maxRetries = confDAO.find("notification.maxRetries", "5");
maxRetries.getValues().clear();
maxRetries.addValue("0", AttributableUtil.getInstance(AttributableType.CONFIGURATION));
confDAO.save(maxRetries);
confDAO.flush();
}