package org.jboss.cache.aop.loader;

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

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

/**
 * Runs the same tests as {@link org.jboss.cache.loader.FileCacheLoaderTest}, but with Berkeley DB instead of a file-based CacheLoader
 * @author Bela Ban
 * @version $Id: BdbjeCacheLoaderTest.java 3389 2007-01-10 20:55:25Z msurtani $
 */
public class BdbjeCacheLoaderTest extends CacheLoaderTestsBase {

    private int counter = 0;
    private String tmp_location = System.getProperty("java.io.tmpdir", "c:\\tmp");
    private File dir = new File(tmp_location + File.separator + "JBossCache_AOP_BDBJECacheLoaderTest");

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

    protected void configureCache() throws Exception {

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

      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.bdbje.BdbjeCacheLoader", "", false, true, false));
   }

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

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

}
