KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > mail > HtmlMailTest


1 package info.magnolia.cms.mail;
2
3 import info.magnolia.cms.mail.templates.MailAttachment;
4 import info.magnolia.cms.mail.templates.MgnlEmail;
5 import info.magnolia.cms.mail.templates.impl.HtmlEmail;
6
7 import java.io.File JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import org.subethamail.wiser.WiserMessage;
13
14
15 /**
16  * @author <a HREF="mailto:niko@macnica.com">Nicolas Modrzyk</a>
17  */

18 public class HtmlMailTest extends AbstractMailTest {
19
20     public void testHtmlMail() throws Exception JavaDoc {
21         MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML);
22         String JavaDoc subject = "test html email";
23         email.setSubject(subject);
24         email.setBody("<h1>Helloniko</h1>", null);
25         email.setToList(TEST_RECIPIENT);
26         email.setFrom(TEST_SENDER);
27
28         handler.prepareAndSendMail(email);
29
30         assertTrue(wiser.getMessages().size() == 1);
31         Iterator JavaDoc emailIter = wiser.getMessages().iterator();
32         WiserMessage message = (WiserMessage) emailIter.next();
33         assertTrue(message.getMimeMessage().getSubject().equals(subject));
34     }
35
36     public void testHtmlMailWithImageFile() throws Exception JavaDoc {
37         MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML);
38         email.addAttachment(new MailAttachment(new File JavaDoc(getResourcePath(TEST_FILE_JPG)).toURL(), "att"));
39         email.setBody("<h1>Helloniko</h1><img SRC=\"cid:att\"/>", null);
40         String JavaDoc subject = "test html email";
41         email.setSubject(subject);
42         email.setToList(TEST_RECIPIENT);
43         email.setFrom(TEST_SENDER);
44
45         handler.prepareAndSendMail(email);
46
47         assertTrue(wiser.getMessages().size() == 1);
48         Iterator JavaDoc emailIter = wiser.getMessages().iterator();
49         WiserMessage message = (WiserMessage) emailIter.next();
50         assertTrue(message.getMimeMessage().getSubject().equals(subject));
51     }
52
53     public void testHtmlMailWithTwoEmbeddedContent() throws Exception JavaDoc {
54         MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML);
55         ArrayList JavaDoc attach = new ArrayList JavaDoc();
56         attach.add(new MailAttachment(new File JavaDoc(getResourcePath(TEST_FILE_JPG)).toURL(), "att1"));
57         attach.add(new MailAttachment(new File JavaDoc(getResourcePath(TEST_FILE_PDF)).toURL(), "att2"));
58         HashMap JavaDoc param = new HashMap JavaDoc(1);
59         param.put(HtmlEmail.MAIL_ATTACHMENT, attach);
60         String JavaDoc subject = "test html email";
61         email.setSubject(subject);
62         email.setBody("<h1>Helloniko</h1><img SRC=\"cid:att1\"/><img SRC=\"cid:att2\"/>", param);
63         email.setToList(TEST_RECIPIENT);
64         email.setFrom(TEST_SENDER);
65
66         handler.prepareAndSendMail(email);
67
68         assertTrue(wiser.getMessages().size() == 1);
69         Iterator JavaDoc emailIter = wiser.getMessages().iterator();
70         WiserMessage message = (WiserMessage) emailIter.next();
71         assertTrue(message.getMimeMessage().getSubject().equals(subject));
72     }
73
74     public void testHtmlMailWithPdf() throws Exception JavaDoc {
75         MgnlEmail email = factory.getEmailFromType(MailConstants.MAIL_TEMPLATE_HTML);
76         String JavaDoc subject = "test html email";
77         email.setSubject(subject);
78         email.setBody("<h1>Helloniko in pdf</h1>", new HashMap JavaDoc(0));
79         email.addAttachment(new MailAttachment(new File JavaDoc(getResourcePath(TEST_FILE_PDF)).toURL(), "att1"));
80         email.setToList(TEST_RECIPIENT);
81         email.setFrom(TEST_SENDER);
82
83         handler.prepareAndSendMail(email);
84
85         assertTrue(wiser.getMessages().size() == 1);
86         Iterator JavaDoc emailIter = wiser.getMessages().iterator();
87         WiserMessage message = (WiserMessage) emailIter.next();
88         assertTrue(message.getMimeMessage().getSubject().equals(subject));
89     }
90
91 }
92
Popular Tags