KickJava   Java API By Example, From Geeks To Geeks.

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


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 MRUConfiguration.
17  *
18  * @author Daniel Huang (dhuang@jboss.org)
19  * @version $Revision: 1.5 $
20  */

21 public class MRUConfigurationTest extends TestCase
22 {
23    MRUConfiguration config = null;
24
25    public void setUp() throws Exception JavaDoc
26    {
27       super.setUp();
28       config = new MRUConfiguration();
29    }
30
31    public void tearDown() throws Exception JavaDoc
32    {
33       super.tearDown();
34    }
35
36    public void testXMLParsing() throws Exception JavaDoc
37    {
38       String JavaDoc xml =
39             "<region name=\"/org/jboss/data\">\n" +
40                   "<attribute name=\"maxNodes\">5000</attribute>\n" +
41                   "</region>";
42       Element JavaDoc element = XmlHelper.stringToElement(xml);
43
44       XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
45
46       assertEquals(5000, config.getMaxNodes());
47    }
48
49    public void testXMLParsing2() throws Exception JavaDoc
50    {
51       String JavaDoc xml = "<region name=\"/Test/\">\n" +
52             "<attribute name=\"maxNodes\">10000</attribute>\n" +
53             "</region>";
54       Element JavaDoc element = XmlHelper.stringToElement(xml);
55
56       XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
57
58       assertEquals(10000, config.getMaxNodes());
59    }
60
61    public void testXMLParsing3() throws Exception JavaDoc
62    {
63       String JavaDoc xml = "<region name=\"/Test/\">\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, maxNodes is required", caught);
76
77       xml = "<region name=\"/Test/\">\n" +
78             "<attribute name=\"maxNodes\">10000</attribute>\n" +
79             "</region>";
80
81       element = XmlHelper.stringToElement(xml);
82
83       XmlConfigurationParser.parseEvictionPolicyConfig(element, config);
84
85       assertEquals(10000, config.getMaxNodes());
86    }
87
88 }
89
Popular Tags