001: /*
002: * Created on Sep 26, 2003
003: *
004: /*
005: Copyright (c) 2003 eInnovation Inc. All rights reserved
006:
007: This library is free software; you can redistribute it and/or modify it under the terms
008: of the GNU Lesser General Public License as published by the Free Software Foundation;
009: either version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
012: without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013: See the GNU Lesser General Public License for more details.
014: */
015: package com.openedit.modules.email;
016:
017: import javax.mail.SendFailedException;
018:
019: import org.apache.commons.logging.Log;
020: import org.apache.commons.logging.LogFactory;
021:
022: import com.openedit.BaseTestCase;
023: import com.openedit.OpenEditException;
024: import com.openedit.WebPageRequest;
025:
026: /**
027: * @author Matt Avery, mavery@einnovation.com
028: */
029: public class SendMailCommandTest extends BaseTestCase {
030: private static final Log log = LogFactory
031: .getLog(SendMailCommandTest.class);
032:
033: public SendMailCommandTest(String arg0) {
034: super (arg0);
035: // TODO Auto-generated constructor stub
036: }
037:
038: public void testSendMail() throws Exception {
039: SendMailModule command = (SendMailModule) getBean("Email");
040: WebPageRequest context = getFixture().createPageRequest();
041: context.setRequestParameter("to", "cburkey@openedit.org");
042: context.setRequestParameter("from", "test@openedit.org");
043: context.setRequestParameter("subject",
044: "SendMailCommand test case");
045: context.setRequestParameter("smtp_server", "mail.openedit.org");
046: context.setRequestParameter("e-mail_layout",
047: "/email/e-mail_layout.html");
048: context.setRequestParameter("success_page",
049: "/email/thankyou.html");
050: context.setRequestParameter("error_page",
051: "/email/mail_failure.html");
052: // that's a lot of parameters!
053:
054: TemplateWebEmail settings = new TemplateWebEmail();
055: settings.loadSettings(context);
056: settings.setPostMail(command.getPostMail());
057: settings.setPageManager(getFixture().getPageManager());
058: context.putPageValue(SendMailModule.EMAIL_SETTINGS, settings);
059:
060: boolean commandSucceeded = false;
061:
062: try {
063: command.sendEmail(context);
064: commandSucceeded = true;
065: } catch (OpenEditException e) {
066: //e.printStackTrace();
067: log.error(e);
068: if (e.getCause() instanceof SendFailedException) {
069: //we can ignore port 25 being blocked etc...
070: commandSucceeded = true;
071: } else {
072: commandSucceeded = false;
073: }
074: }
075: assertTrue(commandSucceeded);
076: }
077:
078: public void testSendMailFromXconf() throws Exception {
079: SendMailModule command = (SendMailModule) getBean("Email");
080: WebPageRequest context = getFixture().createPageRequest(
081: "/email/thankyou.html");
082:
083: TemplateWebEmail settings = new TemplateWebEmail();
084: settings.loadSettings(context);
085: settings.setPageManager(getFixture().getPageManager());
086: settings.setPostMail(command.getPostMail());
087:
088: context.putPageValue(SendMailModule.EMAIL_SETTINGS, settings);
089:
090: boolean commandSucceeded = false;
091:
092: try {
093: command.sendEmail(context);
094: commandSucceeded = true;
095: } catch (OpenEditException e) {
096: //e.printStackTrace();
097: log.error(e);
098:
099: commandSucceeded = false;
100: }
101: assertTrue(commandSucceeded);
102: }
103:
104: public void testPosting() throws Exception {
105: new PostMail().postMail(
106: "Chris S. Burkey <cburkey@openedit.org>", "test",
107: "This is a test", "cburkey@openedit.org");
108: }
109: }
|