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.Writer ; 23 24 import java.util.Properties ; 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.runtime.RuntimeSingleton; 31 import org.apache.velocity.test.provider.TestProvider; 32 import org.apache.velocity.util.StringUtils; 33 import org.apache.velocity.runtime.VelocimacroFactory; 34 35 import junit.framework.TestCase; 36 37 44 public class InlineScopeVMTestCase extends BaseTestCase implements TemplateTestBase 45 { 46 49 private static final String TEST_CASE_NAME = "InlineScopeVMTestCase"; 50 51 InlineScopeVMTestCase() 52 { 53 super(TEST_CASE_NAME); 54 55 try 56 { 57 61 62 Velocity.setProperty( 63 Velocity.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, "true"); 64 65 Velocity.setProperty( 66 Velocity.VM_PERM_INLINE_LOCAL, "true"); 67 68 Velocity.setProperty( 69 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH); 70 71 Velocity.init(); 72 } 73 catch (Exception e) 74 { 75 System.err.println("Cannot setup " + TEST_CASE_NAME); 76 System.exit(1); 77 } 78 } 79 80 public static junit.framework.Test suite () 81 { 82 return new InlineScopeVMTestCase(); 83 } 84 85 88 public void runTest () 89 { 90 try 91 { 92 assureResultsDirectoryExists(RESULT_DIR); 93 94 98 99 Template template2 = RuntimeSingleton.getTemplate( 100 getFileName(null, "vm_test2", TMPL_FILE_EXT)); 101 102 Template template1 = RuntimeSingleton.getTemplate( 103 getFileName(null, "vm_test1", TMPL_FILE_EXT)); 104 105 FileOutputStream fos1 = 106 new FileOutputStream ( 107 getFileName(RESULT_DIR, "vm_test1", RESULT_FILE_EXT)); 108 109 FileOutputStream fos2 = 110 new FileOutputStream ( 111 getFileName(RESULT_DIR, "vm_test2", RESULT_FILE_EXT)); 112 113 Writer writer1 = new BufferedWriter (new OutputStreamWriter (fos1)); 114 Writer writer2 = new BufferedWriter (new OutputStreamWriter (fos2)); 115 116 119 120 VelocityContext context = new VelocityContext(); 121 122 template1.merge(context, writer1); 123 writer1.flush(); 124 writer1.close(); 125 126 template2.merge(context, writer2); 127 writer2.flush(); 128 writer2.close(); 129 130 if (!isMatch(RESULT_DIR,COMPARE_DIR,"vm_test1", 131 RESULT_FILE_EXT,CMP_FILE_EXT) || 132 !isMatch(RESULT_DIR,COMPARE_DIR,"vm_test2", 133 RESULT_FILE_EXT,CMP_FILE_EXT)) 134 { 135 fail("Output incorrect."); 136 } 137 } 138 catch (Exception e) 139 { 140 fail(e.getMessage()); 141 } 142 } 143 } 144 | Popular Tags |