1 package com.ozacc.mail.xml.impl;
5 import junit.framework.TestCase;
7 import org.apache.log4j.BasicConfigurator;
8 import org.jdom2.Document;
9 import org.jdom2.input.DOMBuilder;
10 import org.jdom2.output.XMLOutputter;
12 import com.ozacc.mail.Mail;
13 import com.ozacc.mail.xml.XMLBuilder;
17 * @author Tomohiro Otsuka
18 * @version $Id: XMLBuilderImplTest.java,v 1.4.2.1 2004/10/24 10:28:09 otsuka Exp $
20 public class XMLBuilderImplTest extends TestCase {
22 private XMLBuilder builder;
25 * @see junit.framework.TestCase#setUp()
27 protected void setUp() throws Exception {
30 BasicConfigurator.configure();
32 builder = new XMLBuilderImpl();
36 * @see junit.framework.TestCase#tearDown()
38 protected void tearDown() throws Exception {
39 BasicConfigurator.resetConfiguration();
42 public final void testCreateDocument() throws Exception {
43 Mail mail = getMailForTest();
45 org.w3c.dom.Document doc = builder.buildDocument(mail);
47 DOMBuilder builder = new DOMBuilder();
48 Document jdomDoc = builder.build(doc);
50 System.out.println(jdomDoc);
52 XMLOutputter outputter = new XMLOutputter();
53 String document = outputter.outputString(jdomDoc);
54 System.out.println(document);
58 * Class under test for void saveDocument(Mail, File)
60 public final void testSaveDocumentMailFile() throws Exception {
61 Mail mail = getMailForTest();
63 String filePath = "target/test/data/mail-jdk.xml";
64 File file = new File(filePath);
65 file.getParentFile().mkdirs();
67 builder.saveDocument(mail, file);
70 public final void testSaveDocumentHtml() throws Exception {
71 Mail mail = getMailForTest();
72 mail.setHtmlText("<html><body>テスト成功</body></html>");
74 String filePath = "target/test/data/mail-jdk-html.xml";
75 File file = new File(filePath);
76 file.getParentFile().mkdirs();
78 builder.saveDocument(mail, file);
84 private Mail getMailForTest() {
85 String from = "from@example.com";
86 String fromName = "差出人";
87 String to = "info@example.com";
88 String subject = "件名";
89 String text = "テスト成功\n&<>";
91 Mail mail = new Mail();
92 mail.setFrom(from, fromName);
94 mail.setSubject(subject);