1   package org.apache.jcs.engine;
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 java.util.Properties;
23  
24  import junit.framework.TestCase;
25  
26  import org.apache.jcs.JCS;
27  import org.apache.jcs.engine.control.CompositeCacheManager;
28  import org.apache.jcs.utils.props.PropertyLoader;
29  
30  /***
31   * Verify that system properties can override.
32   */
33  public class SystemPropertyUsageUnitTest
34      extends TestCase
35  {
36  
37      /***
38       * Verify that the system properties are used.
39       * @throws Exception
40       *
41       */
42      public void testSystemPropertyUsage()
43          throws Exception
44      {
45          System.getProperties().setProperty( "jcs.default.cacheattributes.MaxObjects", "6789" );
46  
47          JCS.setConfigFilename( "/TestSystemPropertyUsage.ccf" );
48  
49          JCS jcs = JCS.getInstance( "someCacheNotInFile" );
50  
51          assertEquals( "System property value is not reflected", jcs.getCacheAttributes().getMaxObjects(), Integer
52              .parseInt( "6789" ) );
53  
54      }
55  
56      /***
57       * Verify that the system properties are not used is specified.
58       *
59       * @throws Exception
60       *
61       */
62      public void testSystemPropertyUsage_inactive()
63          throws Exception
64      {
65          System.getProperties().setProperty( "jcs.default.cacheattributes.MaxObjects", "6789" );
66  
67          CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance();
68  
69          Properties props = PropertyLoader.loadProperties( "TestSystemPropertyUsage.ccf" );
70  
71          mgr.configure( props, false );
72  
73          JCS jcs = JCS.getInstance( "someCacheNotInFile" );
74  
75          assertFalse( "System property value should not be reflected",
76                       jcs.getCacheAttributes().getMaxObjects() == Integer.parseInt( props
77                           .getProperty( "jcs.default.cacheattributes.MaxObjects" ) ) );
78  
79      }
80  }