View Javadoc

1   package org.kuali.ole.deliver;
2   
3   import org.junit.Test;
4   import org.junit.runner.RunWith;
5   import org.kuali.rice.core.api.CoreApiServiceLocator;
6   import org.kuali.rice.core.api.mail.*;
7   import org.springframework.test.context.ContextConfiguration;
8   import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9   import org.springframework.test.context.transaction.TransactionConfiguration;
10  
11  import static org.junit.Assert.assertNotNull;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: peris
16   * Date: 12/4/12
17   * Time: 12:38 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
21  @RunWith(value = SpringJUnit4ClassRunner.class)
22  @TransactionConfiguration(defaultRollback = true)
23  public class MailNotifier_UT  {
24      private String sender = "kuali.ole@gmail.com";
25      private String recipient = "kuali.ole@gmail.com";
26      private String subject = "Test Subject";
27      private String messageBody = "Test Message Body";
28  
29      /**
30       * Test that a Mailer can be retrieved via the KEWServiceLocator and can be used
31       * to send an e-mail message to the SMTP server.
32       */
33      @Test
34      public void testSendMessage() {
35          // Test that a Mailer can be retrieved via the KEWServiceLocator
36          Mailer mailer = null;
37          mailer = CoreApiServiceLocator.getMailer();
38          assertNotNull(mailer);
39  
40          // Test that an e-mail message gets sent to the SMTP server
41          mailer.sendEmail(new EmailFrom(sender), new EmailTo(recipient), new EmailSubject(subject), new EmailBody(messageBody), false);
42  
43          //Typically we need to verify if the mail was received; and Wiser a java class under the subethamail.jar will act as a fake SMTP server to receive messages;
44          //But sine we are are using gmail to test our message sending, it wont work here as it expects messages to be sent to the local default mail server listening on port 25.
45          //This is just an illustration so could live with manually verifying if the test works. Eventually we need to fix the test case with a proper assert.
46  
47      }
48  
49  }