1 package org.apache.commons.jcs.engine;
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.commons.jcs.JCS;
25 import org.apache.commons.jcs.access.CacheAccess;
26 import org.apache.commons.jcs.engine.control.CompositeCacheManager;
27 import org.apache.commons.jcs.utils.props.PropertyLoader;
28
29 import java.util.Properties;
30
31
32
33
34 public class SystemPropertyUsageUnitTest
35 extends TestCase
36 {
37 private static final String JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS = "jcs.default.cacheattributes.MaxObjects";
38 private static final int testValue = 6789;
39
40 private CompositeCacheManager manager = null;
41
42 @Override
43 protected void setUp() throws Exception
44 {
45 super.setUp();
46
47 manager = CompositeCacheManager.getInstance();
48 manager.shutDown();
49 }
50
51
52
53
54 @Override
55 protected void tearDown() throws Exception
56 {
57 if (manager != null)
58 {
59 manager.shutDown();
60 }
61
62 System.clearProperty(JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS);
63 super.tearDown();
64 }
65
66
67
68
69
70
71 public void testSystemPropertyUsage()
72 throws Exception
73 {
74 System.setProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS, String.valueOf(testValue) );
75
76 JCS.setConfigFilename( "/TestSystemPropertyUsage.ccf" );
77
78 CacheAccess<String, String> jcs = JCS.getInstance( "someCacheNotInFile" );
79
80 manager = CompositeCacheManager.getInstance();
81
82 assertEquals( "System property value is not reflected.", testValue, jcs.getCacheAttributes().getMaxObjects());
83 }
84
85
86
87
88
89
90
91 public void testSystemPropertyUsage_inactive()
92 throws Exception
93 {
94 System.setProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS, String.valueOf(testValue) );
95
96 manager = CompositeCacheManager.getUnconfiguredInstance();
97
98 Properties props = PropertyLoader.loadProperties( "TestSystemPropertyUsage.ccf" );
99
100 manager.configure( props, false );
101
102 CacheAccess<String, String> jcs = JCS.getInstance( "someCacheNotInFile" );
103
104 assertEquals( "System property value should not be reflected",
105 Integer.parseInt( props.getProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS ) ),
106 jcs.getCacheAttributes().getMaxObjects());
107 }
108 }