1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.event;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21
22 import org.apache.commons.configuration.AbstractConfiguration;
23 import org.apache.commons.configuration.HierarchicalConfiguration;
24 import org.apache.commons.configuration.tree.DefaultConfigurationNode;
25
26 /***
27 * Test class for the events generated by hierarchical configurations.
28 *
29 * @version $Id: TestHierarchicalConfigurationEvents.java 439648 2006-09-02 20:42:10Z oheger $
30 */
31 public class TestHierarchicalConfigurationEvents extends
32 AbstractTestConfigurationEvents
33 {
34 protected AbstractConfiguration createConfiguration()
35 {
36 return new HierarchicalConfiguration();
37 }
38
39 /***
40 * Tests events generated by the clearTree() method.
41 */
42 public void testClearTreeEvent()
43 {
44 HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
45 String key = EXIST_PROPERTY.substring(0, EXIST_PROPERTY.indexOf('.'));
46 Collection nodes = hc.getExpressionEngine()
47 .query(hc.getRootNode(), key);
48 hc.clearTree(key);
49 l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key, null,
50 true);
51 l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key, nodes,
52 false);
53 l.done();
54 }
55
56 /***
57 * Tests events generated by the addNodes() method.
58 */
59 public void testAddNodesEvent()
60 {
61 HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
62 Collection nodes = new ArrayList(1);
63 nodes.add(new DefaultConfigurationNode("a_key", TEST_PROPVALUE));
64 hc.addNodes(TEST_PROPNAME, nodes);
65 l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES, TEST_PROPNAME,
66 nodes, true);
67 l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES, TEST_PROPNAME,
68 nodes, false);
69 l.done();
70 }
71
72 /***
73 * Tests events generated by addNodes() when the list of nodes is empty. In
74 * this case no events should be generated.
75 */
76 public void testAddNodesEmptyEvent()
77 {
78 ((HierarchicalConfiguration) config).addNodes(TEST_PROPNAME,
79 new ArrayList());
80 l.done();
81 }
82 }