package com.ozacc.mail.xml.impl; import java.io.File; import junit.framework.TestCase; import org.apache.log4j.BasicConfigurator; import org.jdom.Document; import org.jdom.input.DOMBuilder; import org.jdom.output.XMLOutputter; import com.ozacc.mail.Mail; /** * * @author Tomohiro Otsuka * @version $Id: JDomXMLBuilderTest.java,v 1.2.2.1 2004/10/24 10:28:09 otsuka Exp $ */ public class JDomXMLBuilderTest extends TestCase { private JDomXMLBuilder builder; /** * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); BasicConfigurator.configure(); builder = new JDomXMLBuilder(); } /** * @see junit.framework.TestCase#tearDown() */ protected void tearDown() throws Exception { BasicConfigurator.resetConfiguration(); } public final void testCreateDocument() throws Exception { Mail mail = getMailForTest(); org.w3c.dom.Document doc = builder.buildDocument(mail); DOMBuilder builder = new DOMBuilder(); Document jdomDoc = builder.build(doc); System.out.println(jdomDoc); XMLOutputter outputter = new XMLOutputter(); String document = outputter.outputString(jdomDoc); System.out.println(document); } /* * Class under test for void saveDocument(Mail, File) */ public final void testSaveDocumentMailFile() throws Exception { Mail mail = getMailForTest(); String filePath = "target/test/data/mail.xml"; File file = new File(filePath); file.getParentFile().mkdirs(); builder.saveDocument(mail, file); } public final void testSaveDocumentHtml() throws Exception { Mail mail = getMailForTest(); mail.setHtmlText("テスト成功"); String filePath = "target/test/data/mail-jdk-html.xml"; File file = new File(filePath); file.getParentFile().mkdirs(); builder.saveDocument(mail, file); } /** * @return */ private Mail getMailForTest() { String from = "from@example.com"; String fromName = "差出人"; String to = "info@example.com"; String subject = "件名"; String text = "テスト成功\n&<>"; Mail mail = new Mail(); mail.setFrom(from, fromName); mail.addTo(to); mail.setSubject(subject); mail.setText(text); return mail; } }