KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > eviction > ElementSizeConfigurationTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 JavaDoc;
14
15 /**
16  * @author Daniel Huang
17  * @version $Revision: 1.3 $
18  */

19 public class ElementSizeConfigurationTest extends TestCase
20 {
21    public void testXMLParse1() throws Exception JavaDoc
22    {
23       ElementSizeConfiguration config = new ElementSizeConfiguration();
24       String JavaDoc xml = "<region name=\"abc\">" +
25             "<attribute name=\"maxNodes\">1000</attribute>" +
26             "<attribute name=\"maxElementsPerNode\">100</attribute>" +
27             "</region>";
28
29       Element JavaDoc 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 JavaDoc
38    {
39       ElementSizeConfiguration config = new ElementSizeConfiguration();
40       String JavaDoc xml = "<region name=\"abc\">" +
41             "<attribute name=\"maxNodes\">1000</attribute>" +
42             "</region>";
43
44       Element JavaDoc 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 JavaDoc
60    {
61       ElementSizeConfiguration config = new ElementSizeConfiguration();
62       String JavaDoc xml = "<region name=\"abc\">" +
63             "<attribute name=\"maxElementsPerNode\">100</attribute>" +
64             "</region>";
65
66       Element JavaDoc 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