1 package com.macvu.tiles.cache;
2
3 import junit.framework.TestCase;
4
5 /***
6 * Created by IntelliJ IDEA.
7 * User: MVu
8 * Date: Mar 16, 2004
9 * Time: 9:32:34 AM
10 * To change this template use File | Settings | File Templates.
11 */
12 public class CacheFactoryManagerTest extends TestCase {
13
14 public CacheFactoryManagerTest(String s) {
15 super(s);
16 }
17
18 public void testGetCacheServiceFactory() {
19 CacheFactoryManager factoryManager = new CacheFactoryManager();
20
21 String singleLRUCache = "com.macvu.tiles.cache.SingleLRUCacheServiceFactory";
22
23 try {
24 CacheServiceFactory factory = factoryManager.getCacheServiceFactory(singleLRUCache);
25 assertNotNull("valid factory class", factory);
26 } catch (Exception e) {
27 fail("Should not throw an exception: " + e.getMessage());
28 }
29
30 String badCacheFactory = "com.macvu.tiles.cache.SimpleCacheKeyFactory";
31
32 try {
33 CacheServiceFactory factory = factoryManager.getCacheServiceFactory(badCacheFactory);
34 fail("Should not get here. Should throw a class cast exception");
35 } catch (ClassCastException e) {
36 } catch (Exception e) {
37 fail("Should not throw other exception" + e.getMessage());
38 }
39
40 String invalidClass = "com.macvu.tiles.cache.CRAP";
41
42 try {
43 CacheServiceFactory factory = factoryManager.getCacheServiceFactory(invalidClass);
44 fail("Should not get here. Should throw a class cast exception");
45 } catch (ClassNotFoundException e) {
46 } catch (Exception e) {
47 fail("Should not throw other exception" + e.getMessage());
48 }
49 }
50
51 public void testGetCacheKeyServiceFactory() {
52 CacheFactoryManager factoryManager = new CacheFactoryManager();
53 String simpleKeyFactory = "com.macvu.tiles.cache.SimpleCacheKeyFactory";
54
55 try {
56 CacheKeyFactory factory = factoryManager.getCacheKeyFactory(simpleKeyFactory);
57 assertNotNull("valid factory class", factory);
58 } catch (Exception e) {
59 fail("Should not throw an exception: " + e.getMessage());
60 }
61
62 String badKeyFactory = "com.macvu.tiles.cache.SingleLRUCacheServiceFactory";
63
64 try {
65 CacheKeyFactory factory = factoryManager.getCacheKeyFactory(badKeyFactory);
66 fail("Should not get here. Should throw a class cast exception");
67 } catch (ClassCastException e) {
68 } catch (Exception e) {
69 fail("Should not throw other exception" + e.getMessage());
70 }
71
72 String invalidClass = "com.macvu.tiles.cache.CRAP";
73
74 try {
75 CacheKeyFactory factory = factoryManager.getCacheKeyFactory(invalidClass);
76 fail("Should not get here. Should throw a class cast exception");
77 } catch (ClassNotFoundException e) {
78 } catch (Exception e) {
79 fail("Should not throw other exception" + e.getMessage());
80 }
81 }
82 }
83