1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 /***
24 *
25 */
26 public class TestDynamicCombinedConfiguration extends TestCase
27 {
28 private static String PATTERN ="${sys:Id}";
29 private static String PATTERN1 = "target/test-classes/testMultiConfiguration_${sys:Id}.xml";
30 private static String DEFAULT_FILE = "target/test-classes/testMultiConfiguration_default.xml";
31
32 /***
33 * Create the test case
34 *
35 * @param testName name of the test case
36 */
37 public TestDynamicCombinedConfiguration( String testName )
38 {
39 super( testName );
40 }
41
42 /***
43 * @return the suite of tests being tested
44 */
45 public static Test suite()
46 {
47 return new TestSuite( TestDynamicCombinedConfiguration.class );
48 }
49
50 public void testConfiguration() throws Exception
51 {
52 DynamicCombinedConfiguration config = new DynamicCombinedConfiguration();
53 config.setKeyPattern(PATTERN);
54 MultiFileHierarchicalConfiguration multi = new MultiFileHierarchicalConfiguration(PATTERN1);
55 config.addConfiguration(multi, "Multi");
56 XMLConfiguration xml = new XMLConfiguration(DEFAULT_FILE);
57 config.addConfiguration(xml, "Default");
58
59 verify("1001", config, 15);
60 verify("1002", config, 25);
61 verify("1003", config, 35);
62 verify("1004", config, 50);
63 }
64
65 private void verify(String key, DynamicCombinedConfiguration config, int rows)
66 {
67 System.setProperty("Id", key);
68 assertTrue(config.getInt("rowsPerPage") == rows);
69 }
70 }