1 package com.ozacc.mail.xml.impl;
2
3 import java.io.File;
4
5 import junit.framework.TestCase;
6
7 import org.jdom.Document;
8 import org.jdom.input.DOMBuilder;
9 import org.jdom.output.XMLOutputter;
10
11 import com.ozacc.mail.Mail;
12 import com.ozacc.mail.xml.XMLBuilder;
13
14 /***
15 *
16 * @author Tomohiro Otsuka
17 * @version $Id: XMLBuilderImplTest.java,v 1.3 2004/09/13 07:13:53 otsuka Exp $
18 */
19 public class XMLBuilderImplTest extends TestCase {
20
21 private XMLBuilder builder;
22
23
24
25
26 protected void setUp() throws Exception {
27 super.setUp();
28
29 builder = new XMLBuilderImpl();
30 }
31
32 public final void testCreateDocument() throws Exception {
33 Mail mail = getMailForTest();
34
35 org.w3c.dom.Document doc = builder.buildDocument(mail);
36
37 DOMBuilder builder = new DOMBuilder();
38 Document jdomDoc = builder.build(doc);
39
40 System.out.println(jdomDoc);
41
42 XMLOutputter outputter = new XMLOutputter();
43 String document = outputter.outputString(jdomDoc);
44 System.out.println(document);
45 }
46
47
48
49
50 public final void testSaveDocumentMailFile() throws Exception {
51 Mail mail = getMailForTest();
52
53 String filePath = "target/test/data/mail-jdk.xml";
54 File file = new File(filePath);
55 file.getParentFile().mkdirs();
56
57 builder.saveDocument(mail, file);
58 }
59
60 /***
61 * @return
62 */
63 private Mail getMailForTest() {
64 String from = "from@example.com";
65 String fromName = "º¹½Ð¿Í";
66 String to = "info@example.com";
67 String subject = "·?̾";
68 String text = "¥Æ¥¹¥ÈÀ®¸?";
69
70 Mail mail = new Mail();
71 mail.setFrom(from, fromName);
72 mail.addTo(to);
73 mail.setSubject(subject);
74 mail.setText(text);
75 return mail;
76 }
77
78 }