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