@Override
protected void invokeApplication() throws Exception
{
UIAttachment attachment = new UIAttachment();
attachment.setFileName("filename.pdf");
UIMessage message = new UIMessage();
attachment.setParent(message);
message.setMailSession(MailSession.instance());
DocumentData doc = new ByteArrayDocumentData("filename", new DocumentData.DocumentType("pdf", "application/pdf"), new byte[] {});
attachment.setValue(doc);
attachment.encodeEnd(FacesContext.getCurrentInstance());
// verify we built the message
Assert.assertEquals(message.getAttachments().size(), 1);
MimeBodyPart bodyPart = message.getAttachments().get(0);
Assert.assertEquals(bodyPart.getFileName(), "filename.pdf");
Assert.assertEquals(bodyPart.getDisposition(),"attachment");
}
}.run();
}