package org.jboss.cache.loader;

import junit.framework.Test;
import junit.framework.TestSuite;

import java.io.File;
import java.io.FileFilter;

/**
 * Tests {@link JdbmCacheLoader}.
 * @author Elias Ross
 * @version $Id: JdbmCacheLoaderTest.java,v 1.2 2006/04/01 00:45:38 genman Exp $
 */
public class JdbmCacheLoaderTest extends ExtendedCacheLoaderTestsBase {

    private int counter = 0;
    private String tmp_location = System.getProperty("java.io.tmpdir", "/tmp");
    private File dir = new File(tmp_location);

    public JdbmCacheLoaderTest()
    {
        if (!dir.exists()) dir.mkdirs();
    }

    protected void configureCache() throws Exception {

      class MyFilter implements FileFilter {
         public boolean accept(File file) {
            return file.getName().endsWith(".db");
         }
      }

      File[] files=dir.listFiles(new MyFilter());
      if (files != null) {
         for (int i = 0; i < files.length; i += 1) {
            File file = files[i];
            if (file.isFile()) {
               if (!file.delete()) {
                  System.err.println("Unable to delete: " + file);
               }
            }
         }
      }

    cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.jdbm.JdbmCacheLoader", "", false, true, false));
   }

   public static Test suite() {
      return new TestSuite(JdbmCacheLoaderTest.class);
   }

    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

}
