OSDN Git Service

CVS最新版の全ファイルを追加
[spring-ext/ozacc-mail.git] / src / test / com / ozacc / mail / impl / XMLMailBuilderImplTest.java
1 package com.ozacc.mail.impl;\r
2 \r
3 import java.io.File;\r
4 \r
5 import javax.mail.internet.InternetAddress;\r
6 \r
7 import junit.framework.TestCase;\r
8 \r
9 import org.apache.log4j.BasicConfigurator;\r
10 \r
11 import com.ozacc.mail.Mail;\r
12 import com.ozacc.mail.MailBuildException;\r
13 import com.ozacc.mail.MultipleMailBuilder;\r
14 \r
15 /**\r
16  * \r
17  * @since 1.0.1\r
18  * @author Tomohiro Otsuka\r
19  * @version $Id: XMLMailBuilderImplTest.java,v 1.6.2.1 2005/01/21 22:17:27 otsuka Exp $\r
20  */\r
21 public class XMLMailBuilderImplTest extends TestCase {\r
22 \r
23         private MultipleMailBuilder builder;\r
24 \r
25         /*\r
26          * @see TestCase#setUp()\r
27          */\r
28         protected void setUp() throws Exception {\r
29                 super.setUp();\r
30                 BasicConfigurator.configure();\r
31 \r
32                 builder = new XMLMailBuilderImpl();\r
33         }\r
34 \r
35         /**\r
36          * @see junit.framework.TestCase#tearDown()\r
37          */\r
38         protected void tearDown() throws Exception {\r
39                 super.tearDown();\r
40                 BasicConfigurator.resetConfiguration();\r
41         }\r
42 \r
43         public final void testBuildMailCDATA() throws Exception {\r
44                 String classPath = "/com/ozacc/mail/test-mail6-cdata.xml";\r
45 \r
46                 String expectedBody = "これはCDATAのテキストです。";\r
47 \r
48                 Mail result = builder.buildMail(classPath);\r
49 \r
50                 assertEquals(expectedBody, result.getText());\r
51         }\r
52 \r
53         public final void testBuildMultipartMailFromFile() throws Exception {\r
54                 String path = "src/test/com/ozacc/mail/test-mail1.xml";\r
55                 File file = new File(path);\r
56 \r
57                 String subject = "XMLMailBuilderのテストケース";\r
58                 String text = "改行します。\n改行しました。\nテストは成功。";\r
59                 String htmlText = "<html><body>これはHTMLテキスト</body></html>";\r
60 \r
61                 InternetAddress from = new InternetAddress("from@example.com", "差出人");\r
62                 InternetAddress returnPath = new InternetAddress("return@example.com");\r
63                 InternetAddress replyTo = new InternetAddress("reply@example.com");\r
64 \r
65                 InternetAddress to1 = new InternetAddress("to1@example.com", "宛先1");\r
66                 InternetAddress to2 = new InternetAddress("to2@example.com");\r
67 \r
68                 InternetAddress cc1 = new InternetAddress("cc1@example.com", "CC1");\r
69                 InternetAddress cc2 = new InternetAddress("cc2@example.com");\r
70 \r
71                 InternetAddress bcc = new InternetAddress("bcc@example.com");\r
72 \r
73                 Mail result = builder.buildMail(file);\r
74 \r
75                 System.out.println(result);\r
76 \r
77                 assertEquals(subject, result.getSubject());\r
78                 assertEquals(text, result.getText());\r
79 \r
80                 assertTrue(result.isMultipartMail());\r
81                 assertTrue(result.isHtmlMail());\r
82                 assertEquals(htmlText, result.getHtmlText());\r
83 \r
84                 assertEquals(from, result.getFrom());\r
85                 assertEquals(returnPath, result.getReturnPath());\r
86                 assertEquals(replyTo, result.getReplyTo());\r
87 \r
88                 InternetAddress[] tos = result.getTo();\r
89                 assertEquals(2, tos.length);\r
90                 assertEquals(to1, tos[0]);\r
91                 assertEquals(to2, tos[1]);\r
92 \r
93                 InternetAddress[] ccs = result.getCc();\r
94                 assertEquals(2, ccs.length);\r
95                 assertEquals(cc1, ccs[0]);\r
96                 assertEquals(cc2, ccs[1]);\r
97 \r
98                 InternetAddress[] bccs = result.getBcc();\r
99                 assertEquals(1, bccs.length);\r
100                 assertEquals(bcc, bccs[0]);\r
101         }\r
102 \r
103         /*\r
104          * Class under test for Mail buildMail(String)\r
105          */\r
106         public final void testBuildMailFromClassPath() throws Exception {\r
107                 String classPath = "/com/ozacc/mail/test-mail1.xml";\r
108 \r
109                 String subject = "XMLMailBuilderのテストケース";\r
110                 String text = "改行します。\n改行しました。\nテストは成功。";\r
111 \r
112                 InternetAddress from = new InternetAddress("from@example.com", "差出人");\r
113                 InternetAddress returnPath = new InternetAddress("return@example.com");\r
114                 InternetAddress replyTo = new InternetAddress("reply@example.com");\r
115 \r
116                 InternetAddress to1 = new InternetAddress("to1@example.com", "宛先1");\r
117                 InternetAddress to2 = new InternetAddress("to2@example.com");\r
118 \r
119                 InternetAddress cc1 = new InternetAddress("cc1@example.com", "CC1");\r
120                 InternetAddress cc2 = new InternetAddress("cc2@example.com");\r
121 \r
122                 InternetAddress bcc = new InternetAddress("bcc@example.com");\r
123 \r
124                 Mail result = builder.buildMail(classPath);\r
125 \r
126                 assertEquals(subject, result.getSubject());\r
127                 assertEquals(text, result.getText());\r
128 \r
129                 assertEquals(from, result.getFrom());\r
130                 assertEquals(returnPath, result.getReturnPath());\r
131                 assertEquals(replyTo, result.getReplyTo());\r
132 \r
133                 InternetAddress[] tos = result.getTo();\r
134                 assertEquals(2, tos.length);\r
135                 assertEquals(to1, tos[0]);\r
136                 assertEquals(to2, tos[1]);\r
137 \r
138                 InternetAddress[] ccs = result.getCc();\r
139                 assertEquals(2, ccs.length);\r
140                 assertEquals(cc1, ccs[0]);\r
141                 assertEquals(cc2, ccs[1]);\r
142 \r
143                 InternetAddress[] bccs = result.getBcc();\r
144                 assertEquals(1, bccs.length);\r
145                 assertEquals(bcc, bccs[0]);\r
146         }\r
147 \r
148         /*\r
149          * Class under test for Mail buildMail(File)\r
150          */\r
151         public final void testBuildMailFile() throws Exception {\r
152                 String path = "src/test/com/ozacc/mail/test-mail1.xml";\r
153                 File file = new File(path);\r
154 \r
155                 String subject = "XMLMailBuilderのテストケース";\r
156                 String text = "改行します。\n改行しました。\nテストは成功。";\r
157 \r
158                 InternetAddress from = new InternetAddress("from@example.com", "差出人");\r
159                 InternetAddress returnPath = new InternetAddress("return@example.com");\r
160                 InternetAddress replyTo = new InternetAddress("reply@example.com");\r
161 \r
162                 InternetAddress to1 = new InternetAddress("to1@example.com", "宛先1");\r
163                 InternetAddress to2 = new InternetAddress("to2@example.com");\r
164 \r
165                 InternetAddress cc1 = new InternetAddress("cc1@example.com", "CC1");\r
166                 InternetAddress cc2 = new InternetAddress("cc2@example.com");\r
167 \r
168                 InternetAddress bcc = new InternetAddress("bcc@example.com");\r
169 \r
170                 Mail result = builder.buildMail(file);\r
171 \r
172                 assertEquals(subject, result.getSubject());\r
173                 assertEquals(text, result.getText());\r
174 \r
175                 assertEquals(from, result.getFrom());\r
176                 assertEquals(returnPath, result.getReturnPath());\r
177                 assertEquals(replyTo, result.getReplyTo());\r
178 \r
179                 InternetAddress[] tos = result.getTo();\r
180                 assertEquals(2, tos.length);\r
181                 assertEquals(to1, tos[0]);\r
182                 assertEquals(to2, tos[1]);\r
183 \r
184                 InternetAddress[] ccs = result.getCc();\r
185                 assertEquals(2, ccs.length);\r
186                 assertEquals(cc1, ccs[0]);\r
187                 assertEquals(cc2, ccs[1]);\r
188 \r
189                 InternetAddress[] bccs = result.getBcc();\r
190                 assertEquals(1, bccs.length);\r
191                 assertEquals(bcc, bccs[0]);\r
192         }\r
193 \r
194         public void testBuildMailFromMultipleMailsTemplate() throws Exception {\r
195                 String path = "src/test/com/ozacc/mail/test-mail7-multiple.xml";\r
196                 File file = new File(path);\r
197 \r
198                 Mail result1 = builder.buildMail(file, "first");\r
199                 assertEquals("1通目", result1.getText());\r
200 \r
201                 Mail result2 = builder.buildMail(file, "second");\r
202                 assertEquals("2通目", result2.getText());\r
203 \r
204                 try {\r
205                         Mail result3 = builder.buildMail(file, "サード");\r
206                 } catch (MailBuildException expected) {\r
207                         \r
208                 }\r
209         }\r
210 }