1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ehcache.config;
18
19 import net.sf.ehcache.AbstractCacheTest;
20 import net.sf.ehcache.CacheManager;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import java.io.File;
25 import java.io.IOException;
26
27
28
29
30
31
32
33 public class ConfigurationHelperTest extends AbstractCacheTest {
34
35 private static final Log LOG = LogFactory.getLog(ConfigurationHelperTest.class.getName());
36
37
38
39
40
41 public void testValidParameters() {
42 Configuration configuration = new Configuration();
43 CacheConfiguration defaultCache = new CacheConfiguration();
44 defaultCache.setEternal(false);
45
46 ConfigurationHelper configurationHelper =
47 new ConfigurationHelper(manager, configuration);
48 assertNotNull(configurationHelper);
49 }
50
51
52
53
54 public void testNullParameters() {
55 try {
56 new ConfigurationHelper((CacheManager) null, null);
57 fail();
58 } catch (Exception e) {
59
60 LOG.debug("Expected exception " + e.getMessage() + ". Initial cause was " + e.getMessage(), e);
61 }
62 }
63
64
65
66
67
68
69
70 public void testDiskStorePathExpansion() throws IOException {
71 DiskStoreConfiguration diskStore = new DiskStoreConfiguration();
72
73 specificPathTest(diskStore, "java.io.tmpdir", "java.io.tmpdir");
74 specificPathTest(diskStore, "java.io.tmpdir/cacheManager1", "java.io.tmpdir");
75 specificPathTest(diskStore, "java.io.tmpdir/cacheManager1/", "java.io.tmpdir");
76 specificPathTest(diskStore, "user.dir", "user.dir");
77 specificPathTest(diskStore, "user.dir/cacheManager1", "user.dir");
78 specificPathTest(diskStore, "user.dir/cacheManager1/", "user.dir");
79 specificPathTest(diskStore, "user.home", "user.home");
80 specificPathTest(diskStore, "user.home/cacheManager1", "user.home");
81 specificPathTest(diskStore, "user.home/cacheManager1/", "user.home");
82 specificPathTest(diskStore, "user.home/cacheManager1/dir1", "user.home");
83
84
85 }
86
87 private void specificPathTest(DiskStoreConfiguration diskStore, String specifiedPath, String systemProperty) {
88 diskStore.setPath(specifiedPath);
89 String expandedPath = diskStore.getPath();
90 assertTrue(expandedPath.indexOf(systemProperty) == -1);
91
92 File diskDir = null;
93 try {
94 diskDir = new File(expandedPath);
95 diskDir.mkdirs();
96 assertTrue(diskDir.exists());
97 assertTrue(diskDir.isDirectory());
98 } finally {
99
100 if (diskDir.getPath().indexOf("cacheManager1") != -1) {
101 diskDir.delete();
102 }
103 }
104 }
105 }