XMLVelocityMailBuilderImplTest xref

    1   package com.ozacc.mail.impl;
    2
    3   import java.io.File;
    4
    5   import javax.mail.internet.InternetAddress;
    6
    7   import junit.framework.TestCase;
    8
    9   import org.apache.log4j.BasicConfigurator;
    10  import org.apache.velocity.VelocityContext;
    11
    12  import com.ozacc.mail.Mail;
    13  import com.ozacc.mail.VelocityMailBuilder;
    14  import com.ozacc.mail.impl.JDomXMLMailBuilderTest.Customer;
    15
    16  /***
    17   *
    18   * @since 1.0.1
    19   * @author Tomohiro Otsuka
    20   * @version $Id: XMLVelocityMailBuilderImplTest.java,v 1.3 2004/10/22 00:50:38 otsuka Exp $
    21   */
    22  public class XMLVelocityMailBuilderImplTest extends TestCase {
    23
    24  	private VelocityMailBuilder builder;
    25
    26  	/*
    27  	 * @see TestCase#setUp()
    28  	 */
    29  	protected void setUp() throws Exception {
    30  		super.setUp();
    31  		BasicConfigurator.configure();
    32  		builder = new XMLVelocityMailBuilderImpl();
    33  	}
    34
    35  	/***
    36  	 * @see junit.framework.TestCase#tearDown()
    37  	 */
    38  	protected void tearDown() throws Exception {
    39  		BasicConfigurator.resetConfiguration();
    40  	}
    41
    42  	public void testBuildMailFromFile() throws Exception {
    43  		String path = "src/test/com/ozacc/mail/test-mail3-velocity.xml";
    44  		File file = new File(path);
    45
    46  		String name = "°ËÅ?È?º?";
    47  		String email = "misaki@example.com";
    48  		Customer customer = new Customer(name, email);
    49  		String item = "GIVE&TAKE (Beige)";
    50
    51  		InternetAddress from = new InternetAddress("shop@example.com", "XMLMailBuilder¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥×");
    52  		InternetAddress to = new InternetAddress(email, name);
    53
    54  		String subject = "XMLMailBuilder¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥× - ¤´Ãúæ¸¤Î³ÎÇ§";
    55  		String text = name + "ÍÍ\n\n¤ªÇã¤¤¾å¤²¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£\n\nGIVE&TAKE (Beige)";
    56
    57  		VelocityContext context = new VelocityContext();
    58  		context.put("customer", customer);
    59  		context.put("item", item);
    60
    61  		// ¥á¡¼¥?À¸À®¼Â¹Ô
    62  		Mail result = builder.buildMail(file, context);
    63
    64  		assertEquals(from, result.getFrom());
    65  		assertEquals(to, result.getTo()[0]);
    66  		assertEquals(subject, result.getSubject());
    67  		assertEquals(text, result.getText());
    68  	}
    69
    70  	public final void testBuildMailStringVelocityContext() throws Exception {
    71  		String classPath = "/com/ozacc/mail/test-mail3-velocity.xml";
    72
    73  		String name = "°ËÅ?È?º?";
    74  		String email = "misaki@example.com";
    75  		Customer customer = new Customer(name, email);
    76  		String item = "GIVE&TAKE (Beige)";
    77
    78  		InternetAddress from = new InternetAddress("shop@example.com", "XMLMailBuilder¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥×");
    79  		InternetAddress to = new InternetAddress(email, name);
    80
    81  		String subject = "XMLMailBuilder¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥× - ¤´Ãúæ¸¤Î³ÎÇ§";
    82  		String text = name + "ÍÍ\n\n¤ªÇã¤¤¾å¤²¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£\n\nGIVE&TAKE (Beige)";
    83
    84  		VelocityContext context = new VelocityContext();
    85  		context.put("customer", customer);
    86  		context.put("item", item);
    87
    88  		// ¥á¡¼¥?À¸À®¼Â¹Ô
    89  		Mail result = builder.buildMail(classPath, context);
    90
    91  		assertEquals(from, result.getFrom());
    92  		assertEquals(to, result.getTo()[0]);
    93  		assertEquals(subject, result.getSubject());
    94  		assertEquals(text, result.getText());
    95  	}
    96
    97  	public final void testBuildMailStringVelocityContextWithCache() throws Exception {
    98  		builder.setCacheEnabled(true);
    99
    100 		String classPath = "/com/ozacc/mail/test-mail3-velocity.xml";
    101
    102 		String name = "°ËÅ?È?º?";
    103 		String email = "misaki@example.com";
    104 		Customer customer = new Customer(name, email);
    105 		String item = "GIVE&TAKE (Beige)";
    106
    107 		InternetAddress from = new InternetAddress("shop@example.com", "XMLMailBuilder¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥×");
    108 		InternetAddress to = new InternetAddress(email, name);
    109 		String subject = "XMLMailBuilder¥ª¥ó¥é¥¤¥ó¥·¥ç¥Ã¥× - ¤´Ãúæ¸¤Î³ÎÇ§";
    110 		String text = name + "ÍÍ\n\n¤ªÇã¤¤¾å¤²¤¢¤ê¤¬¤È¤¦¤´¤¶¤¤¤Þ¤·¤¿¡£\n\nGIVE&TAKE (Beige)";
    111
    112 		VelocityContext context = new VelocityContext();
    113 		context.put("customer", customer);
    114 		context.put("item", item);
    115
    116 		// ¥á¡¼¥?À¸À®¼Â¹Ô
    117 		Mail result = builder.buildMail(classPath, context);
    118 		Mail result2 = builder.buildMail(classPath, context);
    119 		builder.clearCache();
    120 		Mail result3 = builder.buildMail(classPath, context);
    121
    122 		assertEquals(from, result.getFrom());
    123 		assertEquals(to, result.getTo()[0]);
    124 		assertEquals(subject, result.getSubject());
    125 		assertEquals(text, result.getText());
    126 	}
    127 }