KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > handler > RollingDateFileHandlerTest


1 /*
2  * RollingDateFileHandlerTest.java
3  * JUnit based test
4  *
5  * Created on 17. Mai 2004, 13:32
6  */

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 JavaDoc;
16 import java.util.Date JavaDoc;
17 import java.util.Hashtable JavaDoc;
18 /**
19  *
20  * @author mecky
21  */

22 public class RollingDateFileHandlerTest extends TestCase {
23     
24     private static final VariableManager vm = VariableManager.getInstance();
25     
26     public RollingDateFileHandlerTest(java.lang.String JavaDoc 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 JavaDoc params = new Hashtable JavaDoc();
38         params.put("file","/tmp/test-${date}.log");
39         params.put("format","dd.MM.yyyy");
40         handler.setParameter(params);
41         String JavaDoc ret = handler.prepareFileName();
42         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("dd.MM.yyyy");
43         String JavaDoc date = formatter.format(new Date JavaDoc());
44         assertNotNull(ret);
45         assertEquals("/tmp/test-"+date+".log",ret);
46     }
47     
48     public void testFileNameWithVar() {
49         DateFileHandler handler = new DateFileHandler("test");
50         Hashtable JavaDoc params = new Hashtable JavaDoc();
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 JavaDoc ret = handler.prepareFileName();
56         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("dd.MM.yyyy");
57         String JavaDoc date = formatter.format(new Date JavaDoc());
58         assertNotNull(ret);
59         assertEquals("/tmp/test-varvalue_"+date+".log",ret);
60     }
61     
62     
63 }
64
Popular Tags