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 static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.assertSame;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.List;
26
27 import org.junit.Before;
28 import org.junit.Test;
29
30
31
32
33
34
35
36
37
38 public class TestNodeAddData
39 {
40
41 private static final ConfigurationNode TEST_PARENT = new DefaultConfigurationNode(
42 "parent");
43
44
45 private static final String TEST_NODENAME = "testNewNode";
46
47
48 private static final String PATH_NODE_NAME = "PATHNODE";
49
50
51 private static final int PATH_NODE_COUNT = 10;
52
53
54 NodeAddData addData;
55
56 @Before
57 public void setUp() throws Exception
58 {
59 addData = new NodeAddData(TEST_PARENT, TEST_NODENAME);
60 }
61
62
63
64
65 @Test
66 public void testUninitialized()
67 {
68 addData = new NodeAddData();
69 assertNull("A parent is set", addData.getParent());
70 assertNull("Node has a name", addData.getNewNodeName());
71 assertFalse("Attribute flag is set", addData.isAttribute());
72 assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
73 }
74
75
76
77
78 @Test
79 public void testInitialized()
80 {
81 assertSame("Wrong parent", TEST_PARENT, addData.getParent());
82 assertEquals("Wrong node name", TEST_NODENAME, addData.getNewNodeName());
83 assertFalse("Attribute flag is set", addData.isAttribute());
84 assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
85 }
86
87
88
89
90 @Test
91 public void testAddPathNode()
92 {
93 for (int i = 0; i < PATH_NODE_COUNT; i++)
94 {
95 addData.addPathNode(PATH_NODE_NAME + i);
96 }
97
98 List<String> nodes = addData.getPathNodes();
99 assertEquals("Incorrect number of path nodes", PATH_NODE_COUNT, nodes
100 .size());
101 for (int i = 0; i < PATH_NODE_COUNT; i++)
102 {
103 assertEquals("Wrong path node at position" + i, PATH_NODE_NAME + i,
104 nodes.get(i));
105 }
106 }
107 }