1 package org.apache.jcs.access;
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.jcs.JCS;
25 import org.apache.jcs.engine.control.CompositeCacheManager;
26
27 /***
28 * This test is for the system property usage in configuration values.
29 *
30 * @author Aaron Smuts
31 *
32 */
33 public class SystemPropetyUnitTest
34 extends TestCase
35 {
36
37 /***
38 * Verify that we use a system property for a ${FOO} string in a value.
39 *
40 * @throws Exception
41 *
42 */
43 public void testSystemPropertyInValueDelimeter()
44 throws Exception
45 {
46
47 int maxMemory = 1234;
48 System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
49 System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_MAX_SIZE", String.valueOf( maxMemory ) );
50
51 JCS.setConfigFilename( "/TestSystemProperties.ccf" );
52
53 JCS cache = JCS.getInstance( "test1" );
54 assertEquals( "We should have used the system property for the memory size", maxMemory, cache
55 .getCacheAttributes().getMaxObjects() );
56
57 }
58
59 /***
60 * Verify that we use a system property for a ${FOO} string in a value. We
61 * define a propety in the cache.ccf file, but we do not have it as a system
62 * property. The default value should be used, if one exists.
63 *
64 * @throws Exception
65 *
66 */
67 public void testSystemPropertyMissingInValueDelimeter()
68 throws Exception
69 {
70 System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
71
72 CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance();
73 mgr.configure( "/TestSystemProperties.ccf" );
74
75 JCS cache = JCS.getInstance( "missing" );
76
77 assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes()
78 .getMaxObjects() );
79
80 }
81
82 }