87e68dd60545806f0e00bc32318caae6271ead0d
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()
45 protected void setUp() throws Exception
{
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);
55 //Adding first children
56 node10
.addChild(node20
);
57 node20
.addChild(node30
);
58 node30
.addChild(node40
);
59 node40
.addChild(node50
);
60 node50
.addChild(node60
);
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);
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
);
83 // =======================================================================
85 // =======================================================================
87 * @see junit.framework.TestCase#tearDown()
89 protected void tearDown() throws Exception
{
94 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNode#getChildren()}.
96 public void testGetChildren() {
97 LTTngTreeNode
[] childrensOf60
= node60
.getChildren();
98 assertNotNull(childrensOf60
);
100 int size
= childrensOf60
.length
;
101 assertEquals(2, size
);
103 LTTngTreeNode child65
= childrensOf60
[0];
104 LTTngTreeNode child67
= childrensOf60
[1];
106 assertNotNull(child65
);
107 assertNotNull(child67
);
109 assertEquals("node65", child65
.getName());
110 assertEquals("node67", child67
.getName());
114 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getId()}.
116 public void testGetId() {
117 assertEquals(15L, node15
.getId().longValue());
121 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getType()}.
123 public void testGetType() {
124 assertEquals(this.getClass(), node15
.getType());
128 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getChildByName(java.lang.String)}.
130 public void testGetChildByName() {
131 LTTngTreeNode child65
= node60
.getChildByName("node65");
132 LTTngTreeNode child67
= node60
.getChildByName("node67");
133 assertNotNull(child65
);
134 assertNotNull(child67
);
136 assertEquals("node65", child65
.getName());
137 assertEquals("node67", child67
.getName());
141 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#removeChild(org.eclipse.linuxtools.lttng.model.ILTTngTreeNode)}.
143 public void testRemoveChild() {
145 LTTngTreeNode
[] childrensOf20
= node20
.getChildren();
146 assertNotNull(childrensOf20
);
148 int size
= childrensOf20
.length
;
149 assertEquals(2, size
);
151 LTTngTreeNode child30
= childrensOf20
[0];
152 LTTngTreeNode child25
= childrensOf20
[1];
154 assertNotNull(child25
);
155 assertNotNull(child30
);
157 assertEquals("node25", child25
.getName());
158 assertEquals("node30", child30
.getName());
160 // Remove a child with unusual values.
161 node20
.removeChild(null);
162 node20
.removeChild(node60
);
164 // Remove a valid child
165 node20
.removeChild(node30
);
167 // Verify consistency
168 childrensOf20
= node20
.getChildren();
169 assertNotNull(childrensOf20
);
171 size
= childrensOf20
.length
;
172 assertEquals(1, size
);
174 child25
= childrensOf20
[0];
176 assertNotNull(child25
);
178 assertEquals("node25", child25
.getName());
182 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getChildById(java.lang.Integer)}.
184 public void testGetChildById() {
185 LTTngTreeNode child65
= node60
.getChildById(65L);
186 LTTngTreeNode child67
= node60
.getChildById(67L);
187 assertNotNull(child65
);
188 assertNotNull(child67
);
190 assertEquals("node65", child65
.getName());
191 assertEquals("node67", child67
.getName());
195 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getParent()}.
197 public void testGetParent() {
198 assertEquals(node60
, node67
.getParent());
202 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#setParent(org.eclipse.linuxtools.lttng.model.ILTTngTreeNode)}.
204 public void testSetParent() {
205 node30
.removeChild(node35
);
206 node60
.addChild(node35
);
207 node35
.setParent(node60
);
209 assertEquals(node60
, node35
.getParent());
213 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#hasChildren()}.
215 public void testHasChildren() {
216 assertEquals(true, node10
.hasChildren());
218 node10
.removeChild(node15
);
219 node10
.removeChild(node20
);
221 assertEquals(false, node10
.hasChildren());
225 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getName()}.
227 public void testGetName() {
228 assertEquals("node40", node40
.getName());
232 * Test method for {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getPath()}.
234 public void testGetPath() {
235 String path
= node60
.getPath();
236 assertEquals("/node10/node20/node30/node40/node50/node60", path
);
241 * {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getAdapter()}
244 public void testGetAdapter() {
245 Object value
= node60
.getAdapter(this.getClass());
246 assertEquals("Unexpected Adapter reference", this, value
);
251 * {@link org.eclipse.linuxtools.lttng.model.LTTngTreeNodeGeneric#getAttibute()}
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
);
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));
This page took 0.036159 seconds and 4 git commands to generate.