1 package org.apache.velocity.test; 2 3 18 19 import java.io.BufferedWriter ; 20 import java.io.FileOutputStream ; 21 import java.io.OutputStreamWriter ; 22 import java.io.StringWriter ; 23 24 import java.util.Vector ; 25 26 import org.apache.velocity.VelocityContext; 27 28 import org.apache.velocity.Template; 29 import org.apache.velocity.app.Velocity; 30 import org.apache.velocity.test.provider.TestProvider; 31 import org.apache.velocity.util.StringUtils; 32 33 import org.apache.velocity.app.Velocity; 34 35 import junit.framework.TestCase; 36 37 44 public class VelocityAppTestCase extends BaseTestCase implements TemplateTestBase 45 { 46 private StringWriter compare1 = new StringWriter (); 47 private String input1 = "My name is $name -> $Floog"; 48 private String result1 = "My name is jason -> floogie woogie"; 49 50 public VelocityAppTestCase() 51 { 52 super("VelocityAppTestCase"); 53 54 try 55 { 56 Velocity.setProperty( 57 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH); 58 59 Velocity.init(); 60 } 61 catch (Exception e) 62 { 63 System.err.println("Cannot setup VelocityAppTestCase!"); 64 e.printStackTrace(); 65 System.exit(1); 66 } 67 } 68 69 public static junit.framework.Test suite() 70 { 71 return new VelocityAppTestCase(); 72 } 73 74 77 public void runTest () 78 { 79 VelocityContext context = new VelocityContext(); 80 context.put("name", "jason"); 81 context.put("Floog", "floogie woogie"); 82 83 try 84 { 85 Velocity.evaluate(context, compare1, "evaltest", input1); 86 87 97 if (!result1.equals(compare1.toString())) 98 { 99 fail("Output incorrect."); 100 } 101 } 102 catch (Exception e) 103 { 104 fail(e.getMessage()); 105 } 106 } 107 } 108 | Popular Tags |