[jboss-cvs] jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test ...
Dan Allen
dan.j.allen at gmail.com
Tue Jan 8 13:07:46 EST 2008
User: dallen
Date: 08/01/08 13:07:46
Modified: examples/mail/src/org/jboss/seam/example/mail/test
MailTest.java
Log:
add test that verifies DocumentData is handled correctly
cannot use Renderer approach since PDF components aren't handled in mock environment
Revision Changes Path
1.8 +40 -0 jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MailTest.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test/MailTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- MailTest.java 8 Nov 2007 04:27:42 -0000 1.7
+++ MailTest.java 8 Jan 2008 18:07:46 -0000 1.8
@@ -6,12 +6,16 @@
import java.io.InputStream;
import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
+import org.jboss.seam.mail.ui.UIAttachment;
+import org.jboss.seam.mail.ui.UIMessage;
+import org.jboss.seam.pdf.DocumentData;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.example.mail.Person;
import org.jboss.seam.mail.MailSession;
@@ -184,6 +188,42 @@
}
+ /**
+ * This test is needed since the PDF is not rendered in the attachment test.
+ * If PDF rendering is supported in a test environment, then this test can be
+ * removed.
+ */
+ @Test
+ public void testPdfAttachment() throws Exception
+ {
+ new FacesRequest()
+ {
+ @Override
+ protected void invokeApplication() throws Exception
+ {
+ UIAttachment attachment = new UIAttachment();
+ attachment.setFileName("filename.pdf");
+ UIMessage message = new UIMessage();
+ message.setMailSession(MailSession.instance());
+ attachment.setParent(message);
+ DocumentData doc = new DocumentData("filename", new DocumentData.DocumentType("pdf", "application/pdf"), new byte[] {});
+ attachment.setValue(doc);
+ attachment.encodeEnd(FacesContext.getCurrentInstance());
+
+ // verify we built the message
+ MimeMessage mimeMessage = message.getMimeMessage();
+ Object content = mimeMessage.getContent();
+ assert content instanceof MimeMultipart;
+ MimeMultipart multipartContent = (MimeMultipart) content;
+ assert multipartContent.getCount() == 1;
+ assert multipartContent.getBodyPart(0) instanceof MimeBodyPart;
+ MimeBodyPart bodyPart = (MimeBodyPart) multipartContent.getBodyPart(0);
+ assert "filename.pdf".equals(bodyPart.getFileName());
+ assert "attachment".equals(bodyPart.getDisposition());
+ }
+ }.run();
+ }
+
@Test
public void testHtml() throws Exception
{
More information about the jboss-cvs-commits
mailing list