~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng.core.tests/src/org/eclipse/linuxtools/lttng/core/tests/model/LTTngTreeNodeTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.core.tests.model;
 
13
 
 
14
import junit.framework.TestCase;
 
15
 
 
16
import org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode;
 
17
 
 
18
/**
 
19
 * @author alvaro
 
20
 *
 
21
 */
 
22
@SuppressWarnings("nls")
 
23
public class LTTngTreeNodeTest extends TestCase {
 
24
        // =======================================================================
 
25
        // Data
 
26
        // =======================================================================
 
27
        LTTngTreeNode node10;
 
28
        LTTngTreeNode node20;
 
29
        LTTngTreeNode node30;
 
30
        LTTngTreeNode node40;
 
31
        LTTngTreeNode node50;
 
32
        LTTngTreeNode node60;
 
33
 
 
34
        LTTngTreeNode node15;
 
35
        LTTngTreeNode node25;
 
36
        LTTngTreeNode node35;
 
37
        LTTngTreeNode node45;
 
38
        LTTngTreeNode node55;
 
39
        LTTngTreeNode node65;
 
40
        LTTngTreeNode node67;
 
41
 
 
42
        // =======================================================================
 
43
        // Preparation and Finish
 
44
        // =======================================================================
 
45
        /* (non-Javadoc)
 
46
         * @see junit.framework.TestCase#setUp()
 
47
         */
 
48
        @Override
 
49
        protected void setUp() throws Exception {
 
50
                super.setUp();
 
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);
 
58
                
 
59
                //Adding first children
 
60
                node10.addChild(node20);
 
61
                node20.addChild(node30);
 
62
                node30.addChild(node40);
 
63
                node40.addChild(node50);
 
64
                node50.addChild(node60);
 
65
                
 
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);
 
74
                
 
75
                
 
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);
 
84
 
 
85
        }
 
86
 
 
87
        // =======================================================================
 
88
        // Methods
 
89
        // =======================================================================
 
90
        /* (non-Javadoc)
 
91
         * @see junit.framework.TestCase#tearDown()
 
92
         */
 
93
        @Override
 
94
        protected void tearDown() throws Exception {
 
95
                super.tearDown();
 
96
        }
 
97
 
 
98
        /**
 
99
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNode#getChildren()}.
 
100
         */
 
101
        public void testGetChildren() {
 
102
                LTTngTreeNode[] childrensOf60 = node60.getChildren();
 
103
                assertNotNull(childrensOf60);
 
104
 
 
105
                int size = childrensOf60.length;
 
106
                assertEquals(2, size);
 
107
 
 
108
                LTTngTreeNode child65 = childrensOf60[0];
 
109
                LTTngTreeNode child67 = childrensOf60[1];
 
110
 
 
111
                assertNotNull(child65);
 
112
                assertNotNull(child67);
 
113
 
 
114
                assertEquals("node65", child65.getName());
 
115
                assertEquals("node67", child67.getName());
 
116
        }
 
117
 
 
118
        /**
 
119
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getId()}.
 
120
         */
 
121
        public void testGetId() {
 
122
                assertEquals(15L, node15.getId().longValue());
 
123
        }
 
124
 
 
125
        /**
 
126
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getType()}.
 
127
         */
 
128
        public void testGetType() {
 
129
                assertEquals(this.getClass(), node15.getNodeType());
 
130
        }
 
131
 
 
132
        /**
 
133
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getChildByName(java.lang.String)}.
 
134
         */
 
135
        public void testGetChildByName() {
 
136
                LTTngTreeNode child65 = node60.getChildByName("node65");
 
137
                LTTngTreeNode child67 = node60.getChildByName("node67");
 
138
                assertNotNull(child65);
 
139
                assertNotNull(child67);
 
140
 
 
141
                assertEquals("node65", child65.getName());
 
142
                assertEquals("node67", child67.getName());
 
143
        }
 
144
 
 
145
        /**
 
146
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#removeChild(org.eclipse.linuxtools.internal.lttng.core.model.ILTTngTreeNode)}.
 
147
         */
 
