1
2
3
4
5
6
7
8
9 package org.sourceforge.vlibrary.user.workers;
10
11 import junit.framework.TestCase;
12
13 import org.apache.log4j.Logger;
14 import org.sourceforge.vlibrary.TestUtils;
15 import org.sourceforge.vlibrary.user.domain.Book;
16 import org.sourceforge.vlibrary.user.domain.Reader;
17 import org.springframework.beans.factory.BeanFactory;
18 import org.springframework.context.support.ClassPathXmlApplicationContext;
19
20 public class MailWorkerTest extends TestCase {
21 BeanFactory context;
22
23 private static Logger logger =
24 Logger.getLogger(MailWorkerTest.class.getName());
25
26
27 protected DelegatingSimpleSmtpServer server = null;
28
29
30 protected MailWorker mailWorker = null;
31
32
33 private Reader possessor = new Reader(
34 "Schmoe",
35 "Joe",
36 "joe@schmoe.net",
37 "4801234567890",
38 "6021234567890",
39 "123",
40 "TheExplorer",
41 "12345",
42 "guid12345",
43 "sasasas",
44 true);
45
46 private Reader requestor = new Reader(
47 "Schmoe",
48 "Moe",
49 "moe@schmoe.net",
50 "4801234567890",
51 "6021234567890",
52 "123",
53 "TheExplorer",
54 "12345",
55 "guid12346",
56 "asasas",
57 true);
58
59 private Reader reader = new Reader(
60 "Schmoe",
61 "Moe",
62 "moe@schmoe.net",
63 "4801234567890",
64 "6021234567890",
65 "123",
66 "TheExplorer",
67 "12345",
68 "guid12345",
69 "asasasa",
70 true);
71
72
73 private Book book = new Book( "Greatest Book", 0, "Wrox", "10102001",
74 "10102001", 101, "1111");
75
76
77 public MailWorkerTest(String testName) {
78 super(testName);
79 }
80
81 protected void setUp() throws Exception {
82 context =
83 new ClassPathXmlApplicationContext("/lightweightcontainer.xml");
84 server = MailSenderTest.newMockSmtpServer(2500);
85 mailWorker =
86 (MailWorker)context.getBean("MailWorker", MailWorker.class);
87 logger.info("dumbster contents before test");
88 TestUtils.logMessages(server.getDelegate(), logger);
89
90 }
91
92 protected void tearDown() throws Exception {
93 super.tearDown();
94 logger.info("dumbster contents after test");
95 TestUtils.logMessages(server.getDelegate(), logger);
96 server.stop();
97 }
98
99 public void testSendRequestConfirmation() throws Exception {
100 logger.info("testSendRequestConfirmation");
101 mailWorker.sendRequestConfirmation(possessor, requestor, book, "Main");
102 logger.info("testSendRequestConfirmation sent request");
103
104 TestUtils.checkMessage(
105 server,
106 "moe@schmoe.net",
107 "Virtual Library Request Confirmation",
108 "Your request for Greatest Book has been sent to Joe Schmoe");
109
110 logger.info("testSendRequestConfirmation checked message ");
111 }
112
113 public void testSendRequestNotification() throws Exception {
114 logger.info("testSendRequestNotification");
115 mailWorker.sendRequestNotification(possessor, requestor, book, "Main");
116
117 TestUtils.checkMessage(
118 server,
119 "joe@schmoe.net",
120 "Virtual Library Request for: Greatest Book",
121 "Moe Schmoe has requested Greatest Book, which (we think) you have.");
122 }
123
124 public void testSendReturnNotification() throws Exception {
125 logger.info("testSendReturnNotification");
126 mailWorker.sendReturnNotification(reader, book, "Main");
127
128 TestUtils.checkMessage(
129 server,
130 "moe@schmoe.net",
131 "Greatest Book is available for pickup at the Main location",
132 "");
133 }
134
135 public void testSendDeleteConfirmation() throws Exception {
136 logger.info("testSendDeleteConfirmation");
137 mailWorker.sendDeleteConfirmation(reader, book);
138
139 TestUtils.checkMessage(
140 server,
141 "moe@schmoe.net",
142 "Your request for Greatest Book has been deleted",
143 "");
144 }
145
146 public void testSendCheckoutNotification() throws Exception {
147 logger.info("testSendCheckoutNotification");
148 mailWorker.sendCheckoutNotification(possessor, requestor, book, "Main");
149
150 TestUtils.checkMessage(
151 server,
152 "joe@schmoe.net",
153 "Moe Schmoe has checked out Greatest Book",
154 "You are getting this message because you have a pending request");
155 }
156
157 }