1 package com.ozacc.mail.xml.impl;
\r
5 import junit.framework.TestCase;
\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
12 import com.ozacc.mail.Mail;
\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
19 public class JDomXMLBuilderTest extends TestCase {
\r
21 private JDomXMLBuilder builder;
\r
24 * @see TestCase#setUp()
\r
26 protected void setUp() throws Exception {
\r
29 BasicConfigurator.configure();
\r
31 builder = new JDomXMLBuilder();
\r
35 * @see junit.framework.TestCase#tearDown()
\r
37 protected void tearDown() throws Exception {
\r
38 BasicConfigurator.resetConfiguration();
\r
41 public final void testCreateDocument() throws Exception {
\r
42 Mail mail = getMailForTest();
\r
44 org.w3c.dom.Document doc = builder.buildDocument(mail);
\r
46 DOMBuilder builder = new DOMBuilder();
\r
47 Document jdomDoc = builder.build(doc);
\r
49 System.out.println(jdomDoc);
\r
51 XMLOutputter outputter = new XMLOutputter();
\r
52 String document = outputter.outputString(jdomDoc);
\r
53 System.out.println(document);
\r
58 * Class under test for void saveDocument(Mail, File)
\r
60 public final void testSaveDocumentMailFile() throws Exception {
\r
61 Mail mail = getMailForTest();
\r
63 String filePath = "target/test/data/mail.xml";
\r
64 File file = new File(filePath);
\r
65 file.getParentFile().mkdirs();
\r
67 builder.saveDocument(mail, file);
\r
70 public final void testSaveDocumentHtml() throws Exception {
\r
71 Mail mail = getMailForTest();
\r
72 mail.setHtmlText("<html><body>テスト成功</body></html>");
\r
74 String filePath = "target/test/data/mail-jdk-html.xml";
\r
75 File file = new File(filePath);
\r
76 file.getParentFile().mkdirs();
\r
78 builder.saveDocument(mail, file);
\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
91 Mail mail = new Mail();
\r
92 mail.setFrom(from, fromName);
\r
94 mail.setSubject(subject);
\r