Search in sources :

Example 1 with CapybaraPortingLayer

use of org.jenkinsci.test.acceptance.po.CapybaraPortingLayer in project acceptance-test-harness by jenkinsci.

the class MailService method assertMail.

/**
 * Checks that the mail has arrived.
 */
public void assertMail(final Pattern subject, String recipient, Pattern body) throws MessagingException, IOException {
    CapybaraPortingLayer hackish = new CapybaraPortingLayerImpl(World.get().getInjector());
    MimeMessage msg = hackish.waitFor().withMessage("Email whose subject matches: %s", subject).pollingEvery(5, TimeUnit.SECONDS).until(new MailArrives(subject));
    String actualRecipients = Joiner.on(' ').join(msg.getRecipients(TO));
    assertThat("recipient", actualRecipients, is(recipient));
    Object c = msg.getContent();
    if (c instanceof MimeMultipart) {
        MimeMultipart content = (MimeMultipart) c;
        c = content.getBodyPart(0).getContent();
    }
    assertThat(c.toString(), containsRegexp(body));
}
Also used : CapybaraPortingLayer(org.jenkinsci.test.acceptance.po.CapybaraPortingLayer) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) CapybaraPortingLayerImpl(org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)1 MimeMultipart (javax.mail.internet.MimeMultipart)1 CapybaraPortingLayer (org.jenkinsci.test.acceptance.po.CapybaraPortingLayer)1 CapybaraPortingLayerImpl (org.jenkinsci.test.acceptance.po.CapybaraPortingLayerImpl)1