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