1 7 package org.jboss.cache.eviction; 8 9 import junit.framework.TestCase; 10 import org.jboss.cache.xml.XmlHelper; 11 import org.jboss.cache.config.ConfigurationException; 12 import org.jboss.cache.factories.XmlConfigurationParser; 13 import org.w3c.dom.Element ; 14 15 19 public class ElementSizeConfigurationTest extends TestCase 20 { 21 public void testXMLParse1() throws Exception 22 { 23 ElementSizeConfiguration config = new ElementSizeConfiguration(); 24 String xml = "<region name=\"abc\">" + 25 "<attribute name=\"maxNodes\">1000</attribute>" + 26 "<attribute name=\"maxElementsPerNode\">100</attribute>" + 27 "</region>"; 28 29 Element element = XmlHelper.stringToElement(xml); 30 XmlConfigurationParser.parseEvictionPolicyConfig(element, config); 31 32 assertEquals(100, config.getMaxElementsPerNode()); 33 assertEquals(1000, config.getMaxNodes()); 34 } 35 36 37 public void testXMLParse2() throws Exception 38 { 39 ElementSizeConfiguration config = new ElementSizeConfiguration(); 40 String xml = "<region name=\"abc\">" + 41 "<attribute name=\"maxNodes\">1000</attribute>" + 42 "</region>"; 43 44 Element element = XmlHelper.stringToElement(xml); 45 try 46 { 47 XmlConfigurationParser.parseEvictionPolicyConfig(element, config); 48 } 49 catch (ConfigurationException ce) 50 { 51 assertTrue("Configure exception properly thrown", true); 52 return; 53 } 54 55 fail("Invalid region Element Size configuration did not cause ConfigureException to be thrown with empty maxElementsPerNode attribute"); 56 } 57 58 59 public void testXMLParse3() throws Exception 60 { 61 ElementSizeConfiguration config = new ElementSizeConfiguration(); 62 String xml = "<region name=\"abc\">" + 63 "<attribute name=\"maxElementsPerNode\">100</attribute>" + 64 "</region>"; 65 66 Element element = XmlHelper.stringToElement(xml); 67 68 XmlConfigurationParser.parseEvictionPolicyConfig(element, config); 69 70 assertEquals(100, config.getMaxElementsPerNode()); 71 assertEquals(0, config.getMaxNodes()); 72 } 73 74 } 75 | Popular Tags |