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