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