Package org.jzonic.jlo.handler

Source Code of org.jzonic.jlo.handler.RollingDateFileHandlerTest

/*
* 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);       
    }
   
   
}
TOP

Related Classes of org.jzonic.jlo.handler.RollingDateFileHandlerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.