1 34 package groovy.text; 35 36 import java.io.IOException ; 37 import java.util.HashMap ; 38 import java.util.Map ; 39 40 import junit.framework.TestCase; 41 42 import org.codehaus.groovy.control.CompilationFailedException; 43 44 45 46 49 public class TemplateTest extends TestCase { 50 51 public void testMixedTemplateText() throws CompilationFailedException, ClassNotFoundException , IOException { 52 Template template1 = new SimpleTemplateEngine().createTemplate("<%= \"test\" %> of expr and <% test = 1 %>${test} script."); 53 assertEquals("test of expr and 1 script.", template1.make().toString()); 54 55 Template template2 = new GStringTemplateEngine().createTemplate("<%= \"test\" %> of expr and <% test = 1 %>${test} script."); 56 assertEquals("test of expr and 1 script.", template2.make().toString()); 57 58 } 59 60 public void testBinding() throws CompilationFailedException, ClassNotFoundException , IOException { 61 Map binding = new HashMap (); 62 binding.put("sam", "pullara"); 63 64 Template template1 = new SimpleTemplateEngine().createTemplate("<%= sam %><% print sam %>"); 65 assertEquals("pullarapullara", template1.make(binding).toString()); 66 67 Template template2 = new GStringTemplateEngine().createTemplate("<%= sam %><% out << sam %>"); 68 assertEquals("pullarapullara", template2.make(binding).toString()); 69 } 70 } 71 | Popular Tags |