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