1 package org.apache.velocity.test; 2 3 18 19 import org.apache.velocity.app.VelocityEngine; 20 import org.apache.velocity.runtime.RuntimeServices; 21 22 import org.apache.velocity.runtime.log.LogSystem; 23 24 import junit.framework.TestCase; 25 26 32 public class ExternalLoggerTest extends TestCase implements LogSystem 33 { 34 35 private String logString = null; 36 private VelocityEngine ve = null; 37 38 41 public ExternalLoggerTest() 42 { 43 super("LoggerTest"); 44 45 try 46 { 47 50 51 ve = new VelocityEngine(); 52 ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this ); 53 ve.init(); 54 } 55 catch (Exception e) 56 { 57 System.err.println("Cannot setup LoggerTest : " + e); 58 System.exit(1); 59 } 60 } 61 62 public void init( RuntimeServices rs ) 63 { 64 } 66 67 public static junit.framework.Test suite () 68 { 69 return new ExternalLoggerTest(); 70 } 71 72 75 public void runTest () 76 { 77 80 81 logString = null; 82 83 String testString = "This is a test."; 84 85 ve.warn( testString ); 86 87 if (logString == null || !logString.equals( VelocityEngine.WARN_PREFIX + testString ) ) 88 { 89 fail("Didn't recieve log message."); 90 } 91 } 92 93 public void logVelocityMessage(int level, String message) 94 { 95 String out = ""; 96 97 100 switch( level ) 101 { 102 case LogSystem.DEBUG_ID : 103 out = VelocityEngine.DEBUG_PREFIX; 104 break; 105 case LogSystem.INFO_ID : 106 out = VelocityEngine.INFO_PREFIX; 107 break; 108 case LogSystem.WARN_ID : 109 out = VelocityEngine.WARN_PREFIX; 110 break; 111 case LogSystem.ERROR_ID : 112 out = VelocityEngine.ERROR_PREFIX; 113 break; 114 default : 115 out = VelocityEngine.UNKNOWN_PREFIX; 116 break; 117 } 118 119 logString = out + message; 120 } 121 } 122 | Popular Tags |