commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/settings EmailConfiguration.java
Date Mon, 01 Nov 2004 13:55:03 GMT
epugh       2004/11/01 05:55:03

  Modified:    email/src/test/org/apache/commons/mail HtmlEmailTest.java
                        EmailTest.java EmailAttachmentTest.java
                        MultiPartEmailTest.java BaseEmailTestCase.java
                        SimpleEmailTest.java
               email/src/java/org/apache/commons/mail MultiPartEmail.java
                        SimpleEmail.java HtmlEmail.java
               email/src/test/org/apache/commons/mail/settings
                        EmailConfiguration.java
  Removed:     email/src/java/org/apache/commons/mail package.html
  Log:
  Fixs to style and dumbster!
  
  Revision  Changes    Path
  1.8       +86 -45    jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/HtmlEmailTest.java
  
  Index: HtmlEmailTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/HtmlEmailTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HtmlEmailTest.java	29 Oct 2004 11:43:54 -0000	1.7
  +++ HtmlEmailTest.java	1 Nov 2004 13:54:59 -0000	1.8
  @@ -19,14 +19,11 @@
   import java.io.IOException;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import java.util.Iterator;
   
   import javax.mail.MessagingException;
   
   import org.apache.commons.mail.mocks.MockHtmlEmailConcrete;
  -
  -import com.dumbster.smtp.SimpleSmtpServer;
  -import com.dumbster.smtp.SmtpMessage;
  +import org.apache.commons.mail.settings.EmailConfiguration;
   
   /**
    * JUnit test case for HtmlEmail Class
  @@ -60,32 +57,54 @@
       public void testGetSetTextMsg()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        try
           {
  -            this.email.setTextMsg(testCharacters[i]);
  -            assertEquals(testCharacters[i], this.email.getTextMsg());
  +            for (int i = 0; i < testCharsValid.length; i++)
  +            {
  +                this.email.setTextMsg(testCharsValid[i]);
  +                assertEquals(testCharsValid[i], this.email.getTextMsg());
  +            }
  +        }
  +        catch (MessagingException e)
  +        {
  +            e.printStackTrace();
           }
       }
   
       /** */
       public void testGetSetHtmlMsg()
       {
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        try
  +        {
  +            for (int i = 0; i < testCharsValid.length; i++)
  +            {
  +                this.email.setHtmlMsg(testCharsValid[i]);
  +                assertEquals(testCharsValid[i], this.email.getHtmlMsg());
  +            }
  +        }
  +        catch (MessagingException e)
           {
  -            this.email.setHtmlMsg(testCharacters[i]);
  -            assertEquals(testCharacters[i], this.email.getHtmlMsg());
  +            e.printStackTrace();
           }
       }
   
       /** */
       public void testGetSetMsg()
       {
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        try
           {
  -            this.email.setMsg( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.email.getTextMsg() );
  +            for (int i = 0; i < testCharsValid.length; i++)
  +            {
  +                this.email.setMsg(testCharsValid[i]);
  +                assertEquals(testCharsValid[i], this.email.getTextMsg());
   
  -            assertTrue( this.email.getHtmlMsg().indexOf( testCharacters[ i ] ) != -1 );
  +                assertTrue(
  +                    this.email.getHtmlMsg().indexOf(testCharsValid[i]) != -1);
  +            }
  +        }
  +        catch (MessagingException e)
  +        {
  +            e.printStackTrace();
           }
       }
   
  @@ -134,11 +153,8 @@
       }
   
       /** */
  -    public void testSend() throws Exception
  +    public void testSend()
       {
  -        if(fakeMailServer==null || !fakeMailServer.isStopped()){
  -            this.fakeMailServer = SimpleSmtpServer.start(25);
  -        }
           EmailAttachment attachment = new EmailAttachment();
           File testFile = null;
   
  @@ -158,28 +174,27 @@
           // ====================================================================
           try
           {
  +            this.getMailServer();
   
  +            String strSubject = "Test HTML Send #1 Subject (w charset)";
   
               this.email = new MockHtmlEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setFrom(this.strTestMailFrom);
               this.email.addTo(this.strTestMailTo);
  -            
  +
               /** File to used to test file attachmetns (Must be valid) */
               attachment.setName("Test Attachment");
               attachment.setDescription("Test Attachment Desc");
               attachment.setPath(testFile.getAbsolutePath());
  -            this.email.attach(attachment);            
  -            
  -            this.email.setAuthentication(
  -                this.strTestUser,
  -                this.strTestPasswd);
  -            
  +            this.email.attach(attachment);
  +
  +            this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
   
               this.email.setCharset(Email.ISO_8859_1);
  -            this.email.setSubject("Test HTML Send #1 Subject (w charset)");
  +            this.email.setSubject(strSubject);
   
  -            URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
  +            URL url = new URL(EmailConfiguration.TEST_URL);
               String cid = this.email.embed(url, "Apache Logo");
   
               String strHtmlMsg =
  @@ -190,13 +205,8 @@
                   "Your email client does not support HTML emails");
   
               this.email.send();
  -            
  -            assertTrue(fakeMailServer.getReceievedEmailSize() == 1);
  -            Iterator emailIter = fakeMailServer.getReceivedEmail();
  -            SmtpMessage email = (SmtpMessage)emailIter.next();
  -            saveEmailToFile(email);
  -            assertEquals("Test Msg Subject",email.getHeaderValue("Subject"));
  -            //assertEquals("abc123",email.getBody());    
  +            this.fakeMailServer.stop();
  +            assertTrue(validateSend(fakeMailServer, strSubject));
           }
           catch (MessagingException e)
           {
  @@ -208,9 +218,16 @@
               e.printStackTrace();
               fail("Unexpected exception thrown");
           }
  +        catch (IOException e)
  +        {
  +            e.printStackTrace();
  +            fail("Failed to save email to output file");
  +        }
   
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockHtmlEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setFrom(this.strTestMailFrom);
  @@ -223,28 +240,36 @@
                       this.strTestPasswd);
               }
   
  -            this.email.setSubject("Test HTML Send #1 Subject (wo charset)");
  +            String strSubject = "Test HTML Send #1 Subject (wo charset)";
  +            this.email.setSubject(strSubject);
               this.email.setMsg("Test message");
   
               this.email.send();
  -            
  -            assertTrue(fakeMailServer.getReceievedEmailSize() == 1);
  -            Iterator emailIter = fakeMailServer.getReceivedEmail();
  -            SmtpMessage email = (SmtpMessage)emailIter.next();
  -            saveEmailToFile(email);
  -            assertEquals("Test Msg Subject",email.getHeaderValue("Subject"));
  -            //assertEquals("abc123",email.getBody());                
  +            this.fakeMailServer.stop();
  +            assertTrue(validateSend(fakeMailServer, strSubject));
           }
           catch (MessagingException e)
           {
               e.printStackTrace();
               fail("Unexpected exception thrown");
           }
  +        catch (IOException e)
  +        {
  +            e.printStackTrace();
  +            fail("Failed to save email to output file");
  +        }
  +    }
  +
  +    /** */
  +    public void testSend2()
  +    {
           // ====================================================================
           // Test Success
           // ====================================================================
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockHtmlEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setFrom(this.strTestMailFrom);
  @@ -257,19 +282,28 @@
                       this.strTestPasswd);
               }
   
  -            this.email.setSubject("Test HTML Send #2 Subject (wo charset)");
  +            String strSubject = "Test HTML Send #2 Subject (wo charset)";
  +            this.email.setSubject(strSubject);
               this.email.setTextMsg("Test txt msg");
   
               this.email.send();
  +            this.fakeMailServer.stop();
  +            assertTrue(validateSend(fakeMailServer, strSubject));
           }
           catch (MessagingException e)
           {
               e.printStackTrace();
               fail("Unexpected exception thrown");
           }
  +        catch (IOException e1)
  +        {
  +            e1.printStackTrace();
  +        }
   
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockHtmlEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setFrom(this.strTestMailFrom);
  @@ -282,16 +316,23 @@
                       this.strTestPasswd);
               }
   
  +            String strSubject = "Test HTML Send #2 Subject (w charset)";
               this.email.setCharset(Email.ISO_8859_1);
  -            this.email.setSubject("Test HTML Send #2 Subject (w charset)");
  +            this.email.setSubject(strSubject);
               this.email.setTextMsg("Test txt msg");
   
               this.email.send();
  +            this.fakeMailServer.stop();
  +            assertTrue(validateSend(fakeMailServer, strSubject));
           }
           catch (MessagingException e)
           {
               e.printStackTrace();
               fail("Unexpected exception thrown");
  +        }
  +        catch (IOException e1)
  +        {
  +            e1.printStackTrace();
           }
       }
   }
  
  
  
  1.9       +163 -137  jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/EmailTest.java
  
  Index: EmailTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/EmailTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EmailTest.java	29 Oct 2004 11:43:54 -0000	1.8
  +++ EmailTest.java	1 Nov 2004 13:54:59 -0000	1.9
  @@ -15,13 +15,13 @@
    */
   package org.apache.commons.mail;
   
  +import java.io.IOException;
   import java.io.UnsupportedEncodingException;
   import java.util.ArrayList;
   import java.util.Calendar;
   import java.util.Date;
   import java.util.Enumeration;
   import java.util.Hashtable;
  -import java.util.Iterator;
   import java.util.Properties;
   
   import javax.mail.Authenticator;
  @@ -33,9 +33,6 @@
   
   import org.apache.commons.mail.mocks.MockEmailConcrete;
   
  -import com.dumbster.smtp.SimpleSmtpServer;
  -import com.dumbster.smtp.SmtpMessage;
  -
   /**
    * JUnit test case for Email Class
    *
  @@ -47,18 +44,19 @@
   {
       /** */
       private MockEmailConcrete email = null;
  -    
  -    String[] testEmailValid =
  -    {
  -        "me@home.com",
  -        "joe.doe@apache.org",
  -        "someone_here@work-address.com.au" };    
  +
  +    /** */
  +    public static final String[] ARR_VALID_EMAILS =
  +        {
  +            "me@home.com",
  +            "joe.doe@apache.org",
  +            "someone_here@work-address.com.au" };
       /**
        * @param name name
        */
       public EmailTest(String name)
       {
  -        super(name);       
  +        super(name);
       }
   
       /** */
  @@ -68,7 +66,7 @@
           // reusable objects to be used across multiple tests
           this.email = new MockEmailConcrete();
       }
  -
  + 
       /** */
       public void testGetSetDebug()
       {
  @@ -138,42 +136,46 @@
           // setup
           String strUsername = "user.name";
           String strPassword = "user.pwd";
  -        DefaultAuthenticator authenicator = new DefaultAuthenticator( strUsername, strPassword );
  -        this.email.setAuthenticator( authenicator );
  -        
  -        // this is cast into DefaultAuthenticator for convenience and give us access to the getPasswordAuthentication fn
  -        DefaultAuthenticator retrievedAuth = (DefaultAuthenticator) this.email.getAuthenticator();
  +        DefaultAuthenticator authenicator =
  +            new DefaultAuthenticator(strUsername, strPassword);
  +        this.email.setAuthenticator(authenicator);
  +
  +        // this is cast into DefaultAuthenticator for convenience 
  +        // and give us access to the getPasswordAuthentication fn
  +        DefaultAuthenticator retrievedAuth =
  +            (DefaultAuthenticator) this.email.getAuthenticator();
   
           // tests
  -        assertTrue( Authenticator.class.isInstance( this.email.getAuthenticator() ) );
  -        assertEquals( strUsername, retrievedAuth.getPasswordAuthentication().getUserName() );
  -        assertEquals( strPassword, retrievedAuth.getPasswordAuthentication().getPassword() );
  +        assertTrue(
  +            Authenticator.class.isInstance(this.email.getAuthenticator()));
  +        assertEquals(
  +            strUsername,
  +            retrievedAuth.getPasswordAuthentication().getUserName());
  +        assertEquals(
  +            strPassword,
  +            retrievedAuth.getPasswordAuthentication().getPassword());
       }
   
       /** */
       public void testGetSetCharset()
       {
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.email.setCharset( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.email.getCharset() );
  +            this.email.setCharset(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.email.getCharset());
           }
       }
   
       /** */
       public void testSetContentMimeMultipart()
       {
  -        MimeMultipart[] tests = 
  -        {
  -            new MimeMultipart(), 
  -            new MimeMultipart( "abc123" ), 
  -            null
  -        };
  +        MimeMultipart[] tests =
  +            { new MimeMultipart(), new MimeMultipart("abc123"), null };
   
  -        for ( int i = 0; i < tests.length; i++ )
  +        for (int i = 0; i < tests.length; i++)
           {
  -            this.email.setContent( tests[ i ] );
  -            assertEquals( tests[ i ], this.email.getContentMimeMultipart() );
  +            this.email.setContent(tests[i]);
  +            assertEquals(tests[i], this.email.getContentMimeMultipart());
           }
       }
   
  @@ -188,47 +190,47 @@
           // test (string object and valid content type)
           testObject = "test string object";
           testContentType = " ; charset=" + Email.US_ASCII;
  -        
  -        this.email.setContent( testObject, testContentType );
  -        assertEquals( testObject, this.email.getContentObject() );
  -        assertEquals( testContentType, this.email.getContentType() );
  +
  +        this.email.setContent(testObject, testContentType);
  +        assertEquals(testObject, this.email.getContentObject());
  +        assertEquals(testContentType, this.email.getContentType());
   
           // ====================================================================
           // test (null string object and valid content type)
           testObject = null;
           testContentType = " ; charset=" + Email.US_ASCII + " some more here";
  -        
  -        this.email.setContent( testObject, testContentType );
  -        assertEquals( testObject, this.email.getContentObject() );
  -        assertEquals( testContentType, this.email.getContentType() );
  +
  +        this.email.setContent(testObject, testContentType);
  +        assertEquals(testObject, this.email.getContentObject());
  +        assertEquals(testContentType, this.email.getContentType());
   
           // ====================================================================
           // test (string object and null content type)
           testObject = "test string object";
           testContentType = null;
  -        
  -        this.email.setContent( testObject, testContentType );
  -        assertEquals( testObject, this.email.getContentObject() );
  -        assertEquals( testContentType, this.email.getContentType() );
  +
  +        this.email.setContent(testObject, testContentType);
  +        assertEquals(testObject, this.email.getContentObject());
  +        assertEquals(testContentType, this.email.getContentType());
   
           // ====================================================================
           // test (string object and invalid content type)
           testObject = "test string object";
           testContentType = " something incorrect ";
  -        
  -        this.email.setContent( testObject, testContentType );
  -        assertEquals( testObject, this.email.getContentObject() );
  -        assertEquals( testContentType, this.email.getContentType() );
  +
  +        this.email.setContent(testObject, testContentType);
  +        assertEquals(testObject, this.email.getContentObject());
  +        assertEquals(testContentType, this.email.getContentType());
       }
   
       /** */
       public void testGetSetHostName()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.email.setHostName( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.email.getHostName() );
  +            this.email.setHostName(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.email.getHostName());
           }
       }
   
  @@ -307,12 +309,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.setFrom(testEmailValid[i]);
  +                this.email.setFrom(ARR_VALID_EMAILS[i]);
   
                   // retrieve and verify
                   assertEquals(arrExpected.get(i), this.email.getFromAddress());
  @@ -414,9 +416,11 @@
               // reset the mail class
               MockEmailConcrete anotherEmail = new MockEmailConcrete();
               // set a dodgy encoding scheme
  -            anotherEmail.setCharset("bad.encoding??\n");
  +            anotherEmail.setCharset("bad.encoding\uc5ec\n");
               // set a valid address but bad personal name
  -            anotherEmail.setFrom("me@home.com", "\t.bad.personal.name.??\n");
  +            anotherEmail.setFrom(
  +                "me@home.com", 
  +                "\t.bad.personal.name.\uc5ec\n");
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
  @@ -456,12 +460,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addTo(testEmailValid[i]);
  +                this.email.addTo(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -502,12 +506,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addTo(testEmailValid[i]);
  +                this.email.addTo(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -549,12 +553,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addTo(testEmailValid[i], testEmailNames[i]);
  +                this.email.addTo(ARR_VALID_EMAILS[i], testEmailNames[i]);
               }
               catch (MessagingException e)
               {
  @@ -576,9 +580,9 @@
               // reset the mail class
               MockEmailConcrete anotherEmail = new MockEmailConcrete();
               // set a dodgy encoding scheme
  -            anotherEmail.setCharset("bad.encoding??\n");
  +            anotherEmail.setCharset("bad.encoding\uc5ec\n");
               // set a valid address but bad personal name
  -            anotherEmail.addTo("me@home.com", "\t.bad.name.??\n");
  +            anotherEmail.addTo("me@home.com", "\t.bad.name.\uc5ec\n");
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
  @@ -624,7 +628,7 @@
               // retrieve and verify
               assertEquals(testEmailValid2.size(), this.email.getToList().size());
               assertEquals(
  -                    testEmailValid2.toString(),
  +                testEmailValid2.toString(),
                   this.email.getToList().toString());
           }
           catch (MessagingException e)
  @@ -696,12 +700,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addCc(testEmailValid[i]);
  +                this.email.addCc(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -742,12 +746,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addCc(testEmailValid[i]);
  +                this.email.addCc(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -789,12 +793,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addCc(testEmailValid[i], testEmailNames[i]);
  +                this.email.addCc(ARR_VALID_EMAILS[i], testEmailNames[i]);
               }
               catch (MessagingException e)
               {
  @@ -816,9 +820,9 @@
               // reset the mail class
               MockEmailConcrete anotherEmail = new MockEmailConcrete();
               // set a dodgy encoding scheme
  -            anotherEmail.setCharset("bad.encoding??\n");
  +            anotherEmail.setCharset("bad.encoding\uc5ec\n");
               // set a valid address but bad personal name
  -            anotherEmail.addCc("me@home.com", "\t.bad.name.??\n");
  +            anotherEmail.addCc("me@home.com", "\t.bad.name.\uc5ec\n");
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
  @@ -918,12 +922,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addBcc(testEmailValid[i]);
  +                this.email.addBcc(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -966,12 +970,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addBcc(testEmailValid[i]);
  +                this.email.addBcc(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -1015,12 +1019,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addBcc(testEmailValid[i], testEmailNames[i]);
  +                this.email.addBcc(ARR_VALID_EMAILS[i], testEmailNames[i]);
               }
               catch (MessagingException e)
               {
  @@ -1044,9 +1048,9 @@
               // reset the mail class
               MockEmailConcrete anotherEmail = new MockEmailConcrete();
               // set a dodgy encoding scheme
  -            anotherEmail.setCharset("bad.encoding??\n");
  +            anotherEmail.setCharset("bad.encoding\uc5ec\n");
               // set a valid address but bad personal name
  -            anotherEmail.addBcc("me@home.com", "\t.bad.name.??\n");
  +            anotherEmail.addBcc("me@home.com", "\t.bad.name.\uc5ec\n");
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
  @@ -1066,15 +1070,15 @@
           // ====================================================================
           // Test Success
           // ====================================================================
  -        ArrayList testEmailValid = new ArrayList();
  +        ArrayList testInetEmailValid = new ArrayList();
           try
           {
  -            testEmailValid.add(new InternetAddress("me@home.com", "Name1"));
  -            testEmailValid.add(
  +            testInetEmailValid.add(new InternetAddress("me@home.com", "Name1"));
  +            testInetEmailValid.add(
                   new InternetAddress(
                       "joe.doe@apache.org",
                       "joe.doe@apache.org"));
  -            testEmailValid.add(
  +            testInetEmailValid.add(
                   new InternetAddress(
                       "someone_here@work-address.com.au",
                       "someone_here@work-address.com.au"));
  @@ -1087,8 +1091,8 @@
   
           try
           {
  -            this.email.setBcc(testEmailValid);
  -            assertEquals(testEmailValid, this.email.getBccList());
  +            this.email.setBcc(testInetEmailValid);
  +            assertEquals(testInetEmailValid, this.email.getBccList());
           }
           catch (MessagingException e)
           {
  @@ -1159,12 +1163,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addReplyTo(testEmailValid[i]);
  +                this.email.addReplyTo(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -1207,12 +1211,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addReplyTo(testEmailValid[i]);
  +                this.email.addReplyTo(ARR_VALID_EMAILS[i]);
               }
               catch (MessagingException e)
               {
  @@ -1256,12 +1260,12 @@
               fail("Unexpected exception thrown");
           }
   
  -        for (int i = 0; i < testEmailValid.length; i++)
  +        for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
           {
               try
               {
                   // set from 
  -                this.email.addReplyTo(testEmailValid[i], testEmailNames[i]);
  +                this.email.addReplyTo(ARR_VALID_EMAILS[i], testEmailNames[i]);
               }
               catch (MessagingException e)
               {
  @@ -1285,9 +1289,9 @@
               // reset the mail class
               MockEmailConcrete anotherEmail = new MockEmailConcrete();
               // set a dodgy encoding scheme
  -            anotherEmail.setCharset("bad.encoding??\n");
  +            anotherEmail.setCharset("bad.encoding\uc5ec\n");
               // set a valid address but bad personal name
  -            anotherEmail.addReplyTo("me@home.com", "\t.bad.name.??\n");
  +            anotherEmail.addReplyTo("me@home.com", "\t.bad.name.\uc5ec\n");
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
  @@ -1387,69 +1391,73 @@
           // ====================================================================
           // first test
           Hashtable htBad = new Hashtable();
  -        htBad.put( "X-Mailer", "" );
  +        htBad.put("X-Mailer", "");
  +
  +        Hashtable arrExpected = new Hashtable();
   
  -        
  -        Hashtable arrExpected = new Hashtable(); 
  -        
           try
           {
  -            this.email.setHeaders( htBad );
  -            fail( "Should have thrown an exception" );
  +            this.email.setHeaders(htBad);
  +            fail("Should have thrown an exception");
           }
  -        catch ( IllegalArgumentException e )
  +        catch (IllegalArgumentException e)
           {
  -            assertTrue( true );
  +            assertTrue(true);
           }
   
  -        assertEquals( arrExpected.size(),       this.email.getHeaders().size() );
  -        assertEquals( arrExpected.toString(),   this.email.getHeaders().toString() );
  -        
  +        assertEquals(arrExpected.size(), this.email.getHeaders().size());
  +        assertEquals(
  +            arrExpected.toString(),
  +            this.email.getHeaders().toString());
  +
           // ====================================================================
           // second test
           htBad = new Hashtable();
  -        htBad.put( "", "me@home.com" );
  +        htBad.put("", "me@home.com");
   
           try
           {
  -            this.email.setHeaders( htBad );
  -            fail( "Should have thrown an exception" );
  +            this.email.setHeaders(htBad);
  +            fail("Should have thrown an exception");
           }
  -        catch ( IllegalArgumentException e )
  +        catch (IllegalArgumentException e)
           {
  -            assertTrue( true );
  +            assertTrue(true);
           }
   
  -        assertEquals( arrExpected.size(),       this.email.getHeaders().size() );
  -        assertEquals( arrExpected.toString(),   this.email.getHeaders().toString() );
  +        assertEquals(arrExpected.size(), this.email.getHeaders().size());
  +        assertEquals(
  +            arrExpected.toString(),
  +            this.email.getHeaders().toString());
       }
   
       /** */
       public void testSetSubject()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.email.setSubject( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.email.getSubject() );
  +            this.email.setSubject(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.email.getSubject());
           }
       }
   
       /**
        * @todo Add code to test the popBeforeSmtp() settings
  -     * @todo (Not necessary, but would add completeness) add code to recall the message property 
  -     * of the class instances and then verfiy that all settings were made to this correctly       
  +     * @todo (Not necessary, but would add completeness) 
  +     * add code to recall the message property 
  +     * of the class instances and then verfiy that all 
  +     * settings were made to this correctly       
        */
  -    public void testSend() throws Exception
  +    public void testSend()
       {
  -        if(fakeMailServer==null || !fakeMailServer.isStopped()){
  -            this.fakeMailServer = SimpleSmtpServer.start(25);
  -        }
           // ====================================================================
           // Test Success
           // ====================================================================
           try
           {
  +            this.getMailServer();
  +            
               this.email = new MockEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setFrom(this.strTestMailFrom);
  @@ -1462,8 +1470,9 @@
                       this.strTestPasswd);
               }
   
  +            String strSubject = "Test Msg Subject";
               this.email.setCharset(Email.ISO_8859_1);
  -            this.email.setSubject("Test Msg Subject");
  +            this.email.setSubject(strSubject);
   
               this.email.setContent(new MimeMultipart("abc123"));
   
  @@ -1473,20 +1482,22 @@
               ht.put("X-Mailer", "Sendmail");
   
               this.email.setHeaders(ht);
  -            this.email.setDebug(true);
  +//            this.email.setDebug(true);
               this.email.send();
  -            assertEquals(1,fakeMailServer.getReceievedEmailSize());
  -            Iterator emailIter = fakeMailServer.getReceivedEmail();
  -            SmtpMessage email = (SmtpMessage)emailIter.next();
  -            saveEmailToFile(email);
  -            assertEquals("Test Msg Subject",email.getHeaderValue("Subject"));
  -            //assertEquals("abc123",email.getBody());    
  +
  +            this.fakeMailServer.stop();
  +            assertTrue(validateSend(fakeMailServer, strSubject));
           }
           catch (MessagingException e)
           {
               e.printStackTrace();
               fail("Unexpected exception thrown");
           }
  +        catch (IOException e)
  +        {
  +            e.printStackTrace();
  +            fail("failed to save email to output file");
  +        }
       }
   
       /** */
  @@ -1498,12 +1509,15 @@
           // hostname not set
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockEmailConcrete();
               this.email.send();
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
           {
  +            this.fakeMailServer.stop();
               assertTrue(true);
           }
           catch (Exception e)
  @@ -1515,6 +1529,8 @@
           // bad hostname
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockEmailConcrete();
               this.email.setSubject("Test Email #1 Subject");
               this.email.setHostName("bad.host.com");
  @@ -1533,6 +1549,7 @@
           }
           catch (ParseException e)
           {
  +            this.fakeMailServer.stop();
               assertTrue(true);
           }
           catch (Exception e)
  @@ -1547,6 +1564,8 @@
           // from add not set
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setSmtpPort(this.intTestMailServerPort);
  @@ -1556,6 +1575,7 @@
           }
           catch (MessagingException e)
           {
  +            this.fakeMailServer.stop();
               assertTrue(true);
           }
           catch (Exception e)
  @@ -1567,6 +1587,8 @@
           // destination (to/cc/bcc) dd not set
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setSmtpPort(this.intTestMailServerPort);
  @@ -1576,6 +1598,7 @@
           }
           catch (MessagingException e)
           {
  +            this.fakeMailServer.stop();
               assertTrue(true);
           }
           catch (Exception e)
  @@ -1587,6 +1610,8 @@
           // bad auth set
           try
           {
  +            this.getMailServer();
  +
               this.email = new MockEmailConcrete();
               this.email.setHostName(this.strTestMailServer);
               this.email.setSmtpPort(this.intTestMailServerPort);
  @@ -1598,6 +1623,7 @@
           }
           catch (MessagingException e)
           {
  +            this.fakeMailServer.stop();
               assertTrue(true);
           }
           catch (Exception e)
  @@ -1623,23 +1649,23 @@
       /** */
       public void testToInternetAddressArray()
       {
  -        ArrayList testEmailValid = new ArrayList();
  +        ArrayList testInetEmailValid = new ArrayList();
   
           try
           {
  -            testEmailValid.add(new InternetAddress("me@home.com", "Name1"));
  -            testEmailValid.add(
  +            testInetEmailValid.add(new InternetAddress("me@home.com", "Name1"));
  +            testInetEmailValid.add(
                   new InternetAddress(
                       "joe.doe@apache.org",
                       "joe.doe@apache.org"));
  -            testEmailValid.add(
  +            testInetEmailValid.add(
                   new InternetAddress(
                       "someone_here@work-address.com.au",
                       "someone_here@work-address.com.au"));
   
  -            this.email.setBcc(testEmailValid);
  +            this.email.setBcc(testInetEmailValid);
               assertEquals(
  -                testEmailValid.size(),
  +                testInetEmailValid.size(),
                   this.email.toInternetAddressArray(
                       this.email.getBccList()).length);
           }
  @@ -1676,5 +1702,5 @@
           assertEquals(strUsername, this.email.getPopUsername());
           assertEquals(strPassword, this.email.getPopPassword());
       }
  -    
  +
   }
  
  
  
  1.5       +24 -26    jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/EmailAttachmentTest.java
  
  Index: EmailAttachmentTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/EmailAttachmentTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EmailAttachmentTest.java	29 Oct 2004 11:18:50 -0000	1.4
  +++ EmailAttachmentTest.java	1 Nov 2004 13:54:59 -0000	1.5
  @@ -46,15 +46,14 @@
           this.attachment = new EmailAttachment();
       }
   
  -
       /** */
       public void testGetSetDescription()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.attachment.setDescription( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.attachment.getDescription() );
  +            this.attachment.setDescription(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.attachment.getDescription());
           }
       }
   
  @@ -62,10 +61,10 @@
       public void testGetSetName()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.attachment.setName( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.attachment.getName() );
  +            this.attachment.setName(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.attachment.getName());
           }
       }
   
  @@ -73,35 +72,34 @@
       public void testGetSetPath()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.attachment.setPath( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.attachment.getPath() );
  +            this.attachment.setPath(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.attachment.getPath());
           }
       }
   
       /** */
       public void testGetSetURL()
       {
  -        String[] tests = 
  -        {
  -            "http://localhost/", 
  -            "http://www.apache.org/",
  -            "http://bad.url.com"
  -        };
  +        String[] tests =
  +            {
  +                "http://localhost/",
  +                "http://www.apache.org/",
  +                "http://bad.url.com" };
   
  -        for ( int i = 0; i < tests.length; i++ )
  +        for (int i = 0; i < tests.length; i++)
           {
               try
               {
  -                URL testURL = new URL( tests[ i ] );
  -                this.attachment.setURL( testURL );
  -                assertEquals( testURL, this.attachment.getURL() );
  +                URL testURL = new URL(tests[i]);
  +                this.attachment.setURL(testURL);
  +                assertEquals(testURL, this.attachment.getURL());
               }
  -            catch ( MalformedURLException e )
  +            catch (MalformedURLException e)
               {
                   e.printStackTrace();
  -                continue;   
  +                continue;
               }
           }
       }
  @@ -110,10 +108,10 @@
       public void testGetSetDisposition()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.attachment.setDisposition( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.attachment.getDisposition() );
  +            this.attachment.setDisposition(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.attachment.getDisposition());
           }
       }
   
  
  
  
  1.8       +57 -53    jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/MultiPartEmailTest.java
  
  Index: MultiPartEmailTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/MultiPartEmailTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MultiPartEmailTest.java	29 Oct 2004 11:43:54 -0000	1.7
  +++ MultiPartEmailTest.java	1 Nov 2004 13:55:00 -0000	1.8
  @@ -20,7 +20,6 @@
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.Hashtable;
  -import java.util.Iterator;
   
   import javax.activation.URLDataSource;
   import javax.mail.MessagingException;
  @@ -28,9 +27,6 @@
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.mail.mocks.MockMultiPartEmailConcrete;
   
  -import com.dumbster.smtp.SimpleSmtpServer;
  -import com.dumbster.smtp.SmtpMessage;
  -
   /**
    * JUnit test case for MultiPartEmail Class
    *
  @@ -44,32 +40,31 @@
       private MockMultiPartEmailConcrete email = null;
       /** File to used to test file attachmetns (Must be valid) */
       private File testFile;
  -     
  +
       /**
        * @param name name
        */
  -    public MultiPartEmailTest( String name )
  +    public MultiPartEmailTest(String name)
       {
  -        super( name );
  +        super(name);
       }
  -    
  -   
  -    
  +
       /** */
       protected void setUp()
       {
           super.setUp();
           // reusable objects to be used across multiple tests
           this.email = new MockMultiPartEmailConcrete();
  -        try {
  -            testFile = File.createTempFile("testfile",".txt");
  +        try
  +        {
  +            testFile = File.createTempFile("testfile", ".txt");
           }
  -        catch (IOException ioe){
  +        catch (IOException ioe)
  +        {
               fail(ioe.getMessage());
           }
       }
   
  -    
       /** */
       public void testSetMsg()
       {
  @@ -78,33 +73,33 @@
           // ====================================================================
   
           // without charset set
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
               try
               {
  -                this.email.setMsg( testCharacters[ i ] );
  -                assertEquals( testCharacters[ i ], this.email.getMsg() );
  +                this.email.setMsg(testCharsValid[i]);
  +                assertEquals(testCharsValid[i], this.email.getMsg());
               }
  -            catch ( MessagingException e )
  +            catch (MessagingException e)
               {
                   e.printStackTrace();
  -                fail( "Unexpected exception thrown" );
  +                fail("Unexpected exception thrown");
               }
           }
  -        
  +
           // with charset set
  -        this.email.setCharset( Email.US_ASCII );
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        this.email.setCharset(Email.US_ASCII);
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
               try
               {
  -                this.email.setMsg( testCharacters[ i ] );
  -                assertEquals( testCharacters[ i ], this.email.getMsg() );
  +                this.email.setMsg(testCharsValid[i]);
  +                assertEquals(testCharsValid[i], this.email.getMsg());
               }
  -            catch ( MessagingException e )
  +            catch (MessagingException e)
               {
                   e.printStackTrace();
  -                fail( "Unexpected exception thrown" );
  +                fail("Unexpected exception thrown");
               }
           }
   
  @@ -112,33 +107,37 @@
           // Test Exceptions
           // ====================================================================
           String badTest = null;
  -        try
  +        for (int i = 0; i < testCharsNotValid.length; i++)
           {
  -            this.email.setMsg(badTest);
  -            fail("Should have thrown an exception");
  -        }
  -        catch (MessagingException e)
  -        {
  -            assertTrue(true);
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            fail("Unexpected exception thrown");
  +            try
  +            {
  +                this.email.setMsg(testCharsNotValid[i]);
  +                fail("Should have thrown an exception");
  +            }
  +            catch (MessagingException e)
  +            {
  +                assertTrue(true);
  +            }
  +            catch (Exception e)
  +            {
  +                e.printStackTrace();
  +                fail("Unexpected exception thrown");
  +            }
           }
       }
   
       /** */
  -    public void testSend() throws Exception
  +    public void testSend()
       {
  -        if(fakeMailServer==null || !fakeMailServer.isStopped()){
  -            this.fakeMailServer = SimpleSmtpServer.start(25);
  -        }
           // ====================================================================
           // Test Success
           // ====================================================================
           try
           {
  +            this.getMailServer();
  +
  +            String strSubject = "Test Multipart Send Subject";
  +            
               EmailAttachment attachment = new EmailAttachment();
               attachment.setPath(testFile.getAbsolutePath());
               attachment.setDisposition(EmailAttachment.ATTACHMENT);
  @@ -151,6 +150,7 @@
               testEmail.addTo(this.strTestMailTo);
               testEmail.attach(attachment);
               testEmail.setSubType("subType");
  +
               if (StringUtils.isNotEmpty(this.strTestUser)
                   && StringUtils.isNotEmpty(this.strTestPasswd))
               {
  @@ -159,7 +159,7 @@
                       this.strTestPasswd);
               }
   
  -            testEmail.setSubject("Test Multipart Send Subject");
  +            testEmail.setSubject(strSubject);
   
               testEmail.setMsg("Test Message");
   
  @@ -172,29 +172,33 @@
   
               testEmail.send();
   
  -            assertTrue(fakeMailServer.getReceievedEmailSize() == 1);
  -            Iterator emailIter = fakeMailServer.getReceivedEmail();
  -            SmtpMessage email = (SmtpMessage)emailIter.next();
  -            saveEmailToFile(email);
  -            assertEquals("Test Msg Subject",email.getHeaderValue("Subject"));
  -            //assertEquals("abc123",email.getBody());  
  +            this.fakeMailServer.stop();
  +            assertTrue(validateSend(fakeMailServer, strSubject));
           }
           catch (MessagingException e)
           {
               e.printStackTrace();
               fail("Unexpected exception thrown");
           }
  +        catch (IOException e)
  +        {
  +            e.printStackTrace();
  +            fail("Failed to save email to output file");
  +        }
   
           // ====================================================================
           // Test Exceptions
           // ====================================================================
           try
           {
  +            this.getMailServer();
  +
               this.email.send();
               fail("Should have thrown an exception");
           }
           catch (MessagingException e)
           {
  +            this.fakeMailServer.stop();
               assertTrue(true);
           }
           catch (Exception e)
  @@ -457,10 +461,10 @@
       /** */
       public void testGetSetSubType()
       {
  -        for (int i = 0; i < testCharacters.length; i++)
  +        for (int i = 0; i < testCharsValid.length; i++)
           {
  -            this.email.setSubType(testCharacters[i]);
  -            assertEquals(testCharacters[i], this.email.getSubType());
  +            this.email.setSubType(testCharsValid[i]);
  +            assertEquals(testCharsValid[i], this.email.getSubType());
           }
       }
   }
  
  
  
  1.4       +74 -16    jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/BaseEmailTestCase.java
  
  Index: BaseEmailTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/BaseEmailTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BaseEmailTestCase.java	29 Oct 2004 11:43:54 -0000	1.3
  +++ BaseEmailTestCase.java	1 Nov 2004 13:55:00 -0000	1.4
  @@ -17,7 +17,9 @@
   
   import java.io.File;
   import java.io.FileWriter;
  +import java.io.IOException;
   import java.util.Date;
  +import java.util.Iterator;
   
   import junit.framework.TestCase;
   
  @@ -58,7 +60,7 @@
       /** Where to save email output **/
       private File emailOutputDir;
   
  -    protected String[] testCharacters = 
  +    protected String[] testCharsValid = 
       {
           "", 
           " ", 
  @@ -72,6 +74,9 @@
           null
       };
       
  +    /** Array of test strings */
  +    protected String[] testCharsNotValid = { "", null };    
  +    
       /**
        * @param name name
        */
  @@ -79,35 +84,88 @@
       {
           super(name);
           emailOutputDir = new File("target/test-emails");
  -        if(!emailOutputDir.exists()){
  +        if (!emailOutputDir.exists())
  +        {
               emailOutputDir.mkdirs();
           }
       }
   
  -    /** */
       protected void setUp()
       {
  -        // reusable objects to be used across multiple tests
  -       // if(fakeMailServer==null || fakeMailServer.isStopped()){
  -       //     this.fakeMailServer = SimpleSmtpServer.start(25);
  -       // }
  +
       }
   
       /** */
       protected void tearDown()
       {
  -        // stop the fake email server (if started)
  -       // if (!this.fakeMailServer.isStopped())
  -        //{
  -            //this.fakeMailServer.stop();
  -            //this.fakeMailServer = null;
  -        //}
  +        //stop the fake email server (if started)
  +        if (this.fakeMailServer != null && !this.fakeMailServer.isStopped())
  +        {
  +            this.fakeMailServer.stop();
  +        }
  +
  +        this.fakeMailServer = null;
       }
       
  -    protected void saveEmailToFile(SmtpMessage email) throws Exception{
  -        File emailFile = new File(emailOutputDir,"email" + new Date().getTime()+".txt");
  +    /**
  +     * 
  +     * @param email email
  +     * @throws IOException Exception
  +     */
  +    protected void saveEmailToFile(SmtpMessage email) throws IOException
  +    {
  +        File emailFile =
  +            new File(emailOutputDir, "email" + new Date().getTime() + ".txt");
           FileWriter fw = new FileWriter(emailFile);
           fw.write(email.toString());
           fw.close();
       }
  +    /** */
  +    public void getMailServer()
  +    {
  +        if (this.fakeMailServer == null || this.fakeMailServer.isStopped())
  +        {
  +            this.fakeMailServer =
  +                SimpleSmtpServer.start(EmailConfiguration.MAIL_SERVER_PORT);
  +
  +            Date dtStartWait = new Date();
  +            while (this.fakeMailServer.isStopped())
  +            {
  +                // test for connected
  +                if (this.fakeMailServer != null
  +                    && !this.fakeMailServer.isStopped())
  +                {
  +                    break;
  +                }
  +
  +                // test for timeout
  +                if ((dtStartWait.getTime() + EmailConfiguration.TIME_OUT)
  +                    <= new Date().getTime())
  +                {
  +                    fail("Mail server failed to start");
  +                }
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Validate the message was sent properly
  +     * @param mailServer reference to the fake mail server
  +     * @param strSubject expected subject
  +     * @return boolean true if all is well, false otherwise
  +     * @throws IOException Exception
  +     */
  +    protected boolean validateSend(
  +        SimpleSmtpServer mailServer,
  +        String strSubject)
  +        throws IOException
  +    {
  +        assertTrue(mailServer.getReceievedEmailSize() == 1);
  +        Iterator emailIter = fakeMailServer.getReceivedEmail();
  +        SmtpMessage emailMessage = (SmtpMessage) emailIter.next();
  +
  +        this.saveEmailToFile(emailMessage);
  +
  +        return strSubject.equals(emailMessage.getHeaderValue("Subject"));
  +    }    
   }
  
  
  
  1.4       +18 -8     jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/SimpleEmailTest.java
  
  Index: SimpleEmailTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/SimpleEmailTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleEmailTest.java	29 Oct 2004 11:18:51 -0000	1.3
  +++ SimpleEmailTest.java	1 Nov 2004 13:55:00 -0000	1.4
  @@ -15,6 +15,8 @@
    */
   package org.apache.commons.mail;
   
  +import javax.mail.MessagingException;
  +
   import org.apache.commons.mail.mocks.MockSimpleEmail;
   
   /**
  @@ -24,16 +26,16 @@
   public class SimpleEmailTest extends BaseEmailTestCase
   {
       /** */
  -    private MockSimpleEmail email   = null;
  +    private MockSimpleEmail email = null;
   
       /**
        * @param name name
        */
  -    public SimpleEmailTest( String name )
  +    public SimpleEmailTest(String name)
       {
  -        super( name );
  +        super(name);
       }
  -    
  +
       /** */
       protected void setUp()
       {
  @@ -41,15 +43,23 @@
           // reusable objects to be used across multiple tests
           this.email = new MockSimpleEmail();
       }
  - 
  +
       /** */
       public void testGetSetMsg()
       {
   
  -        for ( int i = 0; i < testCharacters.length; i++ )
  +        try
  +        {
  +            for (int i = 0; i < testCharsValid.length; i++)
  +            {
  +                this.email.setMsg(testCharsValid[i]);
  +                assertEquals(testCharsValid[i], this.email.getMsg());
  +            }
  +        }
  +        catch (MessagingException e)
           {
  -            this.email.setMsg( testCharacters[ i ] );
  -            assertEquals( testCharacters[ i ], this.email.getMsg() );
  +            e.printStackTrace();
  +            fail("Unexpected exception thrown");
           }
       }
   }
  
  
  
  1.11      +8 -5      jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/MultiPartEmail.java
  
  Index: MultiPartEmail.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/MultiPartEmail.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MultiPartEmail.java	29 Oct 2004 10:31:35 -0000	1.10
  +++ MultiPartEmail.java	1 Nov 2004 13:55:02 -0000	1.11
  @@ -142,12 +142,12 @@
       public Email setMsg(String msg) throws MessagingException
       {
           // throw exception on null message
  -        if (msg == null)
  +        if (StringUtils.isEmpty(msg))
           {
               throw new MessagingException("Invalid message supplied");
           }
   
  -        if (charset != null)
  +        if (StringUtils.isNotEmpty(charset))
           {
               getPrimaryBodyPart().setText(msg, charset);
           }
  @@ -382,8 +382,11 @@
           }
           
           // Add the first body part to the message.  The fist body part must be
  -        primaryBodyPart = new MimeBodyPart();
  -        container.addBodyPart(primaryBodyPart);
  +        if (this.primaryBodyPart == null)
  +        {
  +            primaryBodyPart = new MimeBodyPart();
  +            getContainer().addBodyPart(primaryBodyPart);
  +        }
   
           return primaryBodyPart;
       }
  
  
  
  1.7       +18 -7     jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/SimpleEmail.java
  
  Index: SimpleEmail.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/SimpleEmail.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleEmail.java	19 Feb 2004 22:38:09 -0000	1.6
  +++ SimpleEmail.java	1 Nov 2004 13:55:02 -0000	1.7
  @@ -15,6 +15,10 @@
    */
   package org.apache.commons.mail;
   
  +import javax.mail.MessagingException;
  +
  +import org.apache.commons.lang.StringUtils;
  +
   /**
    * This class is used to send simple internet email messages without
    * attachments.
  @@ -30,13 +34,20 @@
   public class SimpleEmail extends Email
   {
       /**
  -      * Set the content of the mail
  -      *
  -      * @param msg A String.
  -      * @return An Email.
  -      */
  -    public Email setMsg(String msg)
  +     * Set the content of the mail
  +     *
  +     * @param msg A String.
  +     * @return An Email.
  +     * @throws MessagingException see javax.mail.internet.MimeBodyPart
  +     *  for defintions
  +     */
  +    public Email setMsg(String msg) throws MessagingException
       {
  +        if (StringUtils.isEmpty(msg))
  +        {
  +            throw new MessagingException("Invalid message supplied");
  +        }
  +
           setContent(msg, TEXT_PLAIN);
           return this;
       }
  
  
  
  1.14      +26 -5     jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java
  
  Index: HtmlEmail.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- HtmlEmail.java	29 Oct 2004 12:05:13 -0000	1.13
  +++ HtmlEmail.java	1 Nov 2004 13:55:02 -0000	1.14
  @@ -77,10 +77,17 @@
        *
        * @param aText A String.
        * @return An HtmlEmail.
  +     * @throws MessagingException see javax.mail.internet.MimeBodyPart
  +     *  for defintions
        */
  -    public HtmlEmail setTextMsg(String aText)
  +    public HtmlEmail setTextMsg(String aText) throws MessagingException
       {
  -        this.text = aText;
  +        if (StringUtils.isEmpty(aText))
  +        {
  +            throw new MessagingException("Invalid message supplied");
  +        }
  +
  +       this.text = aText;
           return this;
       }
   
  @@ -89,9 +96,16 @@
        *
        * @param aHtml A String.
        * @return An HtmlEmail.
  +     * @throws MessagingException see javax.mail.internet.MimeBodyPart
  +     *  for defintions
        */
  -    public HtmlEmail setHtmlMsg(String aHtml)
  +    public HtmlEmail setHtmlMsg(String aHtml) throws MessagingException
       {
  +        if (StringUtils.isEmpty(aHtml))
  +        {
  +            throw new MessagingException("Invalid message supplied");
  +        }
  +        
           this.html = aHtml;
           return this;
       }
  @@ -107,9 +121,16 @@
        *
        * @param msg A String.
        * @return An Email.
  +     * @throws MessagingException see javax.mail.internet.MimeBodyPart
  +     *  for defintions
        */
  -    public Email setMsg(String msg)
  +    public Email setMsg(String msg) throws MessagingException
       {
  +        if (StringUtils.isEmpty(msg))
  +        {
  +            throw new MessagingException("Invalid message supplied");
  +        }
  +
           setTextMsg(msg);
   
           setHtmlMsg(
  
  
  
  1.4       +2 -1      jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/settings/EmailConfiguration.java
  
  Index: EmailConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/email/src/test/org/apache/commons/mail/settings/EmailConfiguration.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EmailConfiguration.java	28 Oct 2004 19:28:03 -0000	1.3
  +++ EmailConfiguration.java	1 Nov 2004 13:55:03 -0000	1.4
  @@ -36,5 +36,6 @@
       /** */
       public static final String TEST_URL =
           "http://www.apache.org/images/asf_logo_wide.gif";
  -
  +    /** Amount of time to wait for Dumbster to start up */
  +    public static final int TIME_OUT = 500;
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message