View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.mail;
17  
18  import static org.junit.Assert.assertNotNull;
19  import junit.framework.Assert;
20  
21  import org.junit.Test;
22  import org.kuali.rice.core.mail.EmailBody;
23  import org.kuali.rice.core.mail.EmailFrom;
24  import org.kuali.rice.core.mail.EmailSubject;
25  import org.kuali.rice.core.mail.EmailTo;
26  import org.kuali.rice.core.mail.Mailer;
27  import org.kuali.rice.kew.service.KEWServiceLocator;
28  import org.kuali.rice.kew.test.KEWTestCase;
29  import org.subethamail.wiser.Wiser;
30  
31  /**
32   * Tests email content generation
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  public class MailerTest extends KEWTestCase {
36      
37      private String sender = "testSender@test.kuali.org";
38      private String recipient = "testRecipient@test.kuali.org";
39      private String subject = "Test Subject";
40      private String messageBody = "Test Message Body";
41      
42  	/**
43  	 * Test that a Mailer can be retrieved via the KEWServiceLocator and can be used 
44  	 * to send an e-mail message to the SMTP server.
45  	 */
46  	@Test
47  	public void testSendMessage() {
48  		// Initialize SMTP server
49  		Wiser smtpServer = new Wiser();
50  		smtpServer.setPort(55000);
51  		smtpServer.start();
52  		
53  		// Test that a Mailer can be retrieved via the KEWServiceLocator
54  		Mailer mailer = null;
55  		mailer = KEWServiceLocator.getMailer();
56  		assertNotNull(mailer);
57  		
58  		// Test that an e-mail message gets sent to the SMTP server
59  		mailer.sendEmail(new EmailFrom(sender), new EmailTo(recipient), new EmailSubject(subject), new EmailBody(messageBody), false);
60  		Assert.assertEquals(1, smtpServer.getMessages().size());
61  
62          // Shutdown the SMTP server
63          smtpServer.stop();        
64  	}    
65  
66  }