View Javadoc
1   package org.apache.commons.jcs.auxiliary;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  /** Unit tests for the auxiliary cache configurator. */
31  public class AuxiliaryCacheConfiguratorUnitTest
32      extends TestCase
33  {
34      /**
35       * Verify that we don't get an error.
36       */
37      public void testParseCacheEventLogger_Null()
38      {
39          // SETUP
40          Properties props = new Properties();
41  
42          // DO WORK
43          MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator.parseCacheEventLogger( props,
44                                                                                                                 "junk" );
45  
46          // VERIFY
47          assertNull( "Should not have a logger.", result );
48      }
49  
50      /**
51       * Verify that we don't get an error.
52       */
53      public void testParseCacheEventLogger_NullName()
54      {
55          // SETUP
56          Properties props = new Properties();
57  
58          // DO WORK
59          MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator.parseCacheEventLogger( props,
60                                                                                                                 null );
61  
62          // VERIFY
63          assertNull( "Should not have a logger.", result );
64      }
65  
66      /**
67       * Verify that we can parse the event logger.
68       */
69      public void testParseCacheEventLogger_Normal()
70      {
71          // SETUP
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          // DO WORK
82          MockCacheEventLogger result = (MockCacheEventLogger) AuxiliaryCacheConfigurator
83              .parseCacheEventLogger( props, auxPrefix );
84  
85          // VERIFY
86          assertNotNull( "Should have a logger.", result );
87          assertEquals( "Property should be set.", testPropertyValue, result.getTestProperty() );
88      }
89  
90      /**
91       * Verify that we can parse the ElementSerializer.
92       */
93      public void testParseElementSerializer_Normal()
94      {
95          // SETUP
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         // DO WORK
106         MockElementSerializer result = (MockElementSerializer) AuxiliaryCacheConfigurator
107             .parseElementSerializer( props, auxPrefix );
108 
109         // VERIFY
110         assertNotNull( "Should have a Serializer.", result );
111         assertEquals( "Property should be set.", testPropertyValue, result.getTestProperty() );
112     }
113 
114     /**
115      * Verify that we can parse the ElementSerializer.
116      */
117     public void testParseElementSerializer_Null()
118     {
119         // SETUP
120         Properties props = new Properties();
121 
122         // DO WORK
123         IElementSerializer result = AuxiliaryCacheConfigurator
124             .parseElementSerializer( props, "junk" );
125 
126         // VERIFY
127         assertTrue( "Should have the default Serializer.", result instanceof StandardSerializer );
128     }
129 }