1 7 8 package org.jzonic.jlo.handler; 9 10 import junit.framework.Test; 11 import junit.framework.TestCase; 12 import junit.framework.TestSuite; 13 import org.jzonic.jlo.VariableManager; 14 15 import java.text.SimpleDateFormat ; 16 import java.util.Date ; 17 import java.util.Hashtable ; 18 22 public class RollingDateFileHandlerTest extends TestCase { 23 24 private static final VariableManager vm = VariableManager.getInstance(); 25 26 public RollingDateFileHandlerTest(java.lang.String testName) { 27 super(testName); 28 } 29 30 public static Test suite() { 31 TestSuite suite = new TestSuite(RollingDateFileHandlerTest.class); 32 return suite; 33 } 34 35 public void testFileName() { 36 DateFileHandler handler = new DateFileHandler("test"); 37 Hashtable params = new Hashtable (); 38 params.put("file","/tmp/test-${date}.log"); 39 params.put("format","dd.MM.yyyy"); 40 handler.setParameter(params); 41 String ret = handler.prepareFileName(); 42 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy"); 43 String date = formatter.format(new Date ()); 44 assertNotNull(ret); 45 assertEquals("/tmp/test-"+date+".log",ret); 46 } 47 48 public void testFileNameWithVar() { 49 DateFileHandler handler = new DateFileHandler("test"); 50 Hashtable params = new Hashtable (); 51 params.put("file","/tmp/test-${varname}_${date}.log"); 52 params.put("format","dd.MM.yyyy"); 53 handler.setParameter(params); 54 vm.addVariable("varname","varvalue","test"); 55 String ret = handler.prepareFileName(); 56 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy"); 57 String date = formatter.format(new Date ()); 58 assertNotNull(ret); 59 assertEquals("/tmp/test-varvalue_"+date+".log",ret); 60 } 61 62 63 } 64 | Popular Tags |