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 static org.junit.Assert.assertEquals;
21
22 import java.io.File;
23 import java.io.FileWriter;
24
25 import org.apache.commons.configuration.PropertiesConfiguration;
26 import org.junit.Test;
27
28
29
30
31
32
33
34 public class TestManagedReloadingStrategy
35 {
36 @Test
37 public void testManagedRefresh() throws Exception
38 {
39 File file = new File("target/testReload.properties");
40 if (file.exists())
41 {
42 file.delete();
43 }
44
45 FileWriter out = new FileWriter(file);
46 out.write("string=value1");
47 out.flush();
48 out.close();
49
50
51 PropertiesConfiguration config = new PropertiesConfiguration("target/testReload.properties");
52 ManagedReloadingStrategy strategy = new ManagedReloadingStrategy();
53 config.setReloadingStrategy(strategy);
54 assertEquals("Initial value", "value1", config.getString("string"));
55
56
57 out = new FileWriter(file);
58 out.write("string=value2");
59 out.flush();
60 out.close();
61
62
63 assertEquals("No automatic reloading", "value1", config.getString("string"));
64 strategy.refresh();
65 assertEquals("Modified value with enabled reloading", "value2", config.getString("string"));
66 }
67
68 }