/*
 * 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;

/**
 * @author Daniel Huang
 * @version $Revision: 1.1 $
 */
public class ElementSizeConfigurationTest extends TestCase
{
   public void testXMLParse1() throws Exception
   {
      ElementSizeConfiguration config = new ElementSizeConfiguration();
      String xml = "<region name=\"abc\">" +
            "<attribute name=\"maxNodes\">1000</attribute>" +
            "<attribute name=\"maxElementsPerNode\">100</attribute>" +
            "</region>";

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

      assertEquals(100, config.getMaxElementsPerNode());
      assertEquals(1000, config.getMaxNodes());
   }


   public void testXMLParse2() throws Exception
   {
      ElementSizeConfiguration config = new ElementSizeConfiguration();
      String xml = "<region name=\"abc\">" +
            "<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 Element Size configuration did not cause ConfigureException to be thrown with empty maxElementsPerNode attribute");
   }


   public void testXMLParse3() throws Exception
   {
      ElementSizeConfiguration config = new ElementSizeConfiguration();
      String xml = "<region name=\"abc\">" +
            "<attribute name=\"maxElementsPerNode\">100</attribute>" +
            "</region>";

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

      assertEquals(100, config.getMaxElementsPerNode());
      assertEquals(0, config.getMaxNodes());
   }

}
