Search in sources :

Example 1 with TemplateMail

use of br.com.caelum.vraptor.simplemail.template.TemplateMail in project mamute by caelum.

the class NewQuestionMailerTest method setup.

@Before
public void setup() {
    this.mailer = mock(AsyncMailer.class);
    TemplateMailer templates = mock(TemplateMailer.class);
    BundleFormatter bundle = mock(BundleFormatter.class);
    Linker linker = mock(Linker.class);
    QuestionController questionController = mock(QuestionController.class);
    this.request = mock(HttpServletRequest.class);
    TemplateMail mail = mock(TemplateMail.class);
    this.questionMailer = new NewQuestionMailer(mailer, templates, bundle, linker, "logo");
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(linker.linkTo(QuestionController.class)).thenReturn(questionController);
    when(templates.template(anyString())).thenReturn(mail);
    when(mail.with(anyString(), any())).thenReturn(mail);
}
Also used : TemplateMailer(br.com.caelum.vraptor.simplemail.template.TemplateMailer) HttpServletRequest(javax.servlet.http.HttpServletRequest) QuestionController(org.mamute.controllers.QuestionController) BundleFormatter(br.com.caelum.vraptor.simplemail.template.BundleFormatter) TemplateMail(br.com.caelum.vraptor.simplemail.template.TemplateMail) Linker(org.mamute.vraptor.Linker) AsyncMailer(br.com.caelum.vraptor.simplemail.AsyncMailer) Before(org.junit.Before)

Example 2 with TemplateMail

use of br.com.caelum.vraptor.simplemail.template.TemplateMail in project mamute by caelum.

the class NewQuestionMailer method send.

public void send(List<User> subscribed, Question question) {
    linker.linkTo(QuestionController.class).showQuestion(question, question.getSluggedTitle());
    String questionLink = linker.get();
    TemplateMail template = templates.template("new_question_notification").with("question", question).with("bundle", bundle).with("questionLink", questionLink).with("logoUrl", emailLogo);
    for (User user : subscribed) {
        boolean notSameAuthor = !user.equals(question.getAuthor());
        if (notSameAuthor) {
            Email email = template.to(user.getName(), user.getEmail());
            mailer.asyncSend(email);
        }
    }
}
Also used : QuestionController(org.mamute.controllers.QuestionController) User(org.mamute.model.User) Email(org.apache.commons.mail.Email) TemplateMail(br.com.caelum.vraptor.simplemail.template.TemplateMail)

Aggregations

TemplateMail (br.com.caelum.vraptor.simplemail.template.TemplateMail)2 QuestionController (org.mamute.controllers.QuestionController)2 AsyncMailer (br.com.caelum.vraptor.simplemail.AsyncMailer)1 BundleFormatter (br.com.caelum.vraptor.simplemail.template.BundleFormatter)1 TemplateMailer (br.com.caelum.vraptor.simplemail.template.TemplateMailer)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Email (org.apache.commons.mail.Email)1 Before (org.junit.Before)1 User (org.mamute.model.User)1 Linker (org.mamute.vraptor.Linker)1