KickJava   Java API By Example, From Geeks To Geeks.

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


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.config.ConfigurationException;
11 import org.jboss.cache.factories.XmlConfigurationParser;
12 import org.jboss.cache.xml.XmlHelper;
13 import org.w3c.dom.Element JavaDoc;
14
15 /**
16  * Unit tests for LRUConfiguration.
17  *
18  * @author Daniel Huang (dhuang@jboss.org)
19  * @version $Revision: 1.5 $
20  */

21 public class LRUConfigurationTest extends TestCase
22 {
23
24    public void testXMLParsing() throws Exception JavaDoc
25    {
26       LRUConfiguration config = new LRUConfiguration();
27       String JavaDoc xml =
28             "<region name=\"/org/jboss/data\">\n" +
29                   "<attribute name=\"maxNodes\">5000</attribute>\n" +
30                   "<attribute name=\"timeToLiveSeconds\">1000</attribute>\n" +
31                   "</region>";
32
33       Element JavaDoc element = XmlHelper.stringToElement(xml);
34
35       XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
36
37       assertEquals(5000, config.getMaxNodes());
38       assertEquals(1000, config.getTimeToLiveSeconds());
39    }
40
41    public void testXMLParsing2() throws Exception JavaDoc
42    {
43       LRUConfiguration config = new LRUConfiguration();
44       String JavaDoc xml = "<region name=\"/maxAgeTest/\">\n" +
45             "<attribute name=\"maxNodes\">10000</attribute>\n" +
46             "<attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
47             "<attribute name=\"maxAgeSeconds\">10</attribute>\n" +
48             "</region>";
49       Element JavaDoc element = XmlHelper.stringToElement(xml);
50
51       XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
52
53       assertEquals(10000, config.getMaxNodes());
54       assertEquals(8, config.getTimeToLiveSeconds());
55       assertEquals(10, config.getMaxAgeSeconds());
56    }
57
58    public void testXMLParsing3() throws Exception JavaDoc
59    {
60       LRUConfiguration config = new LRUConfiguration();
61       String JavaDoc xml = "<region name=\"/maxAgeTest/\">\n" +
62             "<attribute name=\"maxNodes\">10000</attribute>\n" +
63             "<attribute name=\"maxAgeSeconds\">10</attribute>\n" +
64             "</region>";
65       Element JavaDoc element = XmlHelper.stringToElement(xml);
66       boolean caught = false;
67       try
68       {
69          XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
70       }
71       catch (ConfigurationException ce)
72       {
73          caught = true;
74       }
75       assertTrue("Configure exception should have been caught", caught);
76
77       xml = "<region name=\"/maxAgeTest/\">\n" +
78             "<attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
79             "<attribute name=\"maxAgeSeconds\">10</attribute>\n" +
80             "</region>";
81
82       element = XmlHelper.stringToElement(xml);
83
84       XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
85
86       assertEquals(0, config.getMaxNodes());
87    }
88 }
89
Popular Tags