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.api.CoreApiServiceLocator;
23  import org.kuali.rice.core.api.mail.EmailBody;
24  import org.kuali.rice.core.api.mail.EmailFrom;
25  import org.kuali.rice.core.api.mail.EmailSubject;
26  import org.kuali.rice.core.api.mail.EmailTo;
27  import org.kuali.rice.core.api.mail.Mailer;
28  import org.kuali.rice.kew.service.KEWServiceLocator;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  import org.subethamail.wiser.Wiser;
31  
32  /**
33   * Tests email content generation
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  public class MailerTest extends KEWTestCase {
37      
38      private String sender = "testSender@test.kuali.org";
39      private String recipient = "testRecipient@test.kuali.org";
40      private String subject = "Test Subject";
41      private String messageBody = "Test Message Body";
42      
43  	/**
44  	 * Test that a Mailer can be retrieved via the KEWServiceLocator and can be used 
45  	 * to send an e-mail message to the SMTP server.
46  	 */
47  	@Test
48  	public void testSendMessage() {
49  		// Initialize SMTP server
50  		Wiser smtpServer = new Wiser();
51  		smtpServer.setPort(55000);
52  		smtpServer.start();
53  		
54  		// Test that a Mailer can be retrieved via the KEWServiceLocator
55  		Mailer mailer = null;
56  		mailer = CoreApiServiceLocator.getMailer();
57  		assertNotNull(mailer);
58  		
59  		// Test that an e-mail message gets sent to the SMTP server
60  		mailer.sendEmail(new EmailFrom(sender), new EmailTo(recipient), new EmailSubject(subject), new EmailBody(messageBody), false);
61  		Assert.assertEquals(1, smtpServer.getMessages().size());
62  
63          // Shutdown the SMTP server
64          smtpServer.stop();        
65  	}    
66  
67  }