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
.model
;
14 import junit
.framework
.TestCase
;
20 public class LTTngTreeNodeTest
extends TestCase
{
21 // =======================================================================
23 // =======================================================================
39 // =======================================================================
40 // Preparation and Finish
41 // =======================================================================
43 * @see junit.framework.TestCase#setUp()
46 protected void setUp() throws Exception
{
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);
56 //Adding first children
57 node10
.addChild(node20
);
58 node20
.addChild(node30
);
59 node30
.addChild(node40
);
60 node40
.addChild(node50
);
61 node50
.addChild(node60
);
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);
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
);
84 // =======================================================================
86 // =======================================================================
88 * @see junit.framework.TestCase#tearDown()
91 protected void tearDown() throws Exception
{
96 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNode#getChildren()}.
98 public void testGetChildren() {
99 LTTngTreeNode
[] childrensOf60
= node60
.getChildren();
100 assertNotNull(childrensOf60
);
102 int size
= childrensOf60
.length
;
103 assertEquals(2, size
);
105 LTTngTreeNode child65
= childrensOf60
[0];
106 LTTngTreeNode child67
= childrensOf60
[1];
108 assertNotNull(child65
);
109 assertNotNull(child67
);
111 assertEquals("node65", child65
.getName());
112 assertEquals("node67", child67
.getName());
116 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getId()}.
118 public void testGetId() {
119 assertEquals(15L, node15
.getId().longValue());
123 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getType()}.
125 public void testGetType() {
126 assertEquals(this.getClass(), node15
.getType());
130 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getChildByName(java.lang.String)}.
132 public void testGetChildByName() {
133 LTTngTreeNode child65
= node60
.getChildByName("node65");
134 LTTngTreeNode child67
= node60
.getChildByName("node67");
135 assertNotNull(child65
);
136 assertNotNull(child67
);
138 assertEquals("node65", child65
.getName());
139 assertEquals("node67", child67
.getName());
143 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#removeChild(org.eclipse.linuxtools.lttng.model.ILTTngTreeNode)}.
145 public void testRemoveChild() {
147 LTTngTreeNode
[] childrensOf20
= node20
.getChildren();
148 assertNotNull(childrensOf20
);
150 int size
= childrensOf20
.length
;
151 assertEquals(2, size
);
153 LTTngTreeNode child25
= childrensOf20
[0];
154 LTTngTreeNode child30
= childrensOf20
[1];
156 assertNotNull(child25
);
157 assertNotNull(child30
);
159 assertEquals("node25", child25
.getName());
160 assertEquals("node30", child30
.getName());
162 // Remove a child with unusual values.
163 node20
.removeChild(null);
164 node20
.removeChild(node60
);
166 // Remove a valid child
167 node20
.removeChild(node30
);
169 // Verify consistency
170 childrensOf20
= node20
.getChildren();
171 assertNotNull(childrensOf20
);
173 size
= childrensOf20
.length
;
174 assertEquals(1, size
);
176 child25
= childrensOf20
[0];
178 assertNotNull(child25
);
180 assertEquals("node25", child25
.getName());
184 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getChildById(java.lang.Integer)}.
186 public void testGetChildById() {
187 LTTngTreeNode child65
= node60
.getChildById(65L);
188 LTTngTreeNode child67
= node60
.getChildById(67L);
189 assertNotNull(child65
);
190 assertNotNull(child67
);
192 assertEquals("node65", child65
.getName());
193 assertEquals("node67", child67
.getName());
197 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getParent()}.
199 public void testGetParent() {
200 assertEquals(node60
, node67
.getParent());
204 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#setParent(org.eclipse.linuxtools.lttng.model.ILTTngTreeNode)}.
206 public void testSetParent() {
207 node30
.removeChild(node35
);
208 node60
.addChild(node35
);
209 node35
.setParent(node60
);
211 assertEquals(node60
, node35
.getParent());
215 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#hasChildren()}.
217 public void testHasChildren() {
218 assertEquals(true, node10
.hasChildren());
220 node10
.removeChild(node15
);
221 node10
.removeChild(node20
);
223 assertEquals(false, node10
.hasChildren());
227 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getName()}.
229 public void testGetName() {
230 assertEquals("node40", node40
.getName());
234 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getPath()}.
236 public void testGetPath() {
237 String path
= node60
.getPath();
238 assertEquals("/node10/node20/node30/node40/node50/node60", path
);
243 * {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getAdapter()}
246 public void testGetAdapter() {
247 Object value
= node60
.getAdapter(this.getClass());
248 assertEquals("Unexpected Adapter reference", this, value
);
253 * {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getAttibute()}
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
);
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));
This page took 0.035752 seconds and 5 git commands to generate.