Source Code Cross Referenced for EmailTest.java in  » Workflow-Engines » Dalma » test » 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 » Workflow Engines » Dalma » test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test;
002:
003:        import dalma.ReplyIterator;
004:        import dalma.endpoints.email.EmailEndPoint;
005:        import dalma.endpoints.email.NewMailHandler;
006:        import dalma.endpoints.email.MimeMessageEx;
007:        import dalma.test.WorkflowTestProgram;
008:        import junit.textui.TestRunner;
009:
010:        import javax.mail.Message;
011:        import javax.mail.MessagingException;
012:        import javax.mail.internet.InternetAddress;
013:        import javax.mail.internet.MimeMessage;
014:        import java.io.Serializable;
015:        import java.util.UUID;
016:
017:        /**
018:         * @author Kohsuke Kawaguchi
019:         */
020:        public class EmailTest extends WorkflowTestProgram {
021:
022:            public EmailTest(String name) {
023:                super (name);
024:            }
025:
026:            public static void main(String[] args) throws Exception {
027:                TestRunner.run(EmailTest.class);
028:            }
029:
030:            EmailEndPoint ep1;
031:            EmailEndPoint ep2;
032:
033:            protected void setupEndPoints() throws Exception {
034:                // passive side
035:                ep1 = (EmailEndPoint) engine.addEndPoint("email1",
036:                        getProperty("email.endpoint1"));
037:                ep1.setNewMailHandler(new NewMailHandler() {
038:                    public void onNewMail(MimeMessage mail) throws Exception {
039:                        System.out.println("new e-mail");
040:                        createConversation(Bob.class, ep1, mail);
041:                    }
042:                });
043:
044:                // active side
045:                ep2 = (EmailEndPoint) engine.addEndPoint("email2",
046:                        getProperty("email.endpoint2"));
047:            }
048:
049:            public void test() throws Throwable {
050:                for (int i = 0; i < 10; i++)
051:                    createConversation(Alice.class, ep2, ep1.getAddress());
052:                engine.waitForCompletion();
053:            }
054:
055:            public static final class Alice implements  Runnable, Serializable {
056:                private final EmailEndPoint ep;
057:                private final InternetAddress adrs;
058:
059:                public Alice(EmailEndPoint ep, InternetAddress adrs) {
060:                    this .ep = ep;
061:                    this .adrs = adrs;
062:                }
063:
064:                public void run() {
065:                    try {
066:                        UUID uuid = UUID.randomUUID();
067:
068:                        System.out.println("A: initiating conversation. UUID="
069:                                + uuid);
070:
071:                        // ep2 -> ep1 to iniciate a conversation
072:                        MimeMessage msg = new MimeMessageEx(ep.getSession());
073:                        msg.setRecipient(Message.RecipientType.TO, adrs);
074:                        msg.setSubject("new conv");
075:                        msg.setText(uuid.toString());
076:                        msg = ep.waitForReply(msg);
077:                        System.out.println("A: got a reply");
078:
079:                        // send multiple replies
080:                        for (int i = 0; i < 10; i++) {
081:                            MimeMessage reply = (MimeMessage) msg.reply(false);
082:                            reply.setText(uuid.toString());
083:                            System.out.println("A: sending a reply");
084:                            ep.send(reply);
085:                        }
086:
087:                        // and finally say bye
088:                        System.out.println("A: sending bye");
089:                        MimeMessage reply = (MimeMessage) msg.reply(false);
090:                        reply.setText("bye");
091:                        ep.send(reply);
092:
093:                        System.out.println("A: exiting");
094:                    } catch (MessagingException e) {
095:                        e.printStackTrace();
096:                    }
097:                }
098:            }
099:
100:            public static final class Bob implements  Runnable, Serializable {
101:                private final EmailEndPoint ep;
102:
103:                // initial e-mail
104:                private MimeMessage email;
105:
106:                public Bob(EmailEndPoint ep, MimeMessage email) {
107:                    this .ep = ep;
108:                    this .email = email;
109:                }
110:
111:                public void run() {
112:                    try {
113:                        MimeMessage msg = email;
114:
115:                        UUID uuid = UUID.fromString(msg.getContent().toString()
116:                                .trim());
117:                        System.out.println("B: started " + uuid);
118:
119:                        msg = (MimeMessage) msg.reply(false);
120:                        msg.setText("welcome");
121:
122:                        ReplyIterator<MimeMessage> itr = ep
123:                                .waitForMultipleReplies(msg);
124:                        while (itr.hasNext()) {
125:                            MimeMessage in = itr.next();
126:                            if (in.getContent().toString().contains("bye"))
127:                                break;
128:
129:                            // make sure that the UUID matches
130:                            assertEquals(uuid, UUID.fromString(in.getContent()
131:                                    .toString().trim()));
132:
133:                            System.out.println("B: got a reply.");
134:                        }
135:
136:                        System.out.println("B: done");
137:                    } catch (Exception e) {
138:                        e.printStackTrace();
139:                    }
140:                }
141:
142:                private static final long serialVersionUID = 1L;
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.