1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration;
19
20 import static org.junit.Assert.assertTrue;
21
22 import java.io.File;
23
24 import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
25 import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
26 import org.junit.Before;
27 import org.junit.Test;
28
29
30
31
32
33
34 public class TestPatternSubtreeConfiguration
35 {
36 private static String CONFIG_FILE = "target/test-classes/testPatternSubtreeConfig.xml";
37 private static String PATTERN = "BusinessClient[@name='${sys:Id}']";
38 private XMLConfiguration conf;
39
40 @Before
41 public void setUp() throws Exception
42 {
43 conf = new XMLConfiguration();
44 conf.setFile(new File(CONFIG_FILE));
45 conf.load();
46 }
47
48
49
50
51 @Test
52 public void testMultiConfiguration()
53 {
54
55 FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
56 strategy.setRefreshDelay(10000);
57
58 PatternSubtreeConfigurationWrapper config = new PatternSubtreeConfigurationWrapper(this.conf, PATTERN);
59 config.setReloadingStrategy(strategy);
60 config.setExpressionEngine(new XPathExpressionEngine());
61
62 System.setProperty("Id", "1001");
63 assertTrue(config.getInt("rowsPerPage") == 15);
64
65 System.setProperty("Id", "1002");
66 assertTrue(config.getInt("rowsPerPage") == 25);
67
68 System.setProperty("Id", "1003");
69 assertTrue(config.getInt("rowsPerPage") == 35);
70 }
71 }