1 /**********************************************************************
2 * Copyright (c) 2012 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 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
14 import java
.util
.LinkedList
;
15 import java
.util
.List
;
17 import junit
.framework
.Test
;
18 import junit
.framework
.TestCase
;
19 import junit
.framework
.TestSuite
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponentChangedListener
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlComponent
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlRoot
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ILttngControlService
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlService
;
30 import org
.eclipse
.swt
.graphics
.Image
;
31 import org
.eclipse
.ui
.ISharedImages
;
32 import org
.eclipse
.ui
.PlatformUI
;
33 import org
.junit
.After
;
34 import org
.junit
.Before
;
37 * The class <code>TraceControlComponentTest</code> contains tests for the class <code>{@link TraceControlComponent}</code>.
40 @SuppressWarnings({"nls", "javadoc"})
41 public class TraceControlComponentTest
extends TestCase
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 * Returns test setup used when executing test case stand-alone.
53 * @return Test setup class
55 public static Test
suite() {
56 return new ModelImplTestSetup(new TestSuite(TraceControlComponentTest
.class));
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Perform pre-test initialization.
67 * if the initialization fails for some reason
72 public void setUp() throws Exception
{
76 * Perform post-test clean-up.
79 * if the clean-up fails for some reason
84 public void tearDown() throws Exception
{
88 * Run the TraceControlComponent(String) constructor test.
90 public void testTraceControlComponent_1()
95 TraceControlComponent result
= new TraceControlComponent(name
);
97 assertNotNull(result
);
98 assertEquals(name
, result
.getName());
99 assertEquals(null, result
.getParent());
100 assertEquals(false, result
.hasChildren());
101 assertEquals(null, result
.getImage());
102 assertEquals(null, result
.getControlService());
103 assertEquals(null, result
.getToolTip());
107 * Run the TraceControlComponent(String,ITraceControlComponent) constructor test.
110 public void testTraceControlComponent_2()
112 String name
= "node";
114 ITraceControlComponent parent
= new TraceControlRoot();
115 TraceControlComponent result
= new TraceControlComponent(name
, parent
);
117 assertNotNull(result
);
118 assertEquals(name
, result
.getName());
119 assertEquals(false, result
.hasChildren());
120 assertEquals(null, result
.getImage());
121 assertEquals(null, result
.getControlService());
122 assertEquals(null, result
.getToolTip());
126 * Run the void addChild(ITraceControlComponent) method test.
131 public void testAddAndGetChild1()
133 TraceControlComponent fixture
= new TraceControlComponent("node", new TraceControlRoot());
134 fixture
.setToolTip("This is the test node");
135 fixture
.addChild(new TraceControlRoot());
136 ITraceControlComponent component
= new TraceControlRoot();
137 fixture
.addChild(component
);
139 ITraceControlComponent child
= fixture
.getChild(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
);
140 assertNotNull(child
);
141 assertEquals(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
, child
.getName());
145 * Run the void addChild(ITraceControlComponent) method test.
150 public void testAddAndGetChild2()
152 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
153 fixture
.setToolTip("");
154 ITraceControlComponent component
= null;
156 fixture
.addChild(component
);
157 assertFalse(fixture
.hasChildren());
161 * Run the void addComponentListener(ITraceControlComponentChangedListener) method test.
167 public void testAddComponentListener_1()
169 TraceControlComponent fixture
= new TraceControlComponent("", (ITraceControlComponent
) null);
170 fixture
.setToolTip("");
172 ListenerValidator validator
= new ListenerValidator();
173 fixture
.addComponentListener(validator
);
175 TraceControlRoot root
= new TraceControlRoot();
176 fixture
.addChild(root
);
177 assertTrue(validator
.isAddedCalled());
179 fixture
.removeChild(root
);
180 assertTrue(validator
.isRemovedCalled());
182 fixture
.fireComponentChanged(fixture
);
183 assertTrue(validator
.isChangedCalled());
187 * Run the boolean containsChild(String) method test.
192 public void testContainsChild_1()
194 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
195 fixture
.setToolTip("");
196 fixture
.addChild(new TraceControlRoot());
197 String name
= "node";
199 boolean result
= fixture
.containsChild(name
);
201 assertEquals(false, result
);
205 * Run the boolean containsChild(String) method test.
210 public void testContainsChild_2()
212 TraceControlComponent fixture
= new TraceControlComponent("name", new TraceControlRoot());
213 fixture
.setToolTip("");
215 boolean result
= fixture
.containsChild(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
);
217 assertEquals(false, result
);
221 * Run the void fireCompenentAdded(ITraceControlComponent,ITraceControlComponent) method test.
222 * Run the void fireCompenentRemoved(ITraceControlComponent,ITraceControlComponent) method test.
223 * Run the void fireCompenentChanged(ITraceControlComponent) method test
229 public void testFireCompenentUpdated()
231 ITraceControlComponent parent
= new TraceControlRoot();
233 TraceControlComponent fixture
= new TraceControlComponent("node", parent
);
234 fixture
.setToolTip("");
236 ITraceControlComponent component
= new TraceControlComponent("child");
237 fixture
.addChild(component
);
239 ListenerValidator validator
= new ListenerValidator();
240 fixture
.addComponentListener(validator
);
242 fixture
.fireComponentAdded(parent
, component
);
243 assertTrue(validator
.isAddedCalled());
244 assertEquals(parent
.getName(), validator
.getSavedParent().getName());
245 assertEquals(component
.getName(), validator
.getSavedChild().getName());
247 validator
.initialize();
249 fixture
.fireComponentRemoved(parent
, component
);
250 assertTrue(validator
.isRemovedCalled());
251 assertEquals(parent
.getName(), validator
.getSavedParent().getName());
252 assertEquals(component
.getName(), validator
.getSavedChild().getName());
254 validator
.initialize();
255 fixture
.fireComponentChanged(fixture
);
256 assertTrue(validator
.isChangedCalled());
257 assertEquals(fixture
.getName(), validator
.getSavedComponent().getName());
261 * Run the Object getAdapter(Class) method test.
267 public void testGetAdapter()
269 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
270 fixture
.setToolTip("");
271 fixture
.addChild(new TraceControlRoot());
272 Class
<Object
> adapter
= Object
.class;
274 Object result
= fixture
.getAdapter(adapter
);
276 assertEquals(null, result
);
280 * Run the ITraceControlComponent[] getChildren() method test.
285 public void testGetChildren_1()
287 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
288 fixture
.setToolTip("");
289 fixture
.addChild(new TraceControlRoot());
291 ITraceControlComponent
[] result
= fixture
.getChildren();
293 assertNotNull(result
);
294 assertEquals(1, result
.length
);
295 assertNotNull(result
[0]);
296 assertEquals("trace_control_root", result
[0].getName());
297 assertEquals(null, result
[0].getParent());
298 assertEquals(false, result
[0].hasChildren());
299 assertEquals(null, result
[0].getImage());
300 assertEquals(null, result
[0].getControlService());
301 assertEquals(null, result
[0].getToolTip());
305 * Run the ILttngControlService getControlService()/setControlService() method test.
310 public void testGetAndSetControlService_1()
313 TraceControlComponent parent
= new TraceControlComponent("parent") {
314 ILttngControlService fService
= null;
317 public void setControlService(ILttngControlService service
) {
322 public ILttngControlService
getControlService() {
327 TraceControlComponent fixture
= new TraceControlComponent("", parent
);
328 parent
.addChild(fixture
);
329 fixture
.setToolTip("");
330 TraceControlComponent child
= new TraceControlComponent("child", fixture
);
331 fixture
.addChild(child
);
333 ILttngControlService result
= fixture
.getControlService();
334 assertEquals(null, result
);
336 TestRemoteSystemProxy proxy
= new TestRemoteSystemProxy();
337 ILttngControlService service
= new LTTngControlService(proxy
.createCommandShell());
338 fixture
.setControlService(service
);
339 result
= fixture
.getControlService();
340 assertNotNull(service
);
341 assertEquals(service
, result
);
343 result
= fixture
.getChildren()[0].getControlService();
344 assertNotNull(service
);
345 assertEquals(service
, result
);
349 * Run the Image getImage() method test.
354 public void testGetImage_1()
356 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
357 fixture
.setToolTip("");
358 fixture
.addChild(new TraceControlRoot());
360 Image result
= fixture
.getImage();
361 assertEquals(null, result
);
363 fixture
.setImage(PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FOLDER
));
364 assertNotNull(fixture
.getImage());
368 * Run the boolean hasChildren() method test.
373 public void testHasChildren_1()
375 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
376 fixture
.setToolTip("");
377 fixture
.addChild(new TraceControlRoot());
379 boolean result
= fixture
.hasChildren();
385 * Run the boolean hasChildren() method test.
390 public void testHasChildren_2()
392 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
393 fixture
.setToolTip("");
395 boolean result
= fixture
.hasChildren();
401 * Run the void removeAllChildren() method test.
406 public void testRemoveAllChildren_2()
408 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
409 fixture
.setToolTip("");
411 fixture
.addChild(new TraceControlRoot());
412 fixture
.addChild(new TraceControlComponent("child"));
414 fixture
.removeAllChildren();
415 assertFalse(fixture
.hasChildren());
419 * Run the void removeChild(ITraceControlComponent) method test.
424 public void testRemoveChild_1()
426 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
427 fixture
.setToolTip("");
428 TraceControlComponent child
= new TraceControlComponent("child", fixture
);
430 fixture
.addChild(child
);
431 fixture
.removeChild(child
);
432 assertFalse(fixture
.hasChildren());
436 * Run the void removeChild(ITraceControlComponent) method test.
442 public void testRemoveChild_2()
444 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
445 fixture
.setToolTip("");
446 fixture
.addChild(new TraceControlRoot());
447 ITraceControlComponent component
= null;
449 fixture
.removeChild(component
);
450 assertTrue(fixture
.hasChildren());
454 * Run the void removeComponentListener(ITraceControlComponentChangedListener) method test.
459 public void testRemoveComponentListener_1()
461 TraceControlComponent fixture
= new TraceControlComponent("", (ITraceControlComponent
) null);
462 fixture
.setToolTip("");
464 ListenerValidator validator
= new ListenerValidator();
465 fixture
.addComponentListener(validator
);
467 // Remove listener and check that validator is not called anymore
468 validator
.initialize();
469 fixture
.removeComponentListener(validator
);
470 TraceControlRoot root
= new TraceControlRoot();
471 fixture
.addChild(root
);
472 assertFalse(validator
.isAddedCalled());
474 fixture
.removeChild(root
);
475 assertFalse(validator
.isRemovedCalled());
477 fixture
.fireComponentChanged(fixture
);
478 assertFalse(validator
.isChangedCalled());
482 * Run the void removeComponentListener(ITraceControlComponentChangedListener) method test.
487 public void testRemoveComponentListener_2()
489 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
490 fixture
.setToolTip("");
491 fixture
.addChild(new TraceControlRoot());
492 ITraceControlComponentChangedListener listener
= new ControlView();
494 fixture
.removeComponentListener(listener
);
499 * Run the void setChildren(List<ITraceControlComponent>)/ITraceControlComponent[] getChildren() method test.
505 public void testGetAndSetChildren()
507 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
508 fixture
.setToolTip("");
509 List
<ITraceControlComponent
> children
= new LinkedList
<ITraceControlComponent
>();
510 children
.add(new TraceControlComponent("child1"));
511 children
.add(new TraceControlComponent("child2"));
513 fixture
.setChildren(children
);
515 ITraceControlComponent
[] result
= fixture
.getChildren();
516 assertEquals(2, result
.length
);
517 assertEquals("child1", result
[0].getName());
518 assertEquals("child2", result
[1].getName());
522 * Run the void String getName()/setName(String) method tests.
527 public void testGetAndSetName()
529 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
530 fixture
.setToolTip("");
531 fixture
.addChild(new TraceControlRoot());
532 String name
= "node";
534 fixture
.setName(name
);
535 assertEquals(name
,fixture
.getName());
540 * Run the void ITraceControlComponent getParent()/setParent(ITraceControlComponent) method tests.
545 public void testGetAndSetParent()
547 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
548 fixture
.setToolTip("");
549 fixture
.addChild(new TraceControlRoot());
550 ITraceControlComponent parent
= new TraceControlRoot();
551 parent
.addChild(fixture
);
553 fixture
.setParent(parent
);
554 ITraceControlComponent retrievedParent
= fixture
.getParent();
555 assertNotNull(retrievedParent
);
556 assertEquals(parent
.getName(), retrievedParent
.getName());
557 assertEquals(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
, retrievedParent
.getName());
558 assertEquals(null, retrievedParent
.getParent());
559 assertEquals(true, retrievedParent
.hasChildren());
563 * Run the void TargetNodeState getTargetNodeState()/etTargetNodeState(TargetNodeState) method tests.
568 public void testGetAndSetTargetNodeState_1()
571 TraceControlComponent parent
= new TraceControlComponent("parent") {
572 private TargetNodeState fState
;
575 public void setTargetNodeState(TargetNodeState state
) {
580 public TargetNodeState
getTargetNodeState() {
585 TraceControlComponent fixture
= new TraceControlComponent("", parent
);
586 parent
.addChild(fixture
);
588 fixture
.setToolTip("");
589 TargetNodeState state
= TargetNodeState
.CONNECTED
;
591 fixture
.setTargetNodeState(state
);
592 TargetNodeState result
= fixture
.getTargetNodeState();
594 assertNotNull(result
);
595 assertEquals(state
, result
);
597 assertEquals(state
, fixture
.getParent().getTargetNodeState());
598 assertEquals("CONNECTED", result
.name());
599 assertEquals("CONNECTED", result
.toString());
600 assertEquals(2, result
.ordinal());
602 fixture
.setTargetNodeState(TargetNodeState
.DISCONNECTED
);
603 result
= fixture
.getTargetNodeState();
604 assertNotNull(result
);
605 assertEquals("DISCONNECTED", result
.name());
606 assertEquals("DISCONNECTED", result
.toString());
607 assertEquals(0, result
.ordinal());
609 state
= TargetNodeState
.CONNECTING
;
611 fixture
.setTargetNodeState(state
);
612 result
= fixture
.getTargetNodeState();
613 assertNotNull(result
);
614 assertEquals("CONNECTING", result
.name());
615 assertEquals("CONNECTING", result
.toString());
616 assertEquals(3, result
.ordinal());
618 fixture
.setTargetNodeState(TargetNodeState
.DISCONNECTING
);
619 result
= fixture
.getTargetNodeState();
620 assertNotNull(result
);
621 assertEquals("DISCONNECTING", result
.name());
622 assertEquals("DISCONNECTING", result
.toString());
623 assertEquals(1, result
.ordinal());
628 * Run the void setToolTip(String) method test.
635 public void testGetSndSetToolTip()
637 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
638 fixture
.setToolTip("This is a tooltip");
639 fixture
.addChild(new TraceControlRoot());
641 String result
= fixture
.getToolTip();
643 assertEquals("This is a tooltip", result
);