1 package org.apache.commons.jcs.auxiliary;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.commons.jcs.engine.behavior.IElementSerializer;
24 import org.apache.commons.jcs.engine.control.MockElementSerializer;
25 import org.apache.commons.jcs.engine.logging.MockCacheEventLogger;
26 import org.apache.commons.jcs.utils.serialization.StandardSerializer;
27
28 import java.util.Properties;
29
30
31 public class AuxiliaryCacheConfiguratorUnitTest
32 extends TestCase
33 {
34
35
36
37 public void testParseCacheEventLogger_Null()
38 {
39
40 Properties props = new Properties();
41
42
43 MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator.parseCacheEventLogger( props,
44 "junk" );
45
46
47 assertNull( "Should not have a logger.", result );
48 }
49
50
51
52
53 public void testParseCacheEventLogger_NullName()
54 {
55
56 Properties props = new Properties();
57
58
59 MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator.parseCacheEventLogger( props,
60 null );
61
62
63 assertNull( "Should not have a logger.", result );
64 }
65
66
67
68
69 public void testParseCacheEventLogger_Normal()
70 {
71
72 String auxPrefix = "jcs.auxiliary." + "MYAux";
73 String testPropertyValue = "This is the value";
74 String className = MockCacheEventLogger.class.getName();
75
76 Properties props = new Properties();
77 props.put( auxPrefix + AuxiliaryCacheConfigurator.CACHE_EVENT_LOGGER_PREFIX, className );
78 props.put( auxPrefix + AuxiliaryCacheConfigurator.CACHE_EVENT_LOGGER_PREFIX
79 + AuxiliaryCacheConfigurator.ATTRIBUTE_PREFIX + ".testProperty", testPropertyValue );
80
81
82 MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator
83 .parseCacheEventLogger( props, auxPrefix );
84
85
86 assertNotNull( "Should have a logger.", result );
87 assertEquals( "Property should be set.", testPropertyValue, result.getTestProperty() );
88 }
89
90
91
92
93 public void testParseElementSerializer_Normal()
94 {
95
96 String auxPrefix = "jcs.auxiliary." + "MYAux";
97 String testPropertyValue = "This is the value";
98 String className = MockElementSerializer.class.getName();
99
100 Properties props = new Properties();
101 props.put( auxPrefix + AuxiliaryCacheConfigurator.SERIALIZER_PREFIX, className );
102 props.put( auxPrefix + AuxiliaryCacheConfigurator.SERIALIZER_PREFIX
103 + AuxiliaryCacheConfigurator.ATTRIBUTE_PREFIX + ".testProperty", testPropertyValue );
104
105
106 MockElementSerializer result = (MockElementSerializer) AuxiliaryCacheConfigurator
107 .parseElementSerializer( props, auxPrefix );
108
109
110 assertNotNull( "Should have a Serializer.", result );
111 assertEquals( "Property should be set.", testPropertyValue, result.getTestProperty() );
112 }
113
114
115
116
117 public void testParseElementSerializer_Null()
118 {
119
120 Properties props = new Properties();
121
122
123 IElementSerializer result = AuxiliaryCacheConfigurator
124 .parseElementSerializer( props, "junk" );
125
126
127 assertTrue( "Should have the default Serializer.", result instanceof StandardSerializer );
128 }
129 }