@Test public void testExecuteNoHtml() throws MessagingException { request = new NotificationEmailDTO(); request.setSubject(SUBJECT); request.setTextBody(TEXT_BODY); request.setDescription("whatever"); request.setToRecipient(TO_RECIPIENT); request.setBccRecipients(BCC_RECIPIENTS); request.setHighPriority(true); final String replyTo = "replyto@eurekastreams.org"; request.setReplyTo(replyTo); context.checking(new Expectations() { { oneOf(emailer).createMessage(); will(returnValue(message)); oneOf(emailer).setSubject(message, SUBJECT); oneOf(emailer).setTextBody(message, TEXT_BODY); oneOf(emailer).setTo(message, TO_RECIPIENT); oneOf(emailer).setBcc(message, BCC_RECIPIENTS); oneOf(emailer).setReplyTo(message, replyTo); oneOf(message).addHeader("Importance", "high"); oneOf(message).addHeader("X-Priority", "1"); oneOf(emailer).sendMail(with(same(message))); } }); sut.execute(TestContextCreator.createPrincipalActionContext(request, null)); context.assertIsSatisfied(); }
@Override public Serializable execute(final ActionContext inActionContext) throws ExecutionException { NotificationEmailDTO request = (NotificationEmailDTO) inActionContext.getParams(); try { MimeMessage message = emailer.createMessage(); emailer.setSubject(message, request.getSubject()); emailer.setTextBody(message, request.getTextBody()); if (StringUtils.isNotBlank(request.getHtmlBody())) { emailer.setHtmlBody(message, request.getHtmlBody()); } if (StringUtils.isNotBlank(request.getToRecipient())) { emailer.setTo(message, request.getToRecipient()); } if (StringUtils.isNotBlank(request.getBccRecipients())) { emailer.setBcc(message, request.getBccRecipients()); } if (StringUtils.isNotBlank(request.getReplyTo())) { emailer.setReplyTo(message, request.getReplyTo()); } if (request.isHighPriority()) { message.addHeader("Importance", "high"); message.addHeader("X-Priority", "1"); } emailer.sendMail(message); log.debug("Sent email for notification {}", request.getDescription()); } catch (MessagingException ex) { String msg = "Failed to send email message for notification " + request.getDescription(); log.error(msg, ex); throw new ExecutionException(msg, ex); } return null; }
SendNotificationEmailExecution implements ExecutionStrategy<ActionContext> { @Override public Serializable execute(final ActionContext inActionContext) throws ExecutionException { NotificationEmailDTO request = (NotificationEmailDTO) inActionContext.getParams(); try { MimeMessage message = emailer.createMessage(); emailer.setSubject(message, request.getSubject()); emailer.setTextBody(message, request.getTextBody()); if (StringUtils.isNotBlank(request.getHtmlBody())) { emailer.setHtmlBody(message, request.getHtmlBody()); } if (StringUtils.isNotBlank(request.getToRecipient())) { emailer.setTo(message, request.getToRecipient()); } if (StringUtils.isNotBlank(request.getBccRecipients())) { emailer.setBcc(message, request.getBccRecipients()); } if (StringUtils.isNotBlank(request.getReplyTo())) { emailer.setReplyTo(message, request.getReplyTo()); } if (request.isHighPriority()) { message.addHeader("Importance", "high"); message.addHeader("X-Priority", "1"); } emailer.sendMail(message); log.debug("Sent email for notification {}", request.getDescription()); } catch (MessagingException ex) { String msg = "Failed to send email message for notification " + request.getDescription(); log.error(msg, ex); throw new ExecutionException(msg, ex); } return null; } }
SendNotificationEmailExecution implements ExecutionStrategy<ActionContext> { @Override public Serializable execute(final ActionContext inActionContext) throws ExecutionException { NotificationEmailDTO request = (NotificationEmailDTO) inActionContext.getParams(); try { MimeMessage message = emailer.createMessage(); emailer.setSubject(message, request.getSubject()); emailer.setTextBody(message, request.getTextBody()); if (StringUtils.isNotBlank(request.getHtmlBody())) { emailer.setHtmlBody(message, request.getHtmlBody()); } if (StringUtils.isNotBlank(request.getToRecipient())) { emailer.setTo(message, request.getToRecipient()); } if (StringUtils.isNotBlank(request.getBccRecipients())) { emailer.setBcc(message, request.getBccRecipients()); } if (StringUtils.isNotBlank(request.getReplyTo())) { emailer.setReplyTo(message, request.getReplyTo()); } if (request.isHighPriority()) { message.addHeader("Importance", "high"); message.addHeader("X-Priority", "1"); } emailer.sendMail(message); log.debug("Sent email for notification {}", request.getDescription()); } catch (MessagingException ex) { String msg = "Failed to send email message for notification " + request.getDescription(); log.error(msg, ex); throw new ExecutionException(msg, ex); } return null; } SendNotificationEmailExecution(final EmailerFactory inEmailer); }
SendNotificationEmailExecution implements ExecutionStrategy<ActionContext> { @Override public Serializable execute(final ActionContext inActionContext) throws ExecutionException { NotificationEmailDTO request = (NotificationEmailDTO) inActionContext.getParams(); try { MimeMessage message = emailer.createMessage(); emailer.setSubject(message, request.getSubject()); emailer.setTextBody(message, request.getTextBody()); if (StringUtils.isNotBlank(request.getHtmlBody())) { emailer.setHtmlBody(message, request.getHtmlBody()); } if (StringUtils.isNotBlank(request.getToRecipient())) { emailer.setTo(message, request.getToRecipient()); } if (StringUtils.isNotBlank(request.getBccRecipients())) { emailer.setBcc(message, request.getBccRecipients()); } if (StringUtils.isNotBlank(request.getReplyTo())) { emailer.setReplyTo(message, request.getReplyTo()); } if (request.isHighPriority()) { message.addHeader("Importance", "high"); message.addHeader("X-Priority", "1"); } emailer.sendMail(message); log.debug("Sent email for notification {}", request.getDescription()); } catch (MessagingException ex) { String msg = "Failed to send email message for notification " + request.getDescription(); log.error(msg, ex); throw new ExecutionException(msg, ex); } return null; } SendNotificationEmailExecution(final EmailerFactory inEmailer); @Override Serializable execute(final ActionContext inActionContext); }
SendNotificationEmailExecution implements ExecutionStrategy<ActionContext> { @Override public Serializable execute(final ActionContext inActionContext) throws ExecutionException { NotificationEmailDTO request = (NotificationEmailDTO) inActionContext.getParams(); try { MimeMessage message = emailer.createMessage(); emailer.setSubject(message, request.getSubject()); emailer.setTextBody(message, request.getTextBody()); if (StringUtils.isNotBlank(request.getHtmlBody())) { emailer.setHtmlBody(message, request.getHtmlBody()); } if (StringUtils.isNotBlank(request.getToRecipient())) { emailer.setTo(message, request.getToRecipient()); } if (StringUtils.isNotBlank(request.getBccRecipients())) { emailer.setBcc(message, request.getBccRecipients()); } if (StringUtils.isNotBlank(request.getReplyTo())) { emailer.setReplyTo(message, request.getReplyTo()); } if (request.isHighPriority()) { message.addHeader("Importance", "high"); message.addHeader("X-Priority", "1"); } emailer.sendMail(message); log.debug("Sent email for notification {}", request.getDescription()); } catch (MessagingException ex) { String msg = "Failed to send email message for notification " + request.getDescription(); log.error(msg, ex); throw new ExecutionException(msg, ex); } return null; } SendNotificationEmailExecution(final EmailerFactory inEmailer); @Override Serializable execute(final ActionContext inActionContext);  }