/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.cache.loader;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Very basic test case that provides methods to create a cache loader config.
 *
 * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 */
public abstract class AbstractCacheLoaderTestBase extends TestCase
{

   protected final Log log = LogFactory.getLog(getClass());

   public AbstractCacheLoaderTestBase(String name) {
      super(name);
   }

   public AbstractCacheLoaderTestBase() {}

   protected void setUp() throws Exception {
      log.debug("");
      log.debug("test " + getName());
   }

    protected Element getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared) throws Exception
    {
        return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async, fetchPersistentState, shared, false);
    }

    protected Element getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
    {
        String xml = "<config>\n" +
                "<passivation>false</passivation>\n" +
                "<preload>" + preload + "</preload>\n" +
                "<cacheloader>\n" +
                "<class>" + cacheloaderClass + "</class>\n" +
                "<properties>" + properties + "</properties>\n" +
                "<async>" + async + "</async>\n" +
                "<shared>" + shared + "</shared>\n" + 
                "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
                "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +                
                "</cacheloader>\n" +
                "</config>";
        return XmlHelper.stringToElement(xml);
    }
}
