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