XMLMailBuilderImplTest xref

    1   package com.ozacc.mail.impl;
    2
    3   import java.io.File;
    4
    5   import javax.mail.internet.InternetAddress;
    6
    7   import org.apache.log4j.BasicConfigurator;
    8
    9   import junit.framework.TestCase;
    10
    11  import com.ozacc.mail.Mail;
    12  import com.ozacc.mail.MailBuilder;
    13
    14  /***
    15   *
    16   * @since 1.0.1
    17   * @author Tomohiro Otsuka
    18   * @version $Id: XMLMailBuilderImplTest.java,v 1.6 2004/09/21 11:43:09 otsuka Exp $
    19   */
    20  public class XMLMailBuilderImplTest extends TestCase {
    21
    22  	private MailBuilder builder;
    23
    24  	/*
    25  	 * @see TestCase#setUp()
    26  	 */
    27  	protected void setUp() throws Exception {
    28  		super.setUp();
    29  		BasicConfigurator.configure();
    30
    31  		builder = new XMLMailBuilderImpl();
    32  	}
    33
    34  	/***
    35  	 * @see junit.framework.TestCase#tearDown()
    36  	 */
    37  	protected void tearDown() throws Exception {
    38  		super.tearDown();
    39  		BasicConfigurator.resetConfiguration();
    40  	}
    41
    42  	public final void testBuildMailCDATA() throws Exception {
    43  		String classPath = "/com/ozacc/mail/test-mail6-cdata.xml";
    44
    45  		String expectedBody = "¤³¤?¤ÏCDATA¤Î¥Æ¥¥¹¥È¤Ç¤¹¡£";
    46
    47  		Mail result = builder.buildMail(classPath);
    48
    49  		assertEquals(expectedBody, result.getText());
    50  	}
    51
    52  	public final void testBuildMultipartMailFromFile() throws Exception {
    53  		String path = "src/test/com/ozacc/mail/test-mail1.xml";
    54  		File file = new File(path);
    55
    56  		String subject = "XMLMailBuilder¤Î¥Æ¥¹¥È¥±¡¼¥¹";
    57  		String text = "²?¹Ô¤·¤Þ¤¹¡£\n²?¹Ô¤·¤Þ¤·¤¿¡£\n¥Æ¥¹¥È¤ÏÀ®¸ù¡£";
    58  		String htmlText = "<html><body>¤³¤?¤ÏHTML¥Æ¥¥¹¥È</body></html>";
    59
    60  		InternetAddress from = new InternetAddress("from@example.com", "º¹½Ð¿Í");
    61  		InternetAddress returnPath = new InternetAddress("return@example.com");
    62  		InternetAddress replyTo = new InternetAddress("reply@example.com");
    63
    64  		InternetAddress to1 = new InternetAddress("to1@example.com", "°¸À?1");
    65  		InternetAddress to2 = new InternetAddress("to2@example.com");
    66
    67  		InternetAddress cc1 = new InternetAddress("cc1@example.com", "CC1");
    68  		InternetAddress cc2 = new InternetAddress("cc2@example.com");
    69
    70  		InternetAddress bcc = new InternetAddress("bcc@example.com");
    71
    72  		Mail result = builder.buildMail(file);
    73
    74  		System.out.println(result);
    75
    76  		assertEquals(subject, result.getSubject());
    77  		assertEquals(text, result.getText());
    78
    79  		assertTrue(result.isMultipartMail());
    80  		assertTrue(result.isHtmlMail());
    81  		assertEquals(htmlText, result.getHtmlText());
    82
    83  		assertEquals(from, result.getFrom());
    84  		assertEquals(returnPath, result.getReturnPath());
    85  		assertEquals(replyTo, result.getReplyTo());
    86
    87  		InternetAddress[] tos = result.getTo();
    88  		assertEquals(2, tos.length);
    89  		assertEquals(to1, tos[0]);
    90  		assertEquals(to2, tos[1]);
    91
    92  		InternetAddress[] ccs = result.getCc();
    93  		assertEquals(2, ccs.length);
    94  		assertEquals(cc1, ccs[0]);
    95  		assertEquals(cc2, ccs[1]);
    96
    97  		InternetAddress[] bccs = result.getBcc();
    98  		assertEquals(1, bccs.length);
    99  		assertEquals(bcc, bccs[0]);
    100 	}
    101
    102 	/*
    103 	 * Class under test for Mail buildMail(String)
    104 	 */
    105 	public final void testBuildMailFromClassPath() throws Exception {
    106 		String classPath = "/com/ozacc/mail/test-mail1.xml";
    107
    108 		String subject = "XMLMailBuilder¤Î¥Æ¥¹¥È¥±¡¼¥¹";
    109 		String text = "²?¹Ô¤·¤Þ¤¹¡£\n²?¹Ô¤·¤Þ¤·¤¿¡£\n¥Æ¥¹¥È¤ÏÀ®¸ù¡£";
    110
    111 		InternetAddress from = new InternetAddress("from@example.com", "º¹½Ð¿Í");
    112 		InternetAddress returnPath = new InternetAddress("return@example.com");
    113 		InternetAddress replyTo = new InternetAddress("reply@example.com");
    114
    115 		InternetAddress to1 = new InternetAddress("to1@example.com", "°¸À?1");
    116 		InternetAddress to2 = new InternetAddress("to2@example.com");
    117
    118 		InternetAddress cc1 = new InternetAddress("cc1@example.com", "CC1");
    119 		InternetAddress cc2 = new InternetAddress("cc2@example.com");
    120
    121 		InternetAddress bcc = new InternetAddress("bcc@example.com");
    122
    123 		Mail result = builder.buildMail(classPath);
    124
    125 		assertEquals(subject, result.getSubject());
    126 		assertEquals(text, result.getText());
    127
    128 		assertEquals(from, result.getFrom());
    129 		assertEquals(returnPath, result.getReturnPath());
    130 		assertEquals(replyTo, result.getReplyTo());
    131
    132 		InternetAddress[] tos = result.getTo();
    133 		assertEquals(2, tos.length);
    134 		assertEquals(to1, tos[0]);
    135 		assertEquals(to2, tos[1]);
    136
    137 		InternetAddress[] ccs = result.getCc();
    138 		assertEquals(2, ccs.length);
    139 		assertEquals(cc1, ccs[0]);
    140 		assertEquals(cc2, ccs[1]);
    141
    142 		InternetAddress[] bccs = result.getBcc();
    143 		assertEquals(1, bccs.length);
    144 		assertEquals(bcc, bccs[0]);
    145 	}
    146
    147 	/*
    148 	 * Class under test for Mail buildMail(File)
    149 	 */
    150 	public final void testBuildMailFile() throws Exception {
    151 		String path = "src/test/com/ozacc/mail/test-mail1.xml";
    152 		File file = new File(path);
    153
    154 		String subject = "XMLMailBuilder¤Î¥Æ¥¹¥È¥±¡¼¥¹";
    155 		String text = "²?¹Ô¤·¤Þ¤¹¡£\n²?¹Ô¤·¤Þ¤·¤¿¡£\n¥Æ¥¹¥È¤ÏÀ®¸ù¡£";
    156
    157 		InternetAddress from = new InternetAddress("from@example.com", "º¹½Ð¿Í");
    158 		InternetAddress returnPath = new InternetAddress("return@example.com");
    159 		InternetAddress replyTo = new InternetAddress("reply@example.com");
    160
    161 		InternetAddress to1 = new InternetAddress("to1@example.com", "°¸À?1");
    162 		InternetAddress to2 = new InternetAddress("to2@example.com");
    163
    164 		InternetAddress cc1 = new InternetAddress("cc1@example.com", "CC1");
    165 		InternetAddress cc2 = new InternetAddress("cc2@example.com");
    166
    167 		InternetAddress bcc = new InternetAddress("bcc@example.com");
    168
    169 		Mail result = builder.buildMail(file);
    170
    171 		assertEquals(subject, result.getSubject());
    172 		assertEquals(text, result.getText());
    173
    174 		assertEquals(from, result.getFrom());
    175 		assertEquals(returnPath, result.getReturnPath());
    176 		assertEquals(replyTo, result.getReplyTo());
    177
    178 		InternetAddress[] tos = result.getTo();
    179 		assertEquals(2, tos.length);
    180 		assertEquals(to1, tos[0]);
    181 		assertEquals(to2, tos[1]);
    182
    183 		InternetAddress[] ccs = result.getCc();
    184 		assertEquals(2, ccs.length);
    185 		assertEquals(cc1, ccs[0]);
    186 		assertEquals(cc2, ccs[1]);
    187
    188 		InternetAddress[] bccs = result.getBcc();
    189 		assertEquals(1, bccs.length);
    190 		assertEquals(bcc, bccs[0]);
    191 	}
    192
    193 }