2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.commons.configuration.tree;
19
import junit.framework.TestCase;
22
* Test class for ViewNode.
24
* @version $Id: TestViewNode.java 439648 2006-09-02 20:42:10Z oheger $
26
public class TestViewNode extends TestCase
28
/** Stores the view node to be tested. */
31
/** Stores a regular node. */
32
ConfigurationNode node;
34
/** A child node of the regular node. */
35
ConfigurationNode child;
37
/** An attribute node of the regular node. */
38
ConfigurationNode attr;
40
protected void setUp() throws Exception
43
node = new DefaultConfigurationNode();
44
child = new DefaultConfigurationNode("child");
45
attr = new DefaultConfigurationNode("attr");
47
node.addAttribute(attr);
48
viewNode = new ViewNode();
52
* Tests adding a child to the view node.
54
public void testAddChild()
56
viewNode.addChild(child);
57
assertEquals("Parent was changed", node, child.getParentNode());
58
assertEquals("Child was not added", 1, viewNode.getChildrenCount());
62
* Tests adding a null child to the view node. This should throw an
65
public void testAddNullChild()
69
viewNode.addChild(null);
70
fail("Could add null child!");
72
catch (IllegalArgumentException iex)
79
* Tests adding an attribute to the view node.
81
public void testAddAttribute()
83
viewNode.addAttribute(attr);
84
assertEquals("Parent was changed", node, attr.getParentNode());
85
assertEquals("Attribute was not added", 1, viewNode.getAttributeCount());
89
* Tests adding a null attribute to the view node. This should cause an
92
public void testAddNullAttribute()
96
viewNode.addAttribute(null);
97
fail("Could add null attribute");
99
catch (IllegalArgumentException iex)
106
* Tests appending all children to a view node.
108
public void testAppendChildren()
110
viewNode.addChild(new DefaultConfigurationNode("testNode"));
111
viewNode.appendChildren(node);
112
assertEquals("Wrong number of children", 2, viewNode.getChildrenCount());
113
assertEquals("Cannot find child", child, viewNode.getChild(1));
114
assertEquals("Parent was changed", node, ((ConfigurationNode) viewNode
115
.getChild(1)).getParentNode());
119
* Tests appending children from a null source. This should be a noop.
121
public void testAppendNullChildren()
123
viewNode.appendChildren(null);
124
assertEquals("Wrong number of children", 0, viewNode.getChildrenCount());
128
* tests appending all attributes to a view node.
130
public void testAppendAttributes()
132
viewNode.appendAttributes(node);
133
assertEquals("Wrong number of attributes", 1, viewNode
134
.getAttributeCount());
135
assertEquals("Cannot find attribute", attr, viewNode.getAttribute(0));
136
assertEquals("Parent was changed", node, ((ConfigurationNode) viewNode
137
.getAttribute(0)).getParentNode());
141
* Tests appending attributes from a null source. This should be a noop.
143
public void testAppendNullAttributes()
145
viewNode.appendAttributes(null);
146
assertEquals("Wrong number of attributes", 0, viewNode
147
.getAttributeCount());