RollingDateFileHandlerTest.java :  » Development » jLo » org » jzonic » jlo » handler » Java Open Source

Java Open Source » Development » jLo 
jLo » org » jzonic » jlo » handler » RollingDateFileHandlerTest.java
/*
 * RollingDateFileHandlerTest.java
 * JUnit based test
 *
 * Created on 17. Mai 2004, 13:32
 */

package org.jzonic.jlo.handler;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jzonic.jlo.VariableManager;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;
/**
 *
 * @author mecky
 */
public class RollingDateFileHandlerTest extends TestCase {
    
    private static final VariableManager vm = VariableManager.getInstance();
    
    public RollingDateFileHandlerTest(java.lang.String testName) {
        super(testName);
    }
    
    public static Test suite() {
        TestSuite suite = new TestSuite(RollingDateFileHandlerTest.class);
        return suite;
    }
    
    public void testFileName() {
        DateFileHandler handler = new DateFileHandler("test");
        Hashtable params = new Hashtable();
        params.put("file","/tmp/test-${date}.log");
        params.put("format","dd.MM.yyyy");        
        handler.setParameter(params);
        String ret = handler.prepareFileName();
        SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
        String date = formatter.format(new Date());
        assertNotNull(ret);
        assertEquals("/tmp/test-"+date+".log",ret);        
    }
    
    public void testFileNameWithVar() {
        DateFileHandler handler = new DateFileHandler("test");
        Hashtable params = new Hashtable();
        params.put("file","/tmp/test-${varname}_${date}.log");
        params.put("format","dd.MM.yyyy");        
        handler.setParameter(params);
        vm.addVariable("varname","varvalue","test");
        String ret = handler.prepareFileName();
        SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
        String date = formatter.format(new Date());
        assertNotNull(ret);
        assertEquals("/tmp/test-varvalue_"+date+".log",ret);        
    }
    
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.