01: /*
02: * RollingDateFileHandlerTest.java
03: * JUnit based test
04: *
05: * Created on 17. Mai 2004, 13:32
06: */
07:
08: package org.jzonic.jlo.handler;
09:
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:
19: /**
20: *
21: * @author mecky
22: */
23: public class RollingDateFileHandlerTest extends TestCase {
24:
25: private static final VariableManager vm = VariableManager
26: .getInstance();
27:
28: public RollingDateFileHandlerTest(java.lang.String testName) {
29: super (testName);
30: }
31:
32: public static Test suite() {
33: TestSuite suite = new TestSuite(
34: RollingDateFileHandlerTest.class);
35: return suite;
36: }
37:
38: public void testFileName() {
39: DateFileHandler handler = new DateFileHandler("test");
40: Hashtable params = new Hashtable();
41: params.put("file", "/tmp/test-${date}.log");
42: params.put("format", "dd.MM.yyyy");
43: handler.setParameter(params);
44: String ret = handler.prepareFileName();
45: SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
46: String date = formatter.format(new Date());
47: assertNotNull(ret);
48: assertEquals("/tmp/test-" + date + ".log", ret);
49: }
50:
51: public void testFileNameWithVar() {
52: DateFileHandler handler = new DateFileHandler("test");
53: Hashtable params = new Hashtable();
54: params.put("file", "/tmp/test-${varname}_${date}.log");
55: params.put("format", "dd.MM.yyyy");
56: handler.setParameter(params);
57: vm.addVariable("varname", "varvalue", "test");
58: String ret = handler.prepareFileName();
59: SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
60: String date = formatter.format(new Date());
61: assertNotNull(ret);
62: assertEquals("/tmp/test-varvalue_" + date + ".log", ret);
63: }
64:
65: }
|