1 package org.apache.commons.jcs.auxiliary.remote.http.client;
2
3 import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
4 import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
5 import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
6 import org.apache.commons.jcs.engine.behavior.IElementSerializer;
7 import org.apache.commons.jcs.engine.control.MockCompositeCacheManager;
8 import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import junit.framework.TestCase;
30
31
32 public class RemoteHttpCacheFactoryUnitTest
33 extends TestCase
34 {
35
36 public void testCreateRemoteHttpCacheClient_Bad()
37 {
38
39 String remoteHttpClientClassName = "junk";
40 RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes();
41 cattr.setRemoteHttpClientClassName( remoteHttpClientClassName );
42
43 RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory();
44
45
46 IRemoteHttpCacheClient<String, String> result = factory.createRemoteHttpCacheClientForAttributes( cattr );
47
48
49 assertNotNull( "Should have a cache.", result );
50 assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient );
51 assertTrue( "Should be initialized", ((RemoteHttpCacheClient<String, String>)result).isInitialized() );
52 }
53
54
55 public void testCreateRemoteHttpCacheClient_default()
56 {
57
58 RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes();
59 RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory();
60
61
62 IRemoteHttpCacheClient<String, String> result = factory.createRemoteHttpCacheClientForAttributes( cattr );
63
64
65 assertNotNull( "Should have a cache.", result );
66 assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient );
67 }
68
69
70 public void testGetCache_normal()
71 {
72
73 ICompositeCacheManager cacheMgr = new MockCompositeCacheManager();
74 ICacheEventLogger cacheEventLogger = null;
75 IElementSerializer elementSerializer = null;
76
77 RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes();
78 RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory();
79
80
81 AuxiliaryCache<String, String> result = factory.createCache(cattr, cacheMgr, cacheEventLogger, elementSerializer);
82
83
84 assertNotNull( "Should have a cache.", result );
85 }
86 }