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.tree;
18:
19: import java.util.List;
20:
21: import junit.framework.TestCase;
22:
23: /**
24: * Test class for NodeAddData.
25: *
26: * @author Oliver Heger
27: */
28: public class TestNodeAddData extends TestCase {
29: /** Constant for the default parent node used for testing. */
30: private static final ConfigurationNode TEST_PARENT = new DefaultConfigurationNode(
31: "parent");
32:
33: /** Constant for the name of the new node. */
34: private static final String TEST_NODENAME = "testNewNode";
35:
36: /** Constant for the name of a path node. */
37: private static final String PATH_NODE_NAME = "PATHNODE";
38:
39: /** Constant for the number of path nodes to be added. */
40: private static final int PATH_NODE_COUNT = 10;
41:
42: /** The object to be tested. */
43: NodeAddData addData;
44:
45: protected void setUp() throws Exception {
46: super .setUp();
47: addData = new NodeAddData(TEST_PARENT, TEST_NODENAME);
48: }
49:
50: /**
51: * Tests the default values of an unitialized instance.
52: */
53: public void testUninitialized() {
54: addData = new NodeAddData();
55: assertNull("A parent is set", addData.getParent());
56: assertNull("Node has a name", addData.getNewNodeName());
57: assertFalse("Attribute flag is set", addData.isAttribute());
58: assertTrue("Path nodes are not empty", addData.getPathNodes()
59: .isEmpty());
60: }
61:
62: /**
63: * Tests the constructor that initializes the most important fields.
64: */
65: public void testInitialized() {
66: assertSame("Wrong parent", TEST_PARENT, addData.getParent());
67: assertEquals("Wrong node name", TEST_NODENAME, addData
68: .getNewNodeName());
69: assertFalse("Attribute flag is set", addData.isAttribute());
70: assertTrue("Path nodes are not empty", addData.getPathNodes()
71: .isEmpty());
72: }
73:
74: /**
75: * Tests adding path nodes.
76: */
77: public void testAddPathNode() {
78: for (int i = 0; i < PATH_NODE_COUNT; i++) {
79: addData.addPathNode(PATH_NODE_NAME + i);
80: }
81:
82: List nodes = addData.getPathNodes();
83: assertEquals("Incorrect number of path nodes", PATH_NODE_COUNT,
84: nodes.size());
85: for (int i = 0; i < PATH_NODE_COUNT; i++) {
86: assertEquals("Wrong path node at position" + i,
87: PATH_NODE_NAME + i, nodes.get(i));
88: }
89: }
90: }
|