org.apache.commons.mail
Class BaseEmailTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.commons.mail.BaseEmailTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
EmailAttachmentTest, EmailTest, HtmlEmailTest, InvalidAddressTest, InvalidInternetAddressTest, MultiPartEmailTest, SendWithAttachmentsTest, SimpleEmailTest

public class BaseEmailTestCase
extends junit.framework.TestCase

Base test case for Email test classes

Since:
1.0
Version:
$Id: BaseEmailTestCase.java 544629 2007-06-05 20:55:13Z bspeakmon $
Author:
Corey Scott, Eric Pugh

Field Summary
static int BODY_END_PAD
          Padding at end of body added by wiser/send
static int BODY_START_PAD
          Padding at start of body added by wiser/send
protected  org.subethamail.wiser.Wiser fakeMailServer
          The fake Wiser email server
protected  String strTestMailFrom
          From address for the test email
protected  String strTestMailServer
          Mail server used for testing
protected  String strTestMailTo
          Destination address for the test email
protected  String strTestPasswd
          Mailserver strTestPasswd (set if needed)
protected  String strTestURL
          URL to used to test URL attachmetns (Must be valid)
protected  String strTestUser
          Mailserver username (set if needed)
protected  String[] testCharsNotValid
          Array of test strings
protected  String[] testCharsValid
          Test characters acceptable to email
 
Constructor Summary
BaseEmailTestCase(String name)
           
 
Method Summary
 void getMailServer()
          Initializes the stub mail server.
protected  int getMailServerPort()
          Gets the mail server port.
 String getMessageAsString(int intMsgNo)
           
protected  boolean isMailServerStopped(org.subethamail.wiser.Wiser fakeMailServer)
          Checks if an email server is running at the address stored in the fakeMailServer.
protected  void saveEmailToFile(org.subethamail.wiser.WiserMessage email)
           
protected  void tearDown()
           
protected  org.subethamail.wiser.WiserMessage validateSend(org.subethamail.wiser.Wiser mailServer, String strSubject, javax.mail.internet.InternetAddress fromAdd, List toAdd, List ccAdd, List bccAdd, boolean boolSaveToFile)
          Validate the message was sent properly
protected  void validateSend(org.subethamail.wiser.Wiser mailServer, String strSubject, javax.mail.Multipart content, javax.mail.internet.InternetAddress fromAdd, List toAdd, List ccAdd, List bccAdd, boolean boolSaveToFile)
          Validate the message was sent properly
protected  void validateSend(org.subethamail.wiser.Wiser mailServer, String strSubject, String strMessage, javax.mail.internet.InternetAddress fromAdd, List toAdd, List ccAdd, List bccAdd, boolean boolSaveToFile)
          Validate the message was sent properly
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BODY_END_PAD

public static final int BODY_END_PAD
Padding at end of body added by wiser/send

See Also:
Constant Field Values

BODY_START_PAD

public static final int BODY_START_PAD
Padding at start of body added by wiser/send

See Also:
Constant Field Values

fakeMailServer

protected org.subethamail.wiser.Wiser fakeMailServer
The fake Wiser email server


strTestMailServer

protected String strTestMailServer
Mail server used for testing


strTestMailFrom

protected String strTestMailFrom
From address for the test email


strTestMailTo

protected String strTestMailTo
Destination address for the test email


strTestUser

protected String strTestUser
Mailserver username (set if needed)


strTestPasswd

protected String strTestPasswd
Mailserver strTestPasswd (set if needed)


strTestURL

protected String strTestURL
URL to used to test URL attachmetns (Must be valid)


testCharsValid

protected String[] testCharsValid
Test characters acceptable to email


testCharsNotValid

protected String[] testCharsNotValid
Array of test strings

Constructor Detail

BaseEmailTestCase

public BaseEmailTestCase(String name)
Parameters:
name - name
Method Detail

tearDown

protected void tearDown()
Overrides:
tearDown in class junit.framework.TestCase

getMailServerPort

protected int getMailServerPort()
Gets the mail server port.

Returns:
the port the server is running on.

saveEmailToFile

protected void saveEmailToFile(org.subethamail.wiser.WiserMessage email)
                        throws IOException
Parameters:
email - email
Throws:
IOException - Exception

getMessageAsString

public String getMessageAsString(int intMsgNo)
Parameters:
intMsgNo - the message to retrieve
Returns:
message as string

getMailServer

public void getMailServer()
Initializes the stub mail server. Fails if the server cannot be proven to have started. If the server is already started, this method returns without changing the state of the server.


validateSend

protected org.subethamail.wiser.WiserMessage validateSend(org.subethamail.wiser.Wiser mailServer,
                                                          String strSubject,
                                                          javax.mail.internet.InternetAddress fromAdd,
                                                          List toAdd,
                                                          List ccAdd,
                                                          List bccAdd,
                                                          boolean boolSaveToFile)
                                                   throws IOException
Validate the message was sent properly

Parameters:
mailServer - reference to the fake mail server
strSubject - expected subject
fromAdd - expected from address
toAdd - list of expected to addresses
ccAdd - list of expected cc addresses
bccAdd - list of expected bcc addresses
boolSaveToFile - true will output to file, false doesnt
Returns:
WiserMessage email to check
Throws:
IOException - Exception

validateSend

protected void validateSend(org.subethamail.wiser.Wiser mailServer,
                            String strSubject,
                            javax.mail.Multipart content,
                            javax.mail.internet.InternetAddress fromAdd,
                            List toAdd,
                            List ccAdd,
                            List bccAdd,
                            boolean boolSaveToFile)
                     throws IOException
Validate the message was sent properly

Parameters:
mailServer - reference to the fake mail server
strSubject - expected subject
content - the expected message content
fromAdd - expected from address
toAdd - list of expected to addresses
ccAdd - list of expected cc addresses
bccAdd - list of expected bcc addresses
boolSaveToFile - true will output to file, false doesnt
Throws:
IOException - Exception

validateSend

protected void validateSend(org.subethamail.wiser.Wiser mailServer,
                            String strSubject,
                            String strMessage,
                            javax.mail.internet.InternetAddress fromAdd,
                            List toAdd,
                            List ccAdd,
                            List bccAdd,
                            boolean boolSaveToFile)
                     throws IOException
Validate the message was sent properly

Parameters:
mailServer - reference to the fake mail server
strSubject - expected subject
strMessage - the expected message as a string
fromAdd - expected from address
toAdd - list of expected to addresses
ccAdd - list of expected cc addresses
bccAdd - list of expected bcc addresses
boolSaveToFile - true will output to file, false doesnt
Throws:
IOException - Exception

isMailServerStopped

protected boolean isMailServerStopped(org.subethamail.wiser.Wiser fakeMailServer)
Checks if an email server is running at the address stored in the fakeMailServer.

Parameters:
fakeMailServer - The server from which the address is picked up.
Returns:
true if the server claims to be running
Since:
1.1


Copyright © 2001-2010 Apache Software Foundation. All Rights Reserved.