001 package org.apache.jcs.auxiliary;
002
003 import java.util.Properties;
004
005 import junit.framework.TestCase;
006
007 import org.apache.jcs.engine.behavior.IElementSerializer;
008 import org.apache.jcs.engine.control.MockElementSerializer;
009 import org.apache.jcs.engine.logging.MockCacheEventLogger;
010 import org.apache.jcs.utils.serialization.StandardSerializer;
011
012 /** Unit tests for the auxiliary cache configurator. */
013 public class AuxiliaryCacheConfiguratorUnitTest
014 extends TestCase
015 {
016 /**
017 * Verify that we don't get an error.
018 */
019 public void testParseCacheEventLogger_Null()
020 {
021 // SETUP
022 Properties props = new Properties();
023
024 // DO WORK
025 MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator.parseCacheEventLogger( props,
026 "junk" );
027
028 // VERIFY
029 assertNull( "Should not have a logger.", result );
030 }
031
032 /**
033 * Verify that we don't get an error.
034 */
035 public void testParseCacheEventLogger_NullName()
036 {
037 // SETUP
038 Properties props = new Properties();
039
040 // DO WORK
041 MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator.parseCacheEventLogger( props,
042 null );
043
044 // VERIFY
045 assertNull( "Should not have a logger.", result );
046 }
047
048 /**
049 * Verify that we can parse the event logger.
050 */
051 public void testParseCacheEventLogger_Normal()
052 {
053 // SETUP
054 String auxPrefix = "jcs.auxiliary." + "MYAux";
055 String testPropertyValue = "This is the value";
056 String className = MockCacheEventLogger.class.getName();
057
058 Properties props = new Properties();
059 props.put( auxPrefix + AuxiliaryCacheConfigurator.CACHE_EVENT_LOGGER_PREFIX, className );
060 props.put( auxPrefix + AuxiliaryCacheConfigurator.CACHE_EVENT_LOGGER_PREFIX
061 + AuxiliaryCacheConfigurator.ATTRIBUTE_PREFIX + ".testProperty", testPropertyValue );
062
063 // DO WORK
064 MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator
065 .parseCacheEventLogger( props, auxPrefix );
066
067 // VERIFY
068 assertNotNull( "Should have a logger.", result );
069 assertEquals( "Property should be set.", testPropertyValue, result.getTestProperty() );
070 }
071
072 /**
073 * Verify that we can parse the ElementSerializer.
074 */
075 public void testParseElementSerializer_Normal()
076 {
077 // SETUP
078 String auxPrefix = "jcs.auxiliary." + "MYAux";
079 String testPropertyValue = "This is the value";
080 String className = MockElementSerializer.class.getName();
081
082 Properties props = new Properties();
083 props.put( auxPrefix + AuxiliaryCacheConfigurator.SERIALIZER_PREFIX, className );
084 props.put( auxPrefix + AuxiliaryCacheConfigurator.SERIALIZER_PREFIX
085 + AuxiliaryCacheConfigurator.ATTRIBUTE_PREFIX + ".testProperty", testPropertyValue );
086
087 // DO WORK
088 MockElementSerializer result = (MockElementSerializer) AuxiliaryCacheConfigurator
089 .parseElementSerializer( props, auxPrefix );
090
091 // VERIFY
092 assertNotNull( "Should have a Serializer.", result );
093 assertEquals( "Property should be set.", testPropertyValue, result.getTestProperty() );
094 }
095
096 /**
097 * Verify that we can parse the ElementSerializer.
098 */
099 public void testParseElementSerializer_Null()
100 {
101 // SETUP
102 Properties props = new Properties();
103
104 // DO WORK
105 IElementSerializer result = AuxiliaryCacheConfigurator
106 .parseElementSerializer( props, "junk" );
107
108 // VERIFY
109 assertTrue( "Should have the default Serializer.", result instanceof StandardSerializer );
110 }
111 }