01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: protected AbstractConfiguration createConfiguration() {
34: return new HierarchicalConfiguration();
35: }
36:
37: /**
38: * Tests events generated by the clearTree() method.
39: */
40: public void testClearTreeEvent() {
41: HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
42: String key = EXIST_PROPERTY.substring(0, EXIST_PROPERTY
43: .indexOf('.'));
44: Collection nodes = hc.getExpressionEngine().query(
45: hc.getRootNode(), key);
46: hc.clearTree(key);
47: l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key,
48: null, true);
49: l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key,
50: nodes, false);
51: l.done();
52: }
53:
54: /**
55: * Tests events generated by the addNodes() method.
56: */
57: public void testAddNodesEvent() {
58: HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
59: Collection nodes = new ArrayList(1);
60: nodes
61: .add(new DefaultConfigurationNode("a_key",
62: TEST_PROPVALUE));
63: hc.addNodes(TEST_PROPNAME, nodes);
64: l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES,
65: TEST_PROPNAME, nodes, true);
66: l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES,
67: TEST_PROPNAME, nodes, false);
68: l.done();
69: }
70:
71: /**
72: * Tests events generated by addNodes() when the list of nodes is empty. In
73: * this case no events should be generated.
74: */
75: public void testAddNodesEmptyEvent() {
76: ((HierarchicalConfiguration) config).addNodes(TEST_PROPNAME,
77: new ArrayList());
78: l.done();
79: }
80: }
|