Commit | Line | Data |
---|---|---|
03c71d1e ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009, 2010 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
6c13869b | 12 | package org.eclipse.linuxtools.lttng.core.tests.model; |
29465de6 | 13 | |
03c71d1e ASL |
14 | import junit.framework.TestCase; |
15 | ||
1b70b6dc PT |
16 | import org.eclipse.linuxtools.lttng.core.model.LTTngTreeNode; |
17 | ||
03c71d1e ASL |
18 | /** |
19 | * @author alvaro | |
20 | * | |
21 | */ | |
3b38ea61 | 22 | @SuppressWarnings("nls") |
03c71d1e ASL |
23 | public class LTTngTreeNodeTest extends TestCase { |
24 | // ======================================================================= | |
25 | // Data | |
26 | // ======================================================================= | |
27 | LTTngTreeNode node10; | |
28 | LTTngTreeNode node20; | |
29 | LTTngTreeNode node30; | |
30 | LTTngTreeNode node40; | |
31 | LTTngTreeNode node50; | |
32 | LTTngTreeNode node60; | |
33 | ||
34 | LTTngTreeNode node15; | |
35 | LTTngTreeNode node25; | |
36 | LTTngTreeNode node35; | |
37 | LTTngTreeNode node45; | |
38 | LTTngTreeNode node55; | |
39 | LTTngTreeNode node65; | |
40 | LTTngTreeNode node67; | |
41 | ||
42 | // ======================================================================= | |
43 | // Preparation and Finish | |
44 | // ======================================================================= | |
45 | /* (non-Javadoc) | |
46 | * @see junit.framework.TestCase#setUp() | |
47 | */ | |
550d787e | 48 | @Override |
03c71d1e ASL |
49 | protected void setUp() throws Exception { |
50 | super.setUp(); | |
51 | // Create state resources and assign a parent | |
52 | node10 = new LTTngTreeNode(10L, null, "node10", this); | |
53 | node20 = new LTTngTreeNode(20L, node10, "node20", this); | |
54 | node30 = new LTTngTreeNode(30L, node20, "node30", this); | |
55 | node40 = new LTTngTreeNode(40L, node30, "node40", this); | |
56 | node50 = new LTTngTreeNode(50L, node40, "node50", this); | |
57 | node60 = new LTTngTreeNode(60L, node50, "node60", this); | |
58 | ||
59 | //Adding first children | |
60 | node10.addChild(node20); | |
61 | node20.addChild(node30); | |
62 | node30.addChild(node40); | |
63 | node40.addChild(node50); | |
64 | node50.addChild(node60); | |
65 | ||
66 | //create additional nodes | |
67 | node15 = new LTTngTreeNode(15L, node10, "node15", this); | |
68 | node25 = new LTTngTreeNode(25L, node20, "node25", this); | |
69 | node35 = new LTTngTreeNode(35L, node30, "node35", this); | |
70 | node45 = new LTTngTreeNode(45L, node40, "node45", this); | |
71 | node55 = new LTTngTreeNode(55L, node50, "node55", this); | |
72 | node65 = new LTTngTreeNode(65L, node60, "node65", this); | |
73 | node67 = new LTTngTreeNode(67L, node60, "node67", this); | |
74 | ||
75 | ||
76 | // Add children to instances | |
77 | node10.addChild(node15); | |
78 | node20.addChild(node25); | |
79 | node30.addChild(node35); | |
80 | node40.addChild(node45); | |
81 | node50.addChild(node55); | |
82 | node60.addChild(node65); | |
83 | node60.addChild(node67); | |
84 | ||
85 | } | |
86 | ||
87 | // ======================================================================= | |
88 | // Methods | |
89 | // ======================================================================= | |
90 | /* (non-Javadoc) | |
91 | * @see junit.framework.TestCase#tearDown() | |
92 | */ | |
550d787e | 93 | @Override |
03c71d1e ASL |
94 | protected void tearDown() throws Exception { |
95 | super.tearDown(); | |
96 | } | |
97 | ||
98 | /** | |
6c13869b | 99 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNode#getChildren()}. |
03c71d1e ASL |
100 | */ |
101 | public void testGetChildren() { | |
102 | LTTngTreeNode[] childrensOf60 = node60.getChildren(); | |
103 | assertNotNull(childrensOf60); | |
104 | ||
105 | int size = childrensOf60.length; | |
106 | assertEquals(2, size); | |
107 | ||
108 | LTTngTreeNode child65 = childrensOf60[0]; | |
109 | LTTngTreeNode child67 = childrensOf60[1]; | |
110 | ||
111 | assertNotNull(child65); | |
112 | assertNotNull(child67); | |
113 | ||
114 | assertEquals("node65", child65.getName()); | |
115 | assertEquals("node67", child67.getName()); | |
116 | } | |
117 | ||
118 | /** | |
6c13869b | 119 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getId()}. |
03c71d1e ASL |
120 | */ |
121 | public void testGetId() { | |
122 | assertEquals(15L, node15.getId().longValue()); | |
123 | } | |
124 | ||
125 | /** | |
6c13869b | 126 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getType()}. |
03c71d1e ASL |
127 | */ |
128 | public void testGetType() { | |
129 | assertEquals(this.getClass(), node15.getType()); | |
130 | } | |
131 | ||
132 | /** | |
6c13869b | 133 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getChildByName(java.lang.String)}. |
03c71d1e ASL |
134 | */ |
135 | public void testGetChildByName() { | |
136 | LTTngTreeNode child65 = node60.getChildByName("node65"); | |
137 | LTTngTreeNode child67 = node60.getChildByName("node67"); | |
138 | assertNotNull(child65); | |
139 | assertNotNull(child67); | |
140 | ||
141 | assertEquals("node65", child65.getName()); | |
142 | assertEquals("node67", child67.getName()); | |
143 | } | |
144 | ||
145 | /** | |
6c13869b | 146 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#removeChild(org.eclipse.linuxtools.lttng.core.model.ILTTngTreeNode)}. |
03c71d1e ASL |
147 | */ |
148 | public void testRemoveChild() { | |
149 | // Verify node20 | |
150 | LTTngTreeNode[] childrensOf20 = node20.getChildren(); | |
151 | assertNotNull(childrensOf20); | |
152 | ||
153 | int size = childrensOf20.length; | |
154 | assertEquals(2, size); | |
155 | ||
d4011df2 FC |
156 | LTTngTreeNode child25 = childrensOf20[0]; |
157 | LTTngTreeNode child30 = childrensOf20[1]; | |
03c71d1e ASL |
158 | |
159 | assertNotNull(child25); | |
160 | assertNotNull(child30); | |
161 | ||
162 | assertEquals("node25", child25.getName()); | |
163 | assertEquals("node30", child30.getName()); | |
164 | ||
165 | // Remove a child with unusual values. | |
166 | node20.removeChild(null); | |
167 | node20.removeChild(node60); | |
168 | ||
169 | // Remove a valid child | |
170 | node20.removeChild(node30); | |
171 | ||
172 | // Verify consistency | |
173 | childrensOf20 = node20.getChildren(); | |
174 | assertNotNull(childrensOf20); | |
175 | ||
176 | size = childrensOf20.length; | |
177 | assertEquals(1, size); | |
178 | ||
179 | child25 = childrensOf20[0]; | |
180 | ||
181 | assertNotNull(child25); | |
182 | ||
183 | assertEquals("node25", child25.getName()); | |
184 | } | |
185 | ||
186 | /** | |
6c13869b | 187 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getChildById(java.lang.Integer)}. |
03c71d1e ASL |
188 | */ |
189 | public void testGetChildById() { | |
190 | LTTngTreeNode child65 = node60.getChildById(65L); | |
191 | LTTngTreeNode child67 = node60.getChildById(67L); | |
192 | assertNotNull(child65); | |
193 | assertNotNull(child67); | |
194 | ||
195 | assertEquals("node65", child65.getName()); | |
196 | assertEquals("node67", child67.getName()); | |
197 | } | |
198 | ||
199 | /** | |
6c13869b | 200 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getParent()}. |
03c71d1e ASL |
201 | */ |
202 | public void testGetParent() { | |
203 | assertEquals(node60, node67.getParent()); | |
204 | } | |
205 | ||
206 | /** | |
6c13869b | 207 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#setParent(org.eclipse.linuxtools.lttng.core.model.ILTTngTreeNode)}. |
03c71d1e ASL |
208 | */ |
209 | public void testSetParent() { | |
210 | node30.removeChild(node35); | |
211 | node60.addChild(node35); | |
212 | node35.setParent(node60); | |
213 | ||
214 | assertEquals(node60, node35.getParent()); | |
215 | } | |
216 | ||
217 | /** | |
6c13869b | 218 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#hasChildren()}. |
03c71d1e ASL |
219 | */ |
220 | public void testHasChildren() { | |
221 | assertEquals(true, node10.hasChildren()); | |
222 | ||
223 | node10.removeChild(node15); | |
224 | node10.removeChild(node20); | |
225 | ||
226 | assertEquals(false, node10.hasChildren()); | |
227 | } | |
228 | ||
229 | /** | |
6c13869b | 230 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getName()}. |
03c71d1e ASL |
231 | */ |
232 | public void testGetName() { | |
233 | assertEquals("node40", node40.getName()); | |
234 | } | |
235 | ||
236 | /** | |
6c13869b | 237 | * Test method for {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getPath()}. |
03c71d1e ASL |
238 | */ |
239 | public void testGetPath() { | |
240 | String path = node60.getPath(); | |
241 | assertEquals("/node10/node20/node30/node40/node50/node60", path); | |
242 | } | |
243 | ||
244 | /** | |
245 | * Test method for | |
6c13869b | 246 | * {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getAdapter()} |
03c71d1e ASL |
247 | * . |
248 | */ | |
249 | public void testGetAdapter() { | |
250 | Object value = node60.getAdapter(this.getClass()); | |
251 | assertEquals("Unexpected Adapter reference", this, value); | |
252 | } | |
253 | ||
254 | /** | |
255 | * Test method for | |
6c13869b | 256 | * {@link org.eclipse.linuxtools.lttng.core.model.LTTngTreeNodeGeneric#getAttibute()} |
03c71d1e ASL |
257 | * . |
258 | */ | |
259 | public void testGetAttribute() { | |
260 | Long lval = Long.valueOf(10L); | |
261 | node60.addAttribute("attr1", "Value1"); | |
262 | node60.addAttribute("attr2", lval); | |
263 | node60.addAttribute("attr3", node50); | |
264 | ||
265 | assertEquals("Value1", node60.getAttribute("attr1", String.class)); | |
266 | assertEquals(lval, node60.getAttribute("attr2", Long.class)); | |
267 | assertEquals(node50, node60.getAttribute("attr3", LTTngTreeNode.class)); | |
268 | assertEquals(null, node60.getAttribute("attr1", LTTngTreeNode.class)); | |
269 | } | |
270 | ||
271 | } |