1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration.reloading;
19
20 import java.io.File;
21 import java.io.FileWriter;
22
23 import org.apache.commons.configuration.PropertiesConfiguration;
24
25 import junit.framework.TestCase;
26
27 /***
28 * Test case for the ManagedReloadingStrategy class.
29 *
30 * @author Nicolas De loof
31 */
32 public class TestManagedReloadingStrategy extends TestCase
33 {
34
35 public void testManagedRefresh() throws Exception
36 {
37 File file = new File("target/testReload.properties");
38 if (file.exists())
39 {
40 file.delete();
41 }
42
43 FileWriter out = new FileWriter(file);
44 out.write("string=value1");
45 out.flush();
46 out.close();
47
48
49 PropertiesConfiguration config = new PropertiesConfiguration("target/testReload.properties");
50 ManagedReloadingStrategy strategy = new ManagedReloadingStrategy();
51 config.setReloadingStrategy(strategy);
52 assertEquals("Initial value", "value1", config.getString("string"));
53
54
55 out = new FileWriter(file);
56 out.write("string=value2");
57 out.flush();
58 out.close();
59
60
61 assertEquals("No automatic reloading", "value1", config.getString("string"));
62 strategy.refresh();
63 assertEquals("Modified value with enabled reloading", "value2", config.getString("string"));
64 }
65
66 }