SummaryTest.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 2k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Class created on Jul 15, 2005
  3.  */ 
  4. package net.jforum.summary;
  5. import java.util.Calendar;
  6. import java.util.Collection;
  7. import java.util.Date;
  8. import java.util.Iterator;
  9. import java.util.List;
  10. import junit.framework.TestCase;
  11. import net.jforum.TestCaseUtils;
  12. import net.jforum.entities.Post;
  13. import org.quartz.SchedulerException;
  14. /**
  15.  * Test case for SummaryScheduler.
  16.  * 
  17.  * @see net.jforum.summary.SummaryScheduler
  18.  * 
  19.  * @author Franklin S. Dattein (<a href="mailto:franklin@hp.com">franklin@hp.com</a>)
  20.  *
  21.  */
  22. public class SummaryTest extends TestCase {
  23.     
  24.     protected void setUp() throws Exception {
  25.         super.setUp();
  26.         TestCaseUtils.loadEnvironment();
  27.         TestCaseUtils.initDatabaseImplementation();
  28.     }
  29.     /**
  30.      * Tests only the scheduler and your frquency.
  31.      * @throws Exception 
  32.      *
  33.      */
  34.     public void testScheduler() throws Exception{
  35.                     
  36.         try {
  37.             SummaryScheduler.startJob();
  38.         } catch (SchedulerException e) {
  39.             e.printStackTrace();
  40.         }        
  41.     }
  42.     
  43.     public void testLoadRecipients() throws Exception{                         
  44.         SummaryModel model = new SummaryModel();
  45.         Iterator iter = model.listRecipients().iterator();
  46.         while (iter.hasNext()) {            
  47.             System.out.println(iter.next());            
  48.         }
  49.         assertTrue(model.listRecipients().size()>0);       
  50.     }
  51.     
  52.     public void testSendMails() throws Exception{
  53.         SummaryModel model = new SummaryModel();
  54.       //Do not uncommentuse this at least you want to send e-mails to all users.
  55.         List recipients = model.listRecipients();
  56.         //List recipients = new ArrayList(1);
  57.         //recipients.add("franklin@hp.com");
  58.         
  59.         model.sendPostsSummary(recipients);
  60.        
  61.     }
  62.     
  63.     public void testListPosts() throws Exception{       
  64.         SummaryModel model= new SummaryModel();
  65. //      Gets a Date seven days before now
  66.         long weekBefore = Calendar.getInstance().getTimeInMillis() - (7 * 1000 * 60 * 60 * 24);
  67.         Date firstDate = new Date(weekBefore);
  68.         System.out.println(firstDate);
  69.         Collection posts = model.listPosts(firstDate,new Date());
  70.         Iterator iter = posts.iterator();
  71.         while (iter.hasNext()) {
  72.             Post post = (Post) iter.next();
  73.             System.out.println(post.getSubject());
  74.             
  75.         }
  76.         assertTrue(posts.size()>0);
  77.         
  78.     }
  79. }