public static void mailAssertions(SmtpServer server, int mailIndex) { assertEquals(1, server.getEmailCount()); assertEquals( String.valueOf(MAIL_PRIORITY), server.getMessage(mailIndex).getFirstHeaderValue("X-Priority")); assertEquals(FROM_ADRESS, server.getMessage(mailIndex).getFirstHeaderValue("From")); assertArrayEquals(TO_ADRESS, extractEmails(server.getMessage(mailIndex), "To")); assertArrayEquals(CC_ADRESS, extractEmails(server.getMessage(mailIndex), "Cc")); // assertArrayEquals(BCC_ADRESS, extractEmails(server.getMessage(mailIndex), "Bcc")); assertEquals(MAIL_SUBJECT, server.getMessage(mailIndex).getFirstHeaderValue("Subject")); assertTrue(server.getMessage(mailIndex).getBody().contains(MAIL_BODY_HTML)); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Type: " + (MAIL_HTML ? "text/html" : "text/plain"))); assertTrue(server.getMessage(mailIndex).getBody().contains("charset=" + MAIL_ENCODING)); }
@After public void cleanup() throws Exception { server.stop(); mailDispatcher.close(); }
public static void mailWithAttachmentsAssertions(SmtpServer server, int mailIndex) { assertEquals(1, server.getEmailCount()); assertEquals( String.valueOf(MAIL_PRIORITY), server.getMessage(mailIndex).getFirstHeaderValue("X-Priority")); assertEquals(FROM_ADRESS, server.getMessage(mailIndex).getFirstHeaderValue("From")); assertArrayEquals(TO_ADRESS, extractEmails(server.getMessage(mailIndex), "To")); assertArrayEquals(CC_ADRESS, extractEmails(server.getMessage(mailIndex), "Cc")); // assertArrayEquals(BCC_ADRESS, extractEmails(server.getMessage(mailIndex), "Bcc")); assertEquals(MAIL_SUBJECT, server.getMessage(mailIndex).getFirstHeaderValue("Subject")); assertTrue(server.getMessage(mailIndex).getBody().contains(MAIL_BODY_HTML)); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Type: " + (MAIL_HTML ? "text/html" : "text/plain"))); assertTrue(server.getMessage(mailIndex).getBody().contains("charset=" + MAIL_ENCODING)); assertTrue( server.getMessage(mailIndex).getBody().contains("Content-Type: text/html; charset=UTF-8")); assertTrue(server.getMessage(mailIndex).getBody().contains("Content-Transfer-Encoding: 7bit")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Type: text/xml; charset=UTF-8; name=helloworld.xml")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Transfer-Encoding: quoted-printable")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Disposition: attachment; filename=helloworld.xml")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("<line>this is an email attachment with some specials characters</line>")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Type: image/gif; name=helloworld.gif")); assertTrue( server.getMessage(mailIndex).getBody().contains("Content-Transfer-Encoding: base64")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Disposition: attachment; filename=helloworld.gif")); assertTrue( server .getMessage(mailIndex) .getBody() .contains( "R0lGODlhvAIsAfcAAHPLLiEkIqQnKhkoKjNKYjNUJ9Amc3FrJJAmarInV/LMmP4mavvmsycoHTYo")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Type: text/plain; charset=UTF-8; name=helloworld.txt")); assertTrue(server.getMessage(mailIndex).getBody().contains("Content-Transfer-Encoding: 7bit")); assertTrue( server .getMessage(mailIndex) .getBody() .contains("Content-Disposition: attachment; filename=helloworld.txt")); assertTrue(server.getMessage(mailIndex).getBody().contains("this is an email attachment")); }