KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > eviction > RegionManagerTest


1 package org.jboss.cache.tests.eviction;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import org.jboss.cache.eviction.Region;
7 import org.jboss.cache.eviction.RegionManager;
8 import org.jboss.cache.eviction.RegionNameConflictException;
9
10 /**
11  * @author Ben Wang, Feb 11, 2004
12  */

13 public class RegionManagerTest extends TestCase
14 {
15    private final String JavaDoc DEFAULT_REGION = "/_default_/";
16
17    public RegionManagerTest(String JavaDoc s)
18    {
19       super(s);
20    }
21
22    public void setUp() throws Exception JavaDoc
23    {
24       super.setUp();
25    }
26
27    public void tearDown() throws Exception JavaDoc
28    {
29       super.tearDown();
30    }
31
32    public void testCreateRegion() {
33       String JavaDoc fqn1 = "/a/b/c";
34       String JavaDoc fqn2 = "/a/b";
35       String JavaDoc fqn3 = "/aop";
36
37       RegionManager regionManager = new RegionManager(null);
38       try {
39          regionManager.createRegion(DEFAULT_REGION, null);
40          regionManager.createRegion(fqn1, null);
41          regionManager.createRegion(fqn2, null);
42          regionManager.createRegion(fqn3, null);
43       } catch (RegionNameConflictException e) {
44          fail("Failed to create region");
45          e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
46
}
47
48       Region[] regions = regionManager.getRegions();
49       assertEquals("Region size ", 4, regions.length);
50    }
51
52    public void testCreateRegion2() {
53       String JavaDoc fqn1 = "/a/b/c";
54       String JavaDoc fqn2 = "/a/b/";
55
56       RegionManager regionManager = new RegionManager(null);
57       try {
58          regionManager.createRegion(fqn1, null);
59          regionManager.createRegion(fqn2, null);
60       } catch (RegionNameConflictException e) {
61          fail("Failed to create region");
62          e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
63
}
64
65       Region[] regions = regionManager.getRegions();
66       assertEquals("Region size ", 2, regions.length);
67       assertEquals("Region 0 ", "/a/b/", regions[0].getFqn());
68       assertEquals("Region 1 ", "/a/b/c/", regions[1].getFqn());
69       Region region = regionManager.getRegion("/a/b/c/d");
70       assertNotNull("Region ", region);
71       assertEquals("Region ", "/a/b/c/", region.getFqn());
72       region = regionManager.getRegion("/a/b");
73       assertNotNull("Region ", region);
74       assertEquals("Region ", "/a/b/", region.getFqn());
75       region = regionManager.getRegion("/a");
76       assertNull("Region ", region);
77    }
78
79    public void testRegionConflict() {
80       String JavaDoc fqn1 = "/a/b";
81       String JavaDoc fqn2 = "/a/b/c";
82       String JavaDoc fqn3 = "/aop";
83
84       RegionManager regionManager = new RegionManager(null);
85       try {
86          regionManager.createRegion(DEFAULT_REGION, null);
87          regionManager.createRegion(fqn1, null);
88          regionManager.createRegion(fqn2, null);
89          regionManager.createRegion(fqn3, null);
90       } catch (RegionNameConflictException e) {
91          Region[] regions = regionManager.getRegions();
92          assertEquals("Region size ", 2, regions.length);
93          return;
94       }
95       fail("testRegionConflict failed");
96    }
97
98    public void testRegionConflict2() {
99       String JavaDoc fqn1 = "/a/b/";
100       String JavaDoc fqn2 = "/a/b/c/";
101       String JavaDoc fqn3 = "/a/bc";
102
103       RegionManager regionManager = new RegionManager(null);
104       try {
105          regionManager.createRegion(fqn1, null);
106          regionManager.createRegion(fqn2, null);
107          regionManager.createRegion(fqn3, null);
108       } catch (RegionNameConflictException e) {
109          Region[] regions = regionManager.getRegions();
110          assertEquals("Region size ", 1, regions.length);
111          return;
112       }
113       fail("testRegionConflict failed");
114    }
115
116    public void testGetRegion() {
117       String JavaDoc fqn1 = "/a/bc";
118       String JavaDoc fqn2 = "/a/b";
119
120       RegionManager regionManager = new RegionManager(null);
121       try {
122          regionManager.createRegion(fqn1, null);
123       } catch (RegionNameConflictException e) {
124          fail("testRegionConflict3 failed " +e);
125       }
126
127       Region region = regionManager.getRegion(fqn2);
128       assertNull("Region " , region);
129    }
130
131    void log(String JavaDoc msg)
132    {
133       System.out.println("-- " + msg);
134    }
135
136    public static Test suite()
137    {
138       return new TestSuite(RegionManagerTest.class);
139    }
140
141    public static void main(String JavaDoc[] args)
142    {
143       junit.textui.TestRunner.run(suite());
144    }
145
146 }
147
Popular Tags