XMLBuilderImplTest xref

    1   package com.ozacc.mail.xml.impl;
    2
    3   import java.io.File;
    4
    5   import junit.framework.TestCase;
    6
    7   import org.apache.log4j.BasicConfigurator;
    8   import org.jdom.Document;
    9   import org.jdom.input.DOMBuilder;
    10  import org.jdom.output.XMLOutputter;
    11
    12  import com.ozacc.mail.Mail;
    13  import com.ozacc.mail.xml.XMLBuilder;
    14
    15  /***
    16   *
    17   * @author Tomohiro Otsuka
    18   * @version $Id: XMLBuilderImplTest.java,v 1.5 2004/10/05 12:02:33 otsuka Exp $
    19   */
    20  public class XMLBuilderImplTest extends TestCase {
    21
    22  	private XMLBuilder builder;
    23
    24  	/***
    25  	 * @see junit.framework.TestCase#setUp()
    26  	 */
    27  	protected void setUp() throws Exception {
    28  		super.setUp();
    29
    30  		BasicConfigurator.configure();
    31
    32  		builder = new XMLBuilderImpl();
    33  	}
    34
    35  	/***
    36  	 * @see junit.framework.TestCase#tearDown()
    37  	 */
    38  	protected void tearDown() throws Exception {
    39  		BasicConfigurator.resetConfiguration();
    40  	}
    41
    42  	public final void testCreateDocument() throws Exception {
    43  		Mail mail = getMailForTest();
    44
    45  		org.w3c.dom.Document doc = builder.buildDocument(mail);
    46
    47  		DOMBuilder builder = new DOMBuilder();
    48  		Document jdomDoc = builder.build(doc);
    49
    50  		System.out.println(jdomDoc);
    51
    52  		XMLOutputter outputter = new XMLOutputter();
    53  		String document = outputter.outputString(jdomDoc);
    54  		System.out.println(document);
    55  	}
    56
    57  	/*
    58  	 * Class under test for void saveDocument(Mail, File)
    59  	 */
    60  	public final void testSaveDocumentMailFile() throws Exception {
    61  		Mail mail = getMailForTest();
    62
    63  		String filePath = "target/test/data/mail-jdk.xml";
    64  		File file = new File(filePath);
    65  		file.getParentFile().mkdirs();
    66
    67  		builder.saveDocument(mail, file);
    68  	}
    69
    70  	public final void testSaveDocumentHtml() throws Exception {
    71  		Mail mail = getMailForTest();
    72  		mail.setHtmlText("<html><body>¥Æ¥¹¥ÈÀ®¸?</body></html>");
    73
    74  		String filePath = "target/test/data/mail-jdk-html.xml";
    75  		File file = new File(filePath);
    76  		file.getParentFile().mkdirs();
    77
    78  		builder.saveDocument(mail, file);
    79  	}
    80
    81  	/***
    82  	 * @return
    83  	 */
    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&<>";
    90
    91  		Mail mail = new Mail();
    92  		mail.setFrom(from, fromName);
    93  		mail.addTo(to);
    94  		mail.setSubject(subject);
    95  		mail.setText(text);
    96  		return mail;
    97  	}
    98
    99  }