/*
 * 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 tests for MRUConfiguration.
 *
 * @author Daniel Huang (dhuang@jboss.org)
 * @version $Revision: 1.2 $
 */
public class MRUConfigurationTest extends TestCase
{
   MRUConfiguration config = null;

   public void setUp() throws Exception
   {
      super.setUp();
      config = new MRUConfiguration();
   }

   public void tearDown() throws Exception
   {
      super.tearDown();
   }

   public void testXMLParsing() throws Exception
   {
      String xml =
            "<region name=\"/org/jboss/data\">\n" +
                  "<attribute name=\"maxNodes\">5000</attribute>\n" +
                  "</region>";
      Element element = XmlHelper.stringToElement(xml);
      config.parseXMLConfig(element);

      assertEquals(5000, config.getMaxNodes());
   }

   public void testXMLParsing2() throws Exception
   {
      String xml = "<region name=\"/Test/\">\n" +
            "<attribute name=\"maxNodes\">10000</attribute>\n" +
            "</region>";
      Element element = XmlHelper.stringToElement(xml);
      config.parseXMLConfig(element);

      assertEquals(10000, config.getMaxNodes());
   }

   public void testXMLParsing3() throws Exception
   {
      String xml = "<region name=\"/Test/\">\n" +
            "</region>";
      Element element = XmlHelper.stringToElement(xml);
      boolean caught = false;
      try
      {
         config.parseXMLConfig(element);
      }
      catch (ConfigureException ce)
      {
         caught = true;
      }
      assertTrue("Configure exception should have been caught", caught);

      xml = "<region name=\"/Test/\">\n" +
            "<attribute name=\"maxNodes\">10000</attribute>\n" +
            "</region>";

      element = XmlHelper.stringToElement(xml);

      config.parseXMLConfig(element);
      assertEquals(10000, config.getMaxNodes());
   }

}
