Source Code Cross Referenced for LinearProcessorTest.java in  » Web-Mail » james-2.3.1 » org » apache » james » transport » 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 » Web Mail » james 2.3.1 » org.apache.james.transport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /****************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one   *
003:         * or more contributor license agreements.  See the NOTICE file *
004:         * distributed with this work for additional information        *
005:         * regarding copyright ownership.  The ASF licenses this file   *
006:         * to you under the Apache License, Version 2.0 (the            *
007:         * "License"); you may not use this file except in compliance   *
008:         * with the License.  You may obtain a copy of the License at   *
009:         *                                                              *
010:         *   http://www.apache.org/licenses/LICENSE-2.0                 *
011:         *                                                              *
012:         * Unless required by applicable law or agreed to in writing,   *
013:         * software distributed under the License is distributed on an  *
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015:         * KIND, either express or implied.  See the License for the    *
016:         * specific language governing permissions and limitations      *
017:         * under the License.                                           *
018:         ****************************************************************/package org.apache.james.transport;
019:
020:        import org.apache.avalon.framework.logger.ConsoleLogger;
021:        import org.apache.avalon.framework.logger.Logger;
022:        import org.apache.james.core.MailImpl;
023:        import org.apache.james.core.MimeMessageCopyOnWriteProxy;
024:        import org.apache.james.core.MimeMessageInputStreamSource;
025:        import org.apache.james.test.mock.james.MockSpoolRepository;
026:        import org.apache.james.test.mock.mailet.MockMailContext;
027:        import org.apache.james.test.mock.mailet.MockMailetConfig;
028:        import org.apache.james.transport.mailets.debug.DumpSystemErr;
029:        import org.apache.james.transport.matchers.All;
030:        import org.apache.james.transport.matchers.RecipientIs;
031:        import org.apache.mailet.GenericMailet;
032:        import org.apache.mailet.Mail;
033:        import org.apache.mailet.MailAddress;
034:        import org.apache.mailet.Mailet;
035:        import org.apache.mailet.MailetConfig;
036:        import org.apache.mailet.MailetContext;
037:        import org.apache.mailet.Matcher;
038:        import org.apache.mailet.MatcherConfig;
039:
040:        import javax.mail.MessagingException;
041:        import javax.mail.internet.MimeMessage;
042:        import javax.mail.util.SharedByteArrayInputStream;
043:
044:        import java.io.IOException;
045:        import java.util.ArrayList;
046:        import java.util.Collection;
047:
048:        import junit.framework.TestCase;
049:
050:        /**
051:         * Currently here as a proof of JAMES-421.
052:         * Fixing code will follow
053:         */
054:        public class LinearProcessorTest extends TestCase {
055:            Collection c;
056:            LinearProcessor t;
057:            MimeMessage mw = null;
058:            String content = "Subject: test\r\nContent-Transfer-Encoding: plain";
059:            String sep = "\r\n\r\n";
060:            String body = "original body\r\n.\r\n";
061:            MailetContext mockContext = new MockMailContext();
062:
063:            public static int counter = 0;
064:
065:            private class CheckerMailet extends GenericMailet {
066:
067:                public ArrayList receivedMails = new ArrayList();
068:
069:                public void service(Mail mail) throws MessagingException {
070:                    Mail m2 = new MailImpl(mail, mail.getName());
071:                    m2.setState(mail.getState());
072:                    receivedMails.add(m2);
073:                }
074:
075:            }
076:
077:            private MailetConfig mockMailetConfig = new MockMailetConfig(
078:                    "Dummy", mockContext);
079:
080:            private CheckerMailet checkerMailet;
081:
082:            private class MyMailet extends GenericMailet {
083:
084:                public void service(Mail mail) throws MessagingException {
085:                    try {
086:                        MimeMessage message = mail.getMessage();
087:                        //Set the header name and value (supplied at init time).
088:                        String newText = "new text " + counter++;
089:                        System.err.println("Setting body to " + newText);
090:                        message.addHeader("x-Header", newText);
091:                        message.setText(newText);
092:                        message.setSubject(newText);
093:                        message.saveChanges();
094:                    } catch (javax.mail.MessagingException me) {
095:                        log(me.getMessage());
096:                    }
097:                }
098:            }
099:
100:            public LinearProcessorTest(String arg0) throws Exception {
101:                super (arg0);
102:
103:                MimeMessageInputStreamSource mmis = null;
104:                try {
105:                    mmis = new MimeMessageInputStreamSource("test",
106:                            new SharedByteArrayInputStream(
107:                                    (content + sep + body).getBytes()));
108:                } catch (MessagingException e) {
109:                }
110:                mw = new MimeMessageCopyOnWriteProxy(mmis);
111:                setUp();
112:            }
113:
114:            private class DummyMatcherConfig implements  MatcherConfig {
115:                private String condition;
116:
117:                public DummyMatcherConfig(String config) {
118:                    this .condition = config;
119:                }
120:
121:                public String getCondition() {
122:                    return condition;
123:                }
124:
125:                public MailetContext getMailetContext() {
126:                    return mockContext;
127:                }
128:
129:                public String getMatcherName() {
130:                    return "All";
131:                }
132:            }
133:
134:            public void testCopyOnWrite() throws IOException,
135:                    MessagingException {
136:                t.setSpool(new MockSpoolRepository());
137:                Matcher recipientIs = new RecipientIs();
138:                recipientIs.init(new DummyMatcherConfig("rec1@domain.com"));
139:
140:                Matcher all = new All();
141:                all.init(new DummyMatcherConfig(""));
142:
143:                Mailet changeBody = new MyMailet();
144:                Mailet changeBody2 = new MyMailet();
145:
146:                changeBody.init(mockMailetConfig);
147:                changeBody2.init(mockMailetConfig);
148:
149:                Mailet dumpSystemErr = new DumpSystemErr();
150:                changeBody.init(mockMailetConfig);
151:
152:                checkerMailet = new CheckerMailet();
153:                t.add(recipientIs, changeBody);
154:                t.add(all, changeBody);
155:                t.add(all, dumpSystemErr);
156:                t.add(all, checkerMailet);
157:                t.closeProcessorLists();
158:
159:                Collection recipients = new ArrayList();
160:                recipients.add(new MailAddress("rec1", "domain.com"));
161:                recipients.add(new MailAddress("rec2", "domain.com"));
162:                try {
163:                    MailImpl m = new MailImpl("mail1", new MailAddress(
164:                            "sender", "domain.com"), recipients, mw);
165:                    t.service(m);
166:                    ArrayList a = checkerMailet.receivedMails;
167:                    assertEquals(2, a.size());
168:                    MimeMessage m1 = ((Mail) a.get(0)).getMessage();
169:                    MimeMessage m2 = ((Mail) a.get(1)).getMessage();
170:                    assertNotSame(m1, m2);
171:                    assertEquals(m1.getSubject(), "new text 1");
172:                    assertEquals(m2.getSubject(), "new text 2");
173:                    m.dispose();
174:                } catch (MessagingException e) {
175:                    // TODO Auto-generated catch block
176:                    e.printStackTrace();
177:                }
178:            }
179:
180:            public void testStateChange() throws IOException,
181:                    MessagingException {
182:                t.setSpool(new MockSpoolRepository() {
183:                    public void store(Mail mc) throws MessagingException {
184:                        assertEquals("MYSTATE", mc.getState());
185:                        super .store(mc);
186:                    }
187:                });
188:
189:                Matcher recipientIs = new RecipientIs();
190:                recipientIs.init(new DummyMatcherConfig("rec1@domain.com"));
191:
192:                Matcher all = new All();
193:                all.init(new DummyMatcherConfig(""));
194:
195:                Mailet dumpSystemErr = new DumpSystemErr();
196:
197:                checkerMailet = new CheckerMailet();
198:                t.add(recipientIs, dumpSystemErr);
199:                t.add(all, dumpSystemErr);
200:                t.add(all, checkerMailet);
201:                t.closeProcessorLists();
202:
203:                Collection recipients = new ArrayList();
204:                recipients.add(new MailAddress("rec1", "domain.com"));
205:                recipients.add(new MailAddress("rec2", "domain.com"));
206:                try {
207:                    MailImpl m = new MailImpl("mail1", new MailAddress(
208:                            "sender", "domain.com"), recipients, mw);
209:                    m.setState("MYSTATE");
210:                    t.service(m);
211:                    ArrayList a = checkerMailet.receivedMails;
212:                    assertEquals(2, a.size());
213:                    MimeMessage m1 = ((Mail) a.get(0)).getMessage();
214:                    MimeMessage m2 = ((Mail) a.get(1)).getMessage();
215:                    assertNotSame(m1, m2);
216:                    assertEquals("MYSTATE", ((Mail) a.get(0)).getState());
217:                    assertEquals("MYSTATE", ((Mail) a.get(1)).getState());
218:                    m.dispose();
219:                } catch (MessagingException e) {
220:                    // TODO Auto-generated catch block
221:                    e.printStackTrace();
222:                }
223:            }
224:
225:            public void setUp() throws Exception {
226:                super .setUp();
227:                t = new LinearProcessor();
228:                Logger l = new ConsoleLogger();
229:                t.enableLogging(l);
230:                t.initialize();
231:
232:            }
233:
234:            public void tearDown() throws Exception {
235:                t.dispose();
236:                super.tearDown();
237:            }
238:
239:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.