148
        public void testRemoveChild() {
 
149
                // Verify node20
 
150
                LTTngTreeNode[] childrensOf20 = node20.getChildren();
 
151
                assertNotNull(childrensOf20);
 
152
 
 
153
                int size = childrensOf20.length;
 
154
                assertEquals(2, size);
 
155
 
 
156
                LTTngTreeNode child25 = childrensOf20[0];
 
157
                LTTngTreeNode child30 = childrensOf20[1];
 
158
 
 
159
                assertNotNull(child25);
 
160
                assertNotNull(child30);
 
161
 
 
162
                assertEquals("node25", child25.getName());
 
163
                assertEquals("node30", child30.getName());
 
164
 
 
165
                // Remove a child with unusual values.
 
166
                node20.removeChild(null);
 
167
                node20.removeChild(node60);
 
168
 
 
169
                // Remove a valid child
 
170
                node20.removeChild(node30);
 
171
 
 
172
                // Verify consistency
 
173
                childrensOf20 = node20.getChildren();
 
174
                assertNotNull(childrensOf20);
 
175
 
 
176
                size = childrensOf20.length;
 
177
                assertEquals(1, size);
 
178
 
 
179
                child25 = childrensOf20[0];
 
180
 
 
181
                assertNotNull(child25);
 
182
 
 
183
                assertEquals("node25", child25.getName());
 
184
        }
 
185
 
 
186
        /**
 
187
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getChildById(java.lang.Integer)}.
 
188
         */
 
189
        public void testGetChildById() {
 
190
                LTTngTreeNode child65 = node60.getChildById(65L);
 
191
                LTTngTreeNode child67 = node60.getChildById(67L);
 
192
                assertNotNull(child65);
 
193
                assertNotNull(child67);
 
194
 
 
195
                assertEquals("node65", child65.getName());
 
196
                assertEquals("node67", child67.getName());
 
197
        }
 
198
 
 
199
        /**
 
200
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getParent()}.
 
201
         */
 
202
        public void testGetParent() {
 
203
                assertEquals(node60, node67.getParent());
 
204
        }
 
205
 
 
206
        /**
 
207
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#setParent(org.eclipse.linuxtools.internal.lttng.core.model.ILTTngTreeNode)}.
 
208
         */
 
209
        public void testSetParent() {
 
210
                node30.removeChild(node35);
 
211
                node60.addChild(node35);
 
212
                node35.setParent(node60);
 
213
 
 
214
                assertEquals(node60, node35.getParent());
 
215
        }
 
216
 
 
217
        /**
 
218
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#hasChildren()}.
 
219
         */
 
220
        public void testHasChildren() {
 
221
                assertEquals(true, node10.hasChildren());
 
222
 
 
223
                node10.removeChild(node15);
 
224
                node10.removeChild(node20);
 
225
 
 
226
                assertEquals(false, node10.hasChildren());
 
227
        }
 
228
 
 
229
        /**
 
230
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getName()}.
 
231
         */
 
232
        public void testGetName() {
 
233
                assertEquals("node40", node40.getName());
 
234
        }
 
235
 
 
236
        /**
 
237
         * Test method for {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getPath()}.
 
238
         */
 
239
        public void testGetPath() {
 
240
                String path = node60.getPath();
 
241
                assertEquals("/node10/node20/node30/node40/node50/node60", path);
 
242
        }
 
243
 
 
244
        /**
 
245
         * Test method for
 
246
         * {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getAdapter()}
 
247
         * .
 
248
         */
 
249
        public void testGetAdapter() {
 
250
                Object value = node60.getAdapter(this.getClass());
 
251
                assertEquals("Unexpected Adapter reference", this, value);
 
252
        }
 
253
 
 
254
        /**
 
255
         * Test method for
 
256
         * {@link org.eclipse.linuxtools.internal.lttng.core.model.LTTngTreeNodeGeneric#getAttibute()}
 
257
         * .
 
258
         */
 
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);
 
264
 
 
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));
 
269
        }
 
270
 
 
271
}