1
2
3
4
5
6
7
8 /
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public class MailSystemTest extends LedgeTestCase
55 {
56 private FileSystem fs = null;
57
58 private MailSystem mailSystem;
59
60 public void setUp()
61 throws Exception
62 {
63 super.setUp();
64 fs = getFileSystem();
65 Logger logger = new Log4JLogger(org.apache.log4j.Logger.getLogger(MailSystem.class));
66 Configuration config =
67 getConfig("config/org.objectledge.templating.velocity.VelocityTemplating.xml");
68 Templating templating = new VelocityTemplating(config, logger, fs);
69 Context context = new Context();
70 config = getConfig("config/org.objectledge.threads.ThreadPool.xml");
71 ThreadPool threadPool = new ThreadPool(null, context,config, logger);
72 config = getConfig("config/org.objectledge.mail.MailSystem.xml");
73 checkSchema(
74 "config/org.objectledge.mail.MailSystem.xml","org/objectledge/mail/MailSystem.rng");
75 mailSystem = new MailSystem(config, logger, fs, templating, threadPool);
76 }
77
78
79 public void testMailSystem()
80 {
81 assertNotNull(mailSystem);
82 }
83
84
85
86
87 public void testGetSession()
88 {
89 assertNotNull(mailSystem.getSession());
90 }
91
92
93
94
95 public void testGetSessionString()
96 {
97 assertNull(mailSystem.getSession("foo"));
98 }
99
100 public void testGetDataSource()
101 {
102 DataSource ds = mailSystem.getDataSource("foo");
103 assertNotNull(ds);
104 }
105
106
107
108
109 public void testNewMessage() throws Exception
110 {
111 LedgeMessage message = mailSystem.newMessage();
112 assertNotNull(message);
113 Session session = mailSystem.getSession();
114 Message msg = new MimeMessage(session);
115 message.setMessage(msg);
116 assertEquals(msg, message.getMessage());
117 message = mailSystem.newMessage();
118 message.setText("foo");
119 message.setEncoding("ISO-8859-2");
120 message.prepare();
121 msg = message.getMessage();
122 assertEquals("foo",msg.getContent());
123 assertEquals("text/plain; charset=ISO-8859-2",msg.getContentType());
124
125 message = mailSystem.newMessage();
126 message.setTemplate(new Locale("pl","PL"), "PLAIN", "Foo");
127 TemplatingContext context = message.getContext();
128 context = message.getContext();
129 assertNotNull(context);
130 context.put("foo","bar");
131 message.prepare();
132 msg = message.getMessage();
133 assertEquals("foo=bar",msg.getContent());
134
135 message = mailSystem.newMessage();
136 assertEquals(0, message.getAttachments().size());
137 assertEquals(0, message.getRelatedContent().size());
138 }
139
140
141
142
143 public void testNewMessageString()
144 {
145 LedgeMessage message = mailSystem.newMessage("foo");
146 assertNotNull(message);
147 }
148
149 public void testSend()
150 throws Exception
151 {
152 LedgeMessage message = mailSystem.newMessage();
153 try
154 {
155 mailSystem.send(message, true);
156 fail("shoild throw the exception");
157 }
158 catch(MessagingException e)
159 {
160
161 }
162 }
163
164 public void testGetContentType()
165 {
166 assertEquals("text/html", mailSystem.getContentType("foo.html"));
167 assertEquals("application/octet-stream", mailSystem.getContentType("xxx.xxx"));
168 }
169
170 public void testIsValidEmailAddress()
171 {
172 assertEquals(true, mailSystem.isValidEmailAddress("foo@bar.foo"));
173 assertEquals(false, mailSystem.isValidEmailAddress("foo@bar_foo"));
174 }
175
176 private Configuration getConfig(String name)
177 throws Exception
178 {
179 return getConfig(fs, name);
180 }
181
182 }