/*
 * JBoss, the OpenSource J2EE webOS
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.cache.eviction;

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

/**
 * Unit test for FIFOConfiguration.
 *
 * @author Daniel Huang (dhuang@jboss.org)
 * @version $Revision: 1852 $
 */
public class FIFOConfigurationTest extends TestCase
{

   public void testXMLParse() throws Exception
   {
      FIFOConfiguration config = new FIFOConfiguration();
      String xml = "<region name=\"abc\">" +
            "<attribute name=\"maxNodes\">1000</attribute>" +
            "</region>";

      Element element = XmlHelper.stringToElement(xml);
      config.parseXMLConfig(element);

      assertEquals(1000, config.getMaxNodes());

   }

   public void testXMLParse2() throws Exception
   {
      FIFOConfiguration config = new FIFOConfiguration();
      String xml = "<region name=\"abc\">" +
            "</region>";

      Element element = XmlHelper.stringToElement(xml);

      try
      {
         config.parseXMLConfig(element);
      }
      catch (ConfigureException ce)
      {
         assertTrue("Configure Exception properly thrown", true);
         return;
      }
      fail("Invalid region FIFO configuration did not cause ConfigureException to be thrown");
   }

   public void testXMLParse3() throws Exception
   {
      FIFOConfiguration config = new FIFOConfiguration();
      String xml = "<region>" +
            "<attribute name=\"maxNodes\">1000</attribute>" +
            "</region>";

      Element element = XmlHelper.stringToElement(xml);

      try
      {
         config.parseXMLConfig(element);
      }
      catch (ConfigureException ce)
      {
         assertTrue("Configure Exception properly thrown", true);
         return;
      }

      fail("Invalid region FIFO configuration did not cause ConfigureException to be thrown");
   }
}
