package org.jboss.cache.passivation;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.cache.xml.XmlHelper;
import org.w3c.dom.Element;

/**
 * tests passivation using file cache loader
 * 
 * @author <a href="mailto:{hmesha@novell.com}">{Hany Mesha}</a>
 * @version $Id: PassivationToFileCacheLoaderTest.java 1010 2006-01-13 14:51:17Z bela $
 */
public class PassivationToFileCacheLoaderTest extends PassivationTestsBase {


   protected void configureCache() throws Exception {

      String tmp_location = null;
      String OS = System.getProperty("os.name").toLowerCase();
      if(OS.indexOf("win") > -1 || OS.indexOf("nt") > -1) {
         tmp_location=System.getProperty("java.io.tmpdir", "c:\\tmp");
      } else {
         tmp_location=System.getProperty("jva.io.tmpdir", "/tmp");
      }

       cache.setCacheLoaderConfiguration(getCacheLoaderConfig(tmp_location));
   }

    protected Element getCacheLoaderConfig(String loc) throws Exception
    {
        String xml = "            <config>\n" +
                "                \n" +
                "                <passivation>true</passivation>\n" +
                "                <preload></preload>\n" +
                "\n" +
                "                <cacheloader>\n" +
                "                    <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
                "                    <properties>\n" +
                "                    </properties>\n" +
                "                    <async>false</async>\n" +
                "                    <fetchPersistentState>false</fetchPersistentState>\n" +
                "                    <ignoreModifications>false</ignoreModifications>\n" +
                "                </cacheloader>\n" +
                "                \n" +
                "            </config>";
        return XmlHelper.stringToElement(xml);
    }


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


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

}
