OSDN Git Service

CVS最新版の全ファイルを追加
[spring-ext/ozacc-mail.git] / src / test / com / ozacc / mail / xml / impl / XMLBuilderImplTest.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 import com.ozacc.mail.xml.XMLBuilder;\r
14 \r
15 /**\r
16  * \r
17  * @author Tomohiro Otsuka\r
18  * @version $Id: XMLBuilderImplTest.java,v 1.4.2.1 2004/10/24 10:28:09 otsuka Exp $\r
19  */\r
20 public class XMLBuilderImplTest extends TestCase {\r
21 \r
22         private XMLBuilder builder;\r
23 \r
24         /**\r
25          * @see junit.framework.TestCase#setUp()\r
26          */\r
27         protected void setUp() throws Exception {\r
28                 super.setUp();\r
29 \r
30                 BasicConfigurator.configure();\r
31 \r
32                 builder = new XMLBuilderImpl();\r
33         }\r
34 \r
35         /**\r
36          * @see junit.framework.TestCase#tearDown()\r
37          */\r
38         protected void tearDown() throws Exception {\r
39                 BasicConfigurator.resetConfiguration();\r
40         }\r
41 \r
42         public final void testCreateDocument() throws Exception {\r
43                 Mail mail = getMailForTest();\r
44 \r
45                 org.w3c.dom.Document doc = builder.buildDocument(mail);\r
46 \r
47                 DOMBuilder builder = new DOMBuilder();\r
48                 Document jdomDoc = builder.build(doc);\r
49 \r
50                 System.out.println(jdomDoc);\r
51 \r
52                 XMLOutputter outputter = new XMLOutputter();\r
53                 String document = outputter.outputString(jdomDoc);\r
54                 System.out.println(document);\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-jdk.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 }