1 package org.apache.jcs.engine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }