OSDN Git Service

CVS最新版の全ファイルを追加
[spring-ext/ozacc-mail.git] / src / test / com / ozacc / mail / xml / impl / JDomXMLBuilderTest.java
1 package com.ozacc.mail.xml.impl;\r
2 \r
3 import java.io.File;\r
4 \r
5 import junit.framework.TestCase;\r
6 \r
7 import org.apache.log4j.BasicConfigurator;\r
8 import org.jdom.Document;\r
9 import org.jdom.input.DOMBuilder;\r
10 import org.jdom.output.XMLOutputter;\r
11 \r
12 import com.ozacc.mail.Mail;\r
13 \r
14 /**\r
15  * \r
16  * @author Tomohiro Otsuka\r
17  * @version $Id: JDomXMLBuilderTest.java,v 1.2.2.1 2004/10/24 10:28:09 otsuka Exp $\r
18  */\r
19 public class JDomXMLBuilderTest extends TestCase {\r
20 \r
21         private JDomXMLBuilder builder;\r
22 \r
23         /**\r
24          * @see TestCase#setUp()\r
25          */\r
26         protected void setUp() throws Exception {\r
27                 super.setUp();\r
28 \r
29                 BasicConfigurator.configure();\r
30 \r
31                 builder = new JDomXMLBuilder();\r
32         }\r
33 \r
34         /**\r
35          * @see junit.framework.TestCase#tearDown()\r
36          */\r
37         protected void tearDown() throws Exception {\r
38                 BasicConfigurator.resetConfiguration();\r
39         }\r
40 \r
41         public final void testCreateDocument() throws Exception {\r
42                 Mail mail = getMailForTest();\r
43 \r
44                 org.w3c.dom.Document doc = builder.buildDocument(mail);\r
45 \r
46                 DOMBuilder builder = new DOMBuilder();\r
47                 Document jdomDoc = builder.build(doc);\r
48 \r
49                 System.out.println(jdomDoc);\r
50 \r
51                 XMLOutputter outputter = new XMLOutputter();\r
52                 String document = outputter.outputString(jdomDoc);\r
53                 System.out.println(document);\r
54 \r
55         }\r
56 \r
57         /*\r
58          * Class under test for void saveDocument(Mail, File)\r
59          */\r
60         public final void testSaveDocumentMailFile() throws Exception {\r
61                 Mail mail = getMailForTest();\r
62 \r
63                 String filePath = "target/test/data/mail.xml";\r
64                 File file = new File(filePath);\r
65                 file.getParentFile().mkdirs();\r
66 \r
67                 builder.saveDocument(mail, file);\r
68         }\r
69 \r
70         public final void testSaveDocumentHtml() throws Exception {\r
71                 Mail mail = getMailForTest();\r
72                 mail.setHtmlText("<html><body>テスト成功</body></html>");\r
73 \r
74                 String filePath = "target/test/data/mail-jdk-html.xml";\r
75                 File file = new File(filePath);\r
76                 file.getParentFile().mkdirs();\r
77 \r
78                 builder.saveDocument(mail, file);\r
79         }\r
80 \r
81         /**\r
82          * @return \r
83          */\r
84         private Mail getMailForTest() {\r
85                 String from = "from@example.com";\r
86                 String fromName = "差出人";\r
87                 String to = "info@example.com";\r
88                 String subject = "件名";\r
89                 String text = "テスト成功\n&<>";\r
90 \r
91                 Mail mail = new Mail();\r
92                 mail.setFrom(from, fromName);\r
93                 mail.addTo(to);\r
94                 mail.setSubject(subject);\r
95                 mail.setText(text);\r
96                 return mail;\r
97         }\r
98 \r
99 }