Source Code Cross Referenced for MailTest.java in  » Content-Management-System » TransferCM » com » methodhead » mail » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » TransferCM » com.methodhead.mail 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright (C) 2006 Methodhead Software LLC.  All rights reserved.
003:         * 
004:         * This file is part of TransferCM.
005:         * 
006:         * TransferCM is free software; you can redistribute it and/or modify it under the
007:         * terms of the GNU General Public License as published by the Free Software
008:         * Foundation; either version 2 of the License, or (at your option) any later
009:         * version.
010:         * 
011:         * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013:         * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
014:         * details.
015:         * 
016:         * You should have received a copy of the GNU General Public License along with
017:         * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018:         * Fifth Floor, Boston, MA  02110-1301  USA
019:         */
020:
021:        package com.methodhead.mail;
022:
023:        import java.util.*;
024:        import java.io.*;
025:        import java.sql.*;
026:        import junit.framework.*;
027:        import org.apache.log4j.*;
028:        import com.methodhead.persistable.*;
029:        import com.methodhead.test.*;
030:        import com.methodhead.*;
031:        import javax.mail.internet.*;
032:        import javax.mail.*;
033:        import org.apache.commons.mail.*;
034:
035:        public class MailTest extends TestCase {
036:
037:            String testRecipient1_ = "test1@methodhead.com";
038:            String testRecipient2_ = "test2@methodhead.com";
039:            Properties props = null;
040:
041:            static {
042:                TestUtils.initLogger();
043:                //TestUtils.setLogLevel( Level.DEBUG );
044:                //TestUtils.initDb();
045:            }
046:
047:            public MailTest(String name) {
048:                super (name);
049:            }
050:
051:            protected void setUp() {
052:                try {
053:                    props = new Properties();
054:                    props.setProperty("mail.host", "localhost");
055:                    props.setProperty("mail.from", "test1@methodhead.com");
056:                    Mail.init(props);
057:                } catch (Exception e) {
058:                    fail(e.getMessage());
059:                }
060:            }
061:
062:            protected void tearDown() {
063:            }
064:
065:            public void testInit() {
066:                try {
067:                    props = new Properties();
068:                    props.setProperty("mail.host", "localhost");
069:
070:                    //
071:                    // should be null by default
072:                    //
073:                    assertNotNull(Mail.mailProperties_);
074:
075:                    //
076:                    // should set mailProperties_
077:                    //
078:                    Mail.init(props);
079:                    assertEquals(props, Mail.mailProperties_);
080:                } catch (Exception e) {
081:                    e.printStackTrace();
082:                    fail();
083:                }
084:            }
085:
086:            public void testIsValidEmailAddress() {
087:                try {
088:                    //
089:                    // invalid from should throw an exception
090:                    //
091:                    assertEquals(false, Mail.isValidAddress(null));
092:                    assertEquals(false, Mail.isValidAddress(""));
093:                    assertEquals(false, Mail.isValidAddress("no reply"));
094:                    assertEquals(false, Mail.isValidAddress("invalid"));
095:                    assertEquals(true, Mail
096:                            .isValidAddress("test1@methodhead.com"));
097:                } catch (Exception e) {
098:                    e.printStackTrace();
099:                    fail();
100:                }
101:            }
102:
103:            public void testSendErrors() {
104:                try {
105:                    //
106:                    // invalid from should throw an exception
107:                    //
108:                    try {
109:                        Mail.send(new String[] { testRecipient1_ }, null,
110:                                "test", "This is a test.");
111:                    } catch (MhfException e) {
112:                        // success
113:                    }
114:
115:                    try {
116:                        Mail.send(new String[] { testRecipient1_ }, "no reply",
117:                                "test", "This is a test.");
118:                    } catch (MhfException e) {
119:                        // success
120:                    }
121:                } catch (Exception e) {
122:                    e.printStackTrace();
123:                    fail();
124:                }
125:            }
126:
127:            public void testSend() {
128:                try {
129:                    //
130:                    // send a simple message to one recipient
131:                    //
132:                    Mail.send(new String[] { testRecipient1_ },
133:                            "noreply@danhensgen.com",
134:                            "testSend() - single recipient", "This is a test.");
135:
136:                    //
137:                    // send a simple message to two recipients
138:                    //
139:                    Mail.send(
140:                            new String[] { testRecipient1_, testRecipient2_ },
141:                            "noreply@danhensgen.com",
142:                            "testSend() - multiple recipients",
143:                            "This is a test.");
144:
145:                    //
146:                    // send a simple message to two recipients, one of them invalid; should
147:                    // send successfully to valid recipient
148:                    //
149:                    Mail
150:                            .send(
151:                                    new String[] { testRecipient1_,
152:                                            "invalid address" },
153:                                    "noreply@danhensgen.com",
154:                                    "testSend() - multiple recipients, one invalid",
155:                                    "This is a test.");
156:                } catch (Exception e) {
157:                    e.printStackTrace();
158:                    fail();
159:                }
160:            }
161:
162:            public void testSendSingleAddress() {
163:                try {
164:                    //
165:                    // send a simple message to one recipient
166:                    //
167:                    Mail.send(testRecipient1_, "noreply@danhensgen.com",
168:                            "testSend() - single recipient (no array)",
169:                            "This is a test.");
170:                } catch (Exception e) {
171:                    e.printStackTrace();
172:                    fail();
173:                }
174:            }
175:
176:            public void testSendHtml() {
177:                try {
178:                    //
179:                    // send a simple message with both text and html to one recipient
180:                    //
181:                    Mail.send(new String[] { testRecipient1_ },
182:                            "noreply@danhensgen.com",
183:                            "testSend() - html, single recipient",
184:                            "This is a test.", "This is a <b>test</b>.");
185:
186:                    //
187:                    // send a simple message to two recipients
188:                    //
189:                    Mail.send(
190:                            new String[] { testRecipient1_, testRecipient2_ },
191:                            "noreply@danhensgen.com",
192:                            "testSend() - html, multiple recipients",
193:                            "This is a test.", "This is a <b>test</b>.");
194:
195:                    //
196:                    // send a simple message to two recipients, one of them invalid; should
197:                    // send successfully to valid recipient
198:                    //
199:                    Mail
200:                            .send(
201:                                    new String[] { testRecipient1_,
202:                                            "invalid address" },
203:                                    "noreply@danhensgen.com",
204:                                    "testSend() - html, multiple recipients, one invalid",
205:                                    "This is a test.", "This is a <b>test</b>.");
206:                } catch (Exception e) {
207:                    e.printStackTrace();
208:                    fail();
209:                }
210:            }
211:
212:            public void testSendWithAttachmentsErrors() {
213:                try {
214:                    //
215:                    // invalid from should throw an exception
216:                    //
217:                    try {
218:                        Mail.send(new String[] { testRecipient1_ }, null,
219:                                "test", "This is a test.");
220:                    } catch (MhfException e) {
221:                        // success
222:                    }
223:
224:                    try {
225:                        Mail.send(new String[] { testRecipient1_ }, "no reply",
226:                                "test", "This is a test.");
227:                    } catch (MhfException e) {
228:                        // success
229:                    }
230:
231:                    //
232:                    // null attachment list should throw an exception
233:                    //
234:                    try {
235:                        Mail.send(new String[] { testRecipient1_ },
236:                                "noreply@danhensgen.com", "test",
237:                                "This is a test.", (File[]) null);
238:                    } catch (MhfException e) {
239:                        // success
240:                    }
241:
242:                    //
243:                    // null attachment should throw an exception
244:                    //
245:                    try {
246:                        Mail.send(new String[] { testRecipient1_ },
247:                                "noreply@danhensgen.com", "test",
248:                                "This is a test.", new File[] { null });
249:                    } catch (MhfException e) {
250:                        // success
251:                    }
252:
253:                    //
254:                    // non-existant attachment should throw an exception
255:                    //
256:                    try {
257:                        Mail.send(new String[] { testRecipient1_ },
258:                                "noreply@danhensgen.com", "test",
259:                                "This is a test.", new File[] { new File(
260:                                        "invalidFile.txt") });
261:                    } catch (MhfException e) {
262:                        // success
263:                    }
264:                } catch (Exception e) {
265:                    e.printStackTrace();
266:                    fail();
267:                }
268:            }
269:
270:            public void testSendWithAttachments() {
271:                try {
272:                    //
273:                    // send a message to one recipient with one attachment
274:                    //
275:                    Mail
276:                            .send(
277:                                    new String[] { testRecipient1_ },
278:                                    "noreply@danhensgen.com",
279:                                    "testSendWithAttachments() - single recipient, single attachment",
280:                                    "This is a test.", new File[] { new File(
281:                                            "support/image1.jpg") });
282:
283:                    //
284:                    // send a message to one recipient with two attachments
285:                    //
286:                    Mail
287:                            .send(
288:                                    new String[] { testRecipient1_ },
289:                                    "noreply@danhensgen.com",
290:                                    "testSendWithAttachments() - single recipient, two attachments",
291:                                    "This is a test.", new File[] {
292:                                            new File("support/image1.jpg"),
293:                                            new File("support/image2.jpg") });
294:
295:                    //
296:                    // send a message to two recipients with one attachment
297:                    //
298:                    Mail
299:                            .send(
300:                                    new String[] { testRecipient1_,
301:                                            testRecipient2_ },
302:                                    "noreply@danhensgen.com",
303:                                    "testSendWithAttachments() - two recipients, one attachment",
304:                                    "This is a test.", new File[] { new File(
305:                                            "support/image1.jpg") });
306:                } catch (Exception e) {
307:                    e.printStackTrace();
308:                    fail();
309:                }
310:            }
311:
312:            public void testSendHtmlWithAttachments() {
313:                try {
314:                    //
315:                    // send a message to one recipient with one attachment
316:                    //
317:                    Mail
318:                            .send(
319:                                    new String[] { testRecipient1_ },
320:                                    "noreply@danhensgen.com",
321:                                    "testSendWithAttachments() - html, single recipient, single attachment",
322:                                    "This is a test.",
323:                                    "This is a <b>test</b>.",
324:                                    new File[] { new File("support/image1.jpg") });
325:
326:                    //
327:                    // send a message to one recipient with two attachments
328:                    //
329:                    Mail
330:                            .send(
331:                                    new String[] { testRecipient1_ },
332:                                    "noreply@danhensgen.com",
333:                                    "testSendWithAttachments() - single recipient, two attachments",
334:                                    "This is a test.", new File[] {
335:                                            new File("support/image1.jpg"),
336:                                            new File("support/image2.jpg") });
337:
338:                    //
339:                    // send a message to two recipients with one attachment
340:                    //
341:                    Mail
342:                            .send(
343:                                    new String[] { testRecipient1_,
344:                                            testRecipient2_ },
345:                                    "noreply@danhensgen.com",
346:                                    "testSendWithAttachments() - two recipients, one attachment",
347:                                    "This is a test.", new File[] { new File(
348:                                            "support/image1.jpg") });
349:                } catch (Exception e) {
350:                    e.printStackTrace();
351:                    fail();
352:                }
353:            }
354:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.