1
/*******************************************************************************
2
* Copyright (c) 2009, 2010 Ericsson
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
10
* Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11
*******************************************************************************/
12
package org.eclipse.linuxtools.lttng.core.tests.model;
14
import junit.framework.TestCase;
16
import org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode;
22
@SuppressWarnings("nls")
23
public class LTTngTreeNodeTest extends TestCase {
24
// =======================================================================
26
// =======================================================================
42
// =======================================================================
43
// Preparation and Finish
44
// =======================================================================
46
* @see junit.framework.TestCase#setUp()
49
protected void setUp() throws Exception {
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);
59
//Adding first children
60
node10.addChild(node20);
61
node20.addChild(node30);
62
node30.addChild(node40);
63
node40.addChild(node50);
64
node50.addChild(node60);
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);
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);
87
// =======================================================================
89
// =======================================================================
91
* @see junit.framework.TestCase#tearDown()
94
protected void tearDown() throws Exception {
99
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode#getChildren()}.
101
public void testGetChildren() {
102
LTTngTreeNode[] childrensOf60 = node60.getChildren();
103
assertNotNull(childrensOf60);
105
int size = childrensOf60.length;
106
assertEquals(2, size);
108
LTTngTreeNode child65 = childrensOf60[0];
109
LTTngTreeNode child67 = childrensOf60[1];
111
assertNotNull(child65);
112
assertNotNull(child67);
114
assertEquals("node65", child65.getName());
115
assertEquals("node67", child67.getName());
119
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getId()}.
121
public void testGetId() {
122
assertEquals(15L, node15.getId().longValue());
126
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getType()}.
128
public void testGetType() {
129
assertEquals(this.getClass(), node15.getNodeType());
133
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getChildByName(java.lang.String)}.
135
public void testGetChildByName() {
136
LTTngTreeNode child65 = node60.getChildByName("node65");
137
LTTngTreeNode child67 = node60.getChildByName("node67");
138
assertNotNull(child65);
139
assertNotNull(child67);
141
assertEquals("node65", child65.getName());
142
assertEquals("node67", child67.getName());
146
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#removeChild(org.eclipse.linuxtools.internal.lttng.core.model.ILTTngTreeNode)}.
148
public void testRemoveChild() {
150
LTTngTreeNode[] childrensOf20 = node20.getChildren();
151
assertNotNull(childrensOf20);
153
int size = childrensOf20.length;
154
assertEquals(2, size);
156
LTTngTreeNode child25 = childrensOf20[0];
157
LTTngTreeNode child30 = childrensOf20[1];
159
assertNotNull(child25);
160
assertNotNull(child30);
162
assertEquals("node25", child25.getName());
163
assertEquals("node30", child30.getName());
165
// Remove a child with unusual values.
166
node20.removeChild(null);
167
node20.removeChild(node60);
169
// Remove a valid child
170
node20.removeChild(node30);
172
// Verify consistency
173
childrensOf20 = node20.getChildren();
174
assertNotNull(childrensOf20);
176
size = childrensOf20.length;
177
assertEquals(1, size);
179
child25 = childrensOf20[0];
181
assertNotNull(child25);
183
assertEquals("node25", child25.getName());
187
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getChildById(java.lang.Integer)}.
189
public void testGetChildById() {
190
LTTngTreeNode child65 = node60.getChildById(65L);
191
LTTngTreeNode child67 = node60.getChildById(67L);
192
assertNotNull(child65);
193
assertNotNull(child67);
195
assertEquals("node65", child65.getName());
196
assertEquals("node67", child67.getName());
200
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getParent()}.
202
public void testGetParent() {
203
assertEquals(node60, node67.getParent());
207
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#setParent(org.eclipse.linuxtools.internal.lttng.core.model.ILTTngTreeNode)}.
209
public void testSetParent() {
210
node30.removeChild(node35);
211
node60.addChild(node35);
212
node35.setParent(node60);
214
assertEquals(node60, node35.getParent());
218
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#hasChildren()}.
220
public void testHasChildren() {
221
assertEquals(true, node10.hasChildren());
223
node10.removeChild(node15);
224
node10.removeChild(node20);
226
assertEquals(false, node10.hasChildren());
230
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getName()}.
232
public void testGetName() {
233
assertEquals("node40", node40.getName());
237
* Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getPath()}.
239
public void testGetPath() {
240
String path = node60.getPath();
241
assertEquals("/node10/node20/node30/node40/node50/node60", path);
246
* {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getAdapter()}
249
public void testGetAdapter() {
250
Object value = node60.getAdapter(this.getClass());
251
assertEquals("Unexpected Adapter reference", this, value);
256
* {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getAttibute()}
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);
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));