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 43 public class VelocimacroTestCase extends TestCase 44 { 45 private String template1 = "#macro(foo $a)$a#end #macro(bar $b)#foo($b)#end #foreach($i in [1..3])#bar($i)#end"; 46 private String result1 = " 123"; 47 48 public VelocimacroTestCase() 49 { 50 super("VelocimacroTestCase"); 51 52 try 53 { 54 57 Velocity.setProperty( Velocity.VM_PERM_INLINE_LOCAL, Boolean.TRUE); 58 Velocity.init(); 59 } 60 catch (Exception e) 61 { 62 System.err.println("Cannot setup VelocimacroTestCase!"); 63 System.exit(1); 64 } 65 } 66 67 public static junit.framework.Test suite() 68 { 69 return new VelocimacroTestCase(); 70 } 71 72 75 public void runTest () 76 { 77 VelocityContext context = new VelocityContext(); 78 79 try 80 { 81 StringWriter writer = new StringWriter (); 82 Velocity.evaluate(context, writer, "vm_chain1", template1); 83 84 String out = writer.toString(); 85 86 if( !result1.equals( out ) ) 87 { 88 fail("output incorrect."); 89 } 90 } 91 catch (Exception e) 92 { 93 fail(e.getMessage()); 94 } 95 } 96 } 97 | Popular Tags |