1 15 package com.openedit.modules.email; 16 17 18 19 import javax.mail.SendFailedException ; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import com.openedit.BaseTestCase; 25 import com.openedit.OpenEditException; 26 import com.openedit.WebPageRequest; 27 28 29 30 33 public class SendMailCommandTest extends BaseTestCase 34 { 35 private static final Log log = LogFactory.getLog(SendMailCommandTest.class); 36 public SendMailCommandTest(String arg0) 37 { 38 super(arg0); 39 } 41 public void testSendMail() throws Exception 42 { 43 SendMailModule command = (SendMailModule)getBean("Email"); 44 WebPageRequest context = getFixture().createPageRequest(); 45 context.setRequestParameter( "to", "cburkey@openedit.org" ); 46 context.setRequestParameter( "from", "test@openedit.org" ); 47 context.setRequestParameter( "subject", "SendMailCommand test case" ); 48 context.setRequestParameter( "smtp_server", "mail.openedit.org" ); 49 context.setRequestParameter( "e-mail_layout", "/email/e-mail_layout.html" ); 50 context.setRequestParameter( "success_page", "/email/thankyou.html" ); 51 context.setRequestParameter( "error_page", "/email/mail_failure.html" ); 52 54 TemplateWebEmail settings = new TemplateWebEmail(); 55 settings.loadSettings(context,getFixture().getPageManager()); 56 context.putPageValue(SendMailModule.EMAIL_SETTINGS,settings); 57 58 boolean commandSucceeded = false; 59 60 try 61 { 62 command.sendEmail( context ); 63 commandSucceeded = true; 64 } 65 catch (OpenEditException e) 66 { 67 log.error(e); 69 if ( e.getCause() instanceof SendFailedException ) 70 { 71 commandSucceeded = true; 73 } 74 else 75 { 76 commandSucceeded = false; 77 } 78 } 79 } 82 83 public void testSendMailFromXconf() throws Exception 84 { 85 SendMailModule command = (SendMailModule)getBean("Email"); 86 WebPageRequest context = getFixture().createPageRequest("/email/thankyou.html"); 87 88 TemplateWebEmail settings = new TemplateWebEmail(); 89 settings.loadSettings(context,getFixture().getPageManager()); 90 context.putPageValue(SendMailModule.EMAIL_SETTINGS,settings); 91 92 boolean commandSucceeded = false; 93 94 try 95 { 96 command.sendEmail( context ); 97 commandSucceeded = true; 98 } 99 catch (OpenEditException e) 100 { 101 log.error(e); 103 104 commandSucceeded = false; 105 } 106 assertTrue( commandSucceeded ); 107 } 108 109 public void testPosting() throws Exception 110 { 111 new PostMail().postMail("Chris S. Burkey <cburkey@openedit.org>","test","This is a test","cburkey@openedit.org"); 112 } 113 } | Popular Tags |