1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 {
30 /*** Constant for the default parent node used for testing. */
31 private static final ConfigurationNode TEST_PARENT = new DefaultConfigurationNode(
32 "parent");
33
34 /*** Constant for the name of the new node. */
35 private static final String TEST_NODENAME = "testNewNode";
36
37 /*** Constant for the name of a path node. */
38 private static final String PATH_NODE_NAME = "PATHNODE";
39
40 /*** Constant for the number of path nodes to be added. */
41 private static final int PATH_NODE_COUNT = 10;
42
43 /*** The object to be tested. */
44 NodeAddData addData;
45
46 protected void setUp() throws Exception
47 {
48 super.setUp();
49 addData = new NodeAddData(TEST_PARENT, TEST_NODENAME);
50 }
51
52 /***
53 * Tests the default values of an unitialized instance.
54 */
55 public void testUninitialized()
56 {
57 addData = new NodeAddData();
58 assertNull("A parent is set", addData.getParent());
59 assertNull("Node has a name", addData.getNewNodeName());
60 assertFalse("Attribute flag is set", addData.isAttribute());
61 assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
62 }
63
64 /***
65 * Tests the constructor that initializes the most important fields.
66 */
67 public void testInitialized()
68 {
69 assertSame("Wrong parent", TEST_PARENT, addData.getParent());
70 assertEquals("Wrong node name", TEST_NODENAME, addData.getNewNodeName());
71 assertFalse("Attribute flag is set", addData.isAttribute());
72 assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
73 }
74
75 /***
76 * Tests adding path nodes.
77 */
78 public void testAddPathNode()
79 {
80 for (int i = 0; i < PATH_NODE_COUNT; i++)
81 {
82 addData.addPathNode(PATH_NODE_NAME + i);
83 }
84
85 List nodes = addData.getPathNodes();
86 assertEquals("Incorrect number of path nodes", PATH_NODE_COUNT, nodes
87 .size());
88 for (int i = 0; i < PATH_NODE_COUNT; i++)
89 {
90 assertEquals("Wrong path node at position" + i, PATH_NODE_NAME + i,
91 nodes.get(i));
92 }
93 }
94 }