[jboss-cvs] jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test ...
Peter Muir
peter at bleepbleep.org.uk
Thu Oct 11 09:43:35 EDT 2007
User: pmuir
Date: 07/10/11 09:43:35
Modified: examples/mail/src/org/jboss/seam/example/mail/test
MailTest.java
Added: examples/mail/src/org/jboss/seam/example/mail/test
errors2.xhtml errors4.xhtml errors3.xhtml
errors1.xhtml
Log:
Error tests for Seam Mail
Revision Changes Path
1.5 +165 -2 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- MailTest.java 11 Oct 2007 10:51:12 -0000 1.4
+++ MailTest.java 11 Oct 2007 13:43:35 -0000 1.5
@@ -4,11 +4,16 @@
import static javax.mail.Message.RecipientType.BCC;
import java.io.InputStream;
+
+import javax.faces.FacesException;
+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.contexts.Contexts;
+import org.jboss.seam.example.mail.Person;
import org.jboss.seam.mail.MailSession;
import org.jboss.seam.mail.MockTransport;
import org.jboss.seam.mock.SeamTest;
@@ -299,7 +304,7 @@
InternetAddress bcc = (InternetAddress) renderedMessage.getRecipients(CC)[0];
assert "test at example.com".equals(bcc.getAddress());
assert "Pete Muir".equals(bcc.getPersonal());
- assert "bulk".equals(renderedMessage.getHeader("Precedence"));
+ assert "bulk".equals(renderedMessage.getHeader("Precedence")[0]);
// Importance
assert renderedMessage.getHeader("X-Priority") != null;
assert renderedMessage.getHeader("Priority") != null;
@@ -326,6 +331,164 @@
}
@Test
+ public void testAttachmentErrors() throws Exception
+ {
+
+ new FacesRequest()
+ {
+
+ @Override
+ protected void updateModelValues() throws Exception
+ {
+
+ }
+
+ @Override
+ protected void invokeApplication() throws Exception
+ {
+ Person person = (Person) getValue("#{person}");
+
+ person.setFirstname("Pete");
+ person.setLastname("Muir");
+ person.setAddress("test at example.com");
+
+ // Test for an unavailable attachment
+
+ Contexts.getEventContext().set("attachment", "/foo.pdf");
+
+ boolean exceptionThrown = false;
+
+ }
+ }.run();
+ }
+
+ @Test
+ public void testAddressValidation() throws Exception
+ {
+
+ new FacesRequest()
+ {
+
+ @Override
+ protected void updateModelValues() throws Exception
+ {
+
+ }
+
+ @Override
+ protected void invokeApplication() throws Exception
+ {
+ Person person = (Person) getValue("#{person}");
+
+ person.setFirstname("Pete");
+ person.setLastname("Muir");
+ boolean exceptionThrown = false;
+
+ person.setAddress("testexample.com");
+
+ try
+ {
+ getRenderedMailMessage("/org/jboss/seam/example/mail/test/errors2.xhtml");
+ }
+ catch (FacesException e)
+ {
+ assert e.getCause() instanceof AddressException;
+ AddressException ae = (AddressException) e.getCause();
+ assert ae.getMessage().startsWith("Missing final '@domain'");
+ exceptionThrown = true;
+ }
+ assert exceptionThrown;
+
+ }
+ }.run();
+ }
+
+ @Test
+ public void testReplyToErrors() throws Exception
+ {
+
+ new FacesRequest()
+ {
+
+ @Override
+ protected void updateModelValues() throws Exception
+ {
+
+ }
+
+ @Override
+ protected void invokeApplication() throws Exception
+ {
+ Person person = (Person) getValue("#{person}");
+
+ person.setFirstname("Pete");
+ person.setLastname("Muir");
+ person.setAddress("test at example.com");
+
+ boolean exceptionThrown = false;
+
+
+
+ try
+ {
+ getRenderedMailMessage("/org/jboss/seam/example/mail/test/errors3.xhtml");
+ }
+ catch (Exception e)
+ {
+ assert e.getCause() instanceof AddressException;
+ AddressException ae = (AddressException) e.getCause();
+ System.out.println(ae.getMessage());
+ assert ae.getMessage().startsWith("Email cannot have more than one Reply-to address");
+ exceptionThrown = true;
+ }
+ assert exceptionThrown;
+
+ }
+ }.run();
+ }
+
+ @Test
+ public void testFromErrors() throws Exception
+ {
+
+ new FacesRequest()
+ {
+
+ @Override
+ protected void updateModelValues() throws Exception
+ {
+
+ }
+
+ @Override
+ protected void invokeApplication() throws Exception
+ {
+ Person person = (Person) getValue("#{person}");
+
+ person.setFirstname("Pete");
+ person.setLastname("Muir");
+ person.setAddress("test at example.com");
+
+ boolean exceptionThrown = false;
+
+ try
+ {
+ getRenderedMailMessage("/org/jboss/seam/example/mail/test/errors4.xhtml");
+ }
+ catch (FacesException e)
+ {
+ assert e.getCause() instanceof AddressException;
+ AddressException ae = (AddressException) e.getCause();
+ assert ae.getMessage().startsWith("Email cannot have more than one from address");
+ exceptionThrown = true;
+ }
+ assert exceptionThrown;
+
+ }
+ }.run();
+ }
+
+ @Test
public void testTemplating() throws Exception
{
1.1 date: 2007/10/11 13:43:35; author: pmuir; state: Exp;jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test/errors2.xhtml
Index: errors2.xhtml
===================================================================
<m:message xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html">
<m:from name="Peter" address="peter at example.com" />
<m:to name="#{person.firstname} #{person.lastname}">#{person.address}</m:to>
<m:subject>Try out Seam!</m:subject>
<m:body>A mail message to test exception handling</m:body>
</m:message>
1.1 date: 2007/10/11 13:43:35; author: pmuir; state: Exp;jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test/errors4.xhtml
Index: errors4.xhtml
===================================================================
<m:message xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html">
<m:from address="bar at bar.com" />
<m:from name="Peter" address="peter at example.com" />
<m:to name="#{person.firstname} #{person.lastname}">#{person.address}</m:to>
<m:subject>Try out Seam!</m:subject>
<m:body>A mail message to test exception handling</m:body>
</m:message>
1.1 date: 2007/10/11 13:43:35; author: pmuir; state: Exp;jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test/errors3.xhtml
Index: errors3.xhtml
===================================================================
<m:message xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html">
<m:replyTo address="foo at bar.com" />
<m:replyTo address="bar at bar.com" />
<m:from name="Peter" address="peter at example.com" />
<m:to name="#{person.firstname} #{person.lastname}">#{person.address}</m:to>
<m:subject>Try out Seam!</m:subject>
<m:body>A mail message to test exception handling</m:body>
</m:message>
1.1 date: 2007/10/11 13:43:35; author: pmuir; state: Exp;jboss-seam/examples/mail/src/org/jboss/seam/example/mail/test/errors1.xhtml
Index: errors1.xhtml
===================================================================
<m:message xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html">
<m:from name="Peter">peter at example.com</m:from>
<m:to name="Peter">peter at email.tld</m:to>
<m:subject>Try out Seam!</m:subject>
<m:attachment value="#{attachment}" />
<m:body>A mail message to test exception handling</m:body>
</m:message>
More information about the jboss-cvs-commits
mailing list