1 package org.apache.commons.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 import org.apache.commons.jcs.JCS;
24 import org.apache.commons.jcs.engine.control.CompositeCacheManager;
25 import org.junit.FixMethodOrder;
26 import org.junit.runners.MethodSorters;
27
28
29
30
31
32
33
34 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
35 public class SystemPropertyUnitTest
36 extends TestCase
37 {
38
39
40
41
42
43
44
45 public void test1SystemPropertyInValueDelimiter()
46 throws Exception
47 {
48
49 int maxMemory = 1234;
50 System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
51 System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_MAX_SIZE", String.valueOf( maxMemory ) );
52
53 JCS.setConfigFilename( "/TestSystemProperties.ccf" );
54
55 CacheAccess<String, String> cache = JCS.getInstance( "test1" );
56 assertEquals( "We should have used the system property for the memory size", maxMemory, cache
57 .getCacheAttributes().getMaxObjects() );
58
59 System.clearProperty("MY_SYSTEM_PROPERTY_DISK_DIR");
60 System.clearProperty("MY_SYSTEM_PROPERTY_MAX_SIZE");
61 }
62
63
64
65
66
67
68
69
70
71 public void test2SystemPropertyMissingInValueDelimeter()
72 throws Exception
73 {
74 System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
75
76 CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance();
77 mgr.configure( "/TestSystemProperties.ccf" );
78
79 CacheAccess<String, String> cache = JCS.getInstance( "missing" );
80
81 assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes()
82 .getMaxObjects() );
83
84 System.clearProperty("MY_SYSTEM_PROPERTY_DISK_DIR");
85
86 }
87
88 }