KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > loader > ChainingCacheLoaderBasicTest


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.loader;
8
9 import junit.framework.Test;
10 import junit.framework.TestSuite;
11
12 import org.jboss.cache.config.CacheLoaderConfig;
13 import org.jboss.cache.factories.XmlConfigurationParser;
14 import org.jboss.cache.xml.XmlHelper;
15 import org.w3c.dom.Element JavaDoc;
16
17 import java.io.File JavaDoc;
18
19 /**
20  * Tests basic functionality of a chaining cache loader with 2 different loaders
21  *
22  * @author <a HREF="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
23  */

24 public class ChainingCacheLoaderBasicTest extends CacheLoaderTestsBase
25 {
26     private String JavaDoc loc1 = System.getProperty("java.io.tmpdir", ".") + File.separator + "JBossCache-ChainingCacheLoaderBasicTest-1";
27     private String JavaDoc loc2 = System.getProperty("java.io.tmpdir", ".") + File.separator + "JBossCache-ChainingCacheLoaderBasicTest-2";
28
29     public ChainingCacheLoaderBasicTest()
30     {
31         File JavaDoc dir1 = new File JavaDoc(loc1);
32         File JavaDoc dir2 = new File JavaDoc(loc2);
33
34         if (!dir1.exists()) dir1.mkdirs();
35         if (!dir2.exists()) dir2.mkdirs();
36     }
37
38     protected void configureCache() throws Exception JavaDoc
39     {
40         cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(loc1, loc2));
41     }
42
43     protected CacheLoaderConfig getCacheLoaderConfig(String JavaDoc loc1, String JavaDoc loc2) throws Exception JavaDoc
44     {
45         String JavaDoc xml = "<config>\n" +
46                 "<passivation>false</passivation>\n" +
47                 "<preload></preload>\n" +
48                 "<cacheloader>\n" +
49                 "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
50                 "<properties>" +
51                 " location=" + loc1 + "\n" +
52                 "</properties>\n" +
53                 "<async>false</async>\n" +
54                 "<fetchPersistentState>true</fetchPersistentState>\n" +
55                 "</cacheloader>\n" +
56                 "<cacheloader>\n" +
57                 "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
58                 "<properties>" +
59                 " location=" + loc2 + "\n" +
60                 "</properties>\n" +
61                 "<async>false</async>\n" +
62                 "<fetchPersistentState>false</fetchPersistentState>\n" +
63                 "</cacheloader>\n" +
64                 "</config>";
65         Element JavaDoc element = XmlHelper.stringToElement(xml);
66         return XmlConfigurationParser.parseCacheLoaderConfig(element);
67     }
68
69     public static Test suite()
70     {
71         return new TestSuite(ChainingCacheLoaderBasicTest.class);
72     }
73
74
75     public static void main(String JavaDoc[] args)
76     {
77         junit.textui.TestRunner.run(suite());
78     }
79 }
80
Popular Tags