1   /* $Id: VelocityTest.java,v 1.1 2004/06/02 20:10:05 johndavidtaylor Exp $
2    * Created on May 22, 2004 by jdt@roe.ac.uk
3    * The alipes project
4    *
5    */
6   package org.abraracourcix.alipes.listeners.email;
7   
8   import java.io.StringWriter;
9   
10  import org.apache.velocity.Template;
11  import org.apache.velocity.VelocityContext;
12  import org.apache.velocity.app.Velocity;
13  import org.apache.velocity.app.VelocityEngine;
14  import org.apache.velocity.exception.ParseErrorException;
15  import org.apache.velocity.exception.ResourceNotFoundException;
16  
17  import junit.framework.TestCase;
18  
19  /***
20   * A few simple tests of velocity to see if we can
21   * get the hang of it.
22   * 
23   * @author jdt
24   */
25  public class VelocityTest extends TestCase {
26      public static void main(String[] args) {
27          junit.textui.TestRunner.run(VelocityTest.class);
28      }
29      
30      /***
31       * Take the template and replace a value
32       *
33       */
34      public void testSimpleReplace() throws ResourceNotFoundException, ParseErrorException, Exception {
35          Velocity.init();
36          VelocityContext context = new VelocityContext();
37  
38          context.put( "name", new String("John") );
39  
40          Template  template = Velocity.getTemplate("src/test/templates/template1.vm");
41  
42  
43          StringWriter sw = new StringWriter();
44  
45          template.merge( context, sw );
46          //System.out.println(sw.toString());
47          assertEquals(sw.toString(),"My name is John");
48          
49      }
50  }
51  
52  
53  /*
54   *  $Log: VelocityTest.java,v $
55   *  Revision 1.1  2004/06/02 20:10:05  johndavidtaylor
56   *  Refactoring to allow email templates.
57   *
58   */