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
.lttng
.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
.lttng
.stubs
.service
.TestRemoteSystemProxy
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.tests
.control
.model
.impl
.ListenerValidator
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponentChangedListener
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TargetNodeState
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceControlComponent
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceControlRoot
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.ILttngControlService
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.LTTngControlService
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.ui
.ISharedImages
;
33 import org
.eclipse
.ui
.PlatformUI
;
34 import org
.junit
.After
;
35 import org
.junit
.Before
;
38 * The class <code>TraceControlComponentTest</code> contains tests for the class <code>{@link TraceControlComponent}</code>.
41 @SuppressWarnings("nls")
42 public class TraceControlComponentTest
extends TestCase
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * Returns test setup used when executing test case stand-alone.
54 * @return Test setup class
56 public static Test
suite() {
57 return new ModelImplTestSetup(new TestSuite(TraceControlComponentTest
.class));
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Perform pre-test initialization.
68 * if the initialization fails for some reason
73 public void setUp() throws Exception
{
77 * Perform post-test clean-up.
80 * if the clean-up fails for some reason
85 public void tearDown() throws Exception
{
89 * Run the TraceControlComponent(String) constructor test.
91 public void testTraceControlComponent_1()
96 TraceControlComponent result
= new TraceControlComponent(name
);
98 assertNotNull(result
);
99 assertEquals(name
, result
.getName());
100 assertEquals(null, result
.getParent());
101 assertEquals(false, result
.hasChildren());
102 assertEquals(null, result
.getImage());
103 assertEquals(null, result
.getControlService());
104 assertEquals(null, result
.getToolTip());
108 * Run the TraceControlComponent(String,ITraceControlComponent) constructor test.
111 public void testTraceControlComponent_2()
113 String name
= "node";
115 ITraceControlComponent parent
= new TraceControlRoot();
116 TraceControlComponent result
= new TraceControlComponent(name
, parent
);
118 assertNotNull(result
);
119 assertEquals(name
, result
.getName());
120 assertEquals(false, result
.hasChildren());
121 assertEquals(null, result
.getImage());
122 assertEquals(null, result
.getControlService());
123 assertEquals(null, result
.getToolTip());
127 * Run the void addChild(ITraceControlComponent) method test.
132 public void testAddAndGetChild1()
134 TraceControlComponent fixture
= new TraceControlComponent("node", new TraceControlRoot());
135 fixture
.setToolTip("This is the test node");
136 fixture
.addChild(new TraceControlRoot());
137 ITraceControlComponent component
= new TraceControlRoot();
138 fixture
.addChild(component
);
140 ITraceControlComponent child
= fixture
.getChild(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
);
141 assertNotNull(child
);
142 assertEquals(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
, child
.getName());
146 * Run the void addChild(ITraceControlComponent) method test.
151 public void testAddAndGetChild2()
153 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
154 fixture
.setToolTip("");
155 ITraceControlComponent component
= null;
157 fixture
.addChild(component
);
158 assertFalse(fixture
.hasChildren());
162 * Run the void addComponentListener(ITraceControlComponentChangedListener) method test.
168 public void testAddComponentListener_1()
170 TraceControlComponent fixture
= new TraceControlComponent("", (ITraceControlComponent
) null);
171 fixture
.setToolTip("");
173 ListenerValidator validator
= new ListenerValidator();
174 fixture
.addComponentListener(validator
);
176 TraceControlRoot root
= new TraceControlRoot();
177 fixture
.addChild(root
);
178 assertTrue(validator
.isAddedCalled());
180 fixture
.removeChild(root
);
181 assertTrue(validator
.isRemovedCalled());
183 fixture
.fireComponentChanged(fixture
);
184 assertTrue(validator
.isChangedCalled());
188 * Run the boolean containsChild(String) method test.
193 public void testContainsChild_1()
195 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
196 fixture
.setToolTip("");
197 fixture
.addChild(new TraceControlRoot());
198 String name
= "node";
200 boolean result
= fixture
.containsChild(name
);
202 assertEquals(false, result
);
206 * Run the boolean containsChild(String) method test.
211 public void testContainsChild_2()
213 TraceControlComponent fixture
= new TraceControlComponent("name", new TraceControlRoot());
214 fixture
.setToolTip("");
216 boolean result
= fixture
.containsChild(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
);
218 assertEquals(false, result
);
222 * Run the void fireCompenentAdded(ITraceControlComponent,ITraceControlComponent) method test.
223 * Run the void fireCompenentRemoved(ITraceControlComponent,ITraceControlComponent) method test.
224 * Run the void fireCompenentChanged(ITraceControlComponent) method test
230 public void testFireCompenentUpdated()
232 ITraceControlComponent parent
= new TraceControlRoot();
234 TraceControlComponent fixture
= new TraceControlComponent("node", parent
);
235 fixture
.setToolTip("");
237 ITraceControlComponent component
= new TraceControlComponent("child");
238 fixture
.addChild(component
);
240 ListenerValidator validator
= new ListenerValidator();
241 fixture
.addComponentListener(validator
);
243 fixture
.fireComponentAdded(parent
, component
);
244 assertTrue(validator
.isAddedCalled());
245 assertEquals(parent
.getName(), validator
.getSavedParent().getName());
246 assertEquals(component
.getName(), validator
.getSavedChild().getName());
248 validator
.initialize();
250 fixture
.fireComponentRemoved(parent
, component
);
251 assertTrue(validator
.isRemovedCalled());
252 assertEquals(parent
.getName(), validator
.getSavedParent().getName());
253 assertEquals(component
.getName(), validator
.getSavedChild().getName());
255 validator
.initialize();
256 fixture
.fireComponentChanged(fixture
);
257 assertTrue(validator
.isChangedCalled());
258 assertEquals(fixture
.getName(), validator
.getSavedComponent().getName());
262 * Run the Object getAdapter(Class) method test.
268 public void testGetAdapter()
270 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
271 fixture
.setToolTip("");
272 fixture
.addChild(new TraceControlRoot());
273 Class
<Object
> adapter
= Object
.class;
275 Object result
= fixture
.getAdapter(adapter
);
277 assertEquals(null, result
);
281 * Run the ITraceControlComponent[] getChildren() method test.
286 public void testGetChildren_1()
288 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
289 fixture
.setToolTip("");
290 fixture
.addChild(new TraceControlRoot());
292 ITraceControlComponent
[] result
= fixture
.getChildren();
294 assertNotNull(result
);
295 assertEquals(1, result
.length
);
296 assertNotNull(result
[0]);
297 assertEquals("trace_control_root", result
[0].getName());
298 assertEquals(null, result
[0].getParent());
299 assertEquals(false, result
[0].hasChildren());
300 assertEquals(null, result
[0].getImage());
301 assertEquals(null, result
[0].getControlService());
302 assertEquals(null, result
[0].getToolTip());
306 * Run the ILttngControlService getControlService()/setControlService() method test.
311 public void testGetAndSetControlService_1()
314 TraceControlComponent parent
= new TraceControlComponent("parent") {
315 ILttngControlService fService
= null;
318 public void setControlService(ILttngControlService service
) {
323 public ILttngControlService
getControlService() {
328 TraceControlComponent fixture
= new TraceControlComponent("", parent
);
329 parent
.addChild(fixture
);
330 fixture
.setToolTip("");
331 TraceControlComponent child
= new TraceControlComponent("child", fixture
);
332 fixture
.addChild(child
);
334 ILttngControlService result
= fixture
.getControlService();
335 assertEquals(null, result
);
337 TestRemoteSystemProxy proxy
= new TestRemoteSystemProxy();
338 ILttngControlService service
= new LTTngControlService(proxy
.createCommandShell());
339 fixture
.setControlService(service
);
340 result
= fixture
.getControlService();
341 assertNotNull(service
);
342 assertEquals(service
, result
);
344 result
= fixture
.getChildren()[0].getControlService();
345 assertNotNull(service
);
346 assertEquals(service
, result
);
350 * Run the Image getImage() method test.
355 public void testGetImage_1()
357 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
358 fixture
.setToolTip("");
359 fixture
.addChild(new TraceControlRoot());
361 Image result
= fixture
.getImage();
362 assertEquals(null, result
);
364 fixture
.setImage(PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FOLDER
));
365 assertNotNull(fixture
.getImage());
369 * Run the boolean hasChildren() method test.
374 public void testHasChildren_1()
376 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
377 fixture
.setToolTip("");
378 fixture
.addChild(new TraceControlRoot());
380 boolean result
= fixture
.hasChildren();
386 * Run the boolean hasChildren() method test.
391 public void testHasChildren_2()
393 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
394 fixture
.setToolTip("");
396 boolean result
= fixture
.hasChildren();
402 * Run the void removeAllChildren() method test.
407 public void testRemoveAllChildren_2()
409 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
410 fixture
.setToolTip("");
412 fixture
.addChild(new TraceControlRoot());
413 fixture
.addChild(new TraceControlComponent("child"));
415 fixture
.removeAllChildren();
416 assertFalse(fixture
.hasChildren());
420 * Run the void removeChild(ITraceControlComponent) method test.
425 public void testRemoveChild_1()
427 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
428 fixture
.setToolTip("");
429 TraceControlComponent child
= new TraceControlComponent("child", fixture
);
431 fixture
.addChild(child
);
432 fixture
.removeChild(child
);
433 assertFalse(fixture
.hasChildren());
437 * Run the void removeChild(ITraceControlComponent) method test.
443 public void testRemoveChild_2()
445 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
446 fixture
.setToolTip("");
447 fixture
.addChild(new TraceControlRoot());
448 ITraceControlComponent component
= null;
450 fixture
.removeChild(component
);
451 assertTrue(fixture
.hasChildren());
455 * Run the void removeComponentListener(ITraceControlComponentChangedListener) method test.
460 public void testRemoveComponentListener_1()
462 TraceControlComponent fixture
= new TraceControlComponent("", (ITraceControlComponent
) null);
463 fixture
.setToolTip("");
465 ListenerValidator validator
= new ListenerValidator();
466 fixture
.addComponentListener(validator
);
468 // Remove listener and check that validator is not called anymore
469 validator
.initialize();
470 fixture
.removeComponentListener(validator
);
471 TraceControlRoot root
= new TraceControlRoot();
472 fixture
.addChild(root
);
473 assertFalse(validator
.isAddedCalled());
475 fixture
.removeChild(root
);
476 assertFalse(validator
.isRemovedCalled());
478 fixture
.fireComponentChanged(fixture
);
479 assertFalse(validator
.isChangedCalled());
483 * Run the void removeComponentListener(ITraceControlComponentChangedListener) method test.
488 public void testRemoveComponentListener_2()
490 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
491 fixture
.setToolTip("");
492 fixture
.addChild(new TraceControlRoot());
493 ITraceControlComponentChangedListener listener
= new ControlView();
495 fixture
.removeComponentListener(listener
);
500 * Run the void setChildren(List<ITraceControlComponent>)/ITraceControlComponent[] getChildren() method test.
506 public void testGetAndSetChildren()
508 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
509 fixture
.setToolTip("");
510 List
<ITraceControlComponent
> children
= new LinkedList
<ITraceControlComponent
>();
511 children
.add(new TraceControlComponent("child1"));
512 children
.add(new TraceControlComponent("child2"));
514 fixture
.setChildren(children
);
516 ITraceControlComponent
[] result
= fixture
.getChildren();
517 assertEquals(2, result
.length
);
518 assertEquals("child1", result
[0].getName());
519 assertEquals("child2", result
[1].getName());
523 * Run the void String getName()/setName(String) method tests.
528 public void testGetAndSetName()
530 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
531 fixture
.setToolTip("");
532 fixture
.addChild(new TraceControlRoot());
533 String name
= "node";
535 fixture
.setName(name
);
536 assertEquals(name
,fixture
.getName());
541 * Run the void ITraceControlComponent getParent()/setParent(ITraceControlComponent) method tests.
546 public void testGetAndSetParent()
548 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
549 fixture
.setToolTip("");
550 fixture
.addChild(new TraceControlRoot());
551 ITraceControlComponent parent
= new TraceControlRoot();
552 parent
.addChild(fixture
);
554 fixture
.setParent(parent
);
555 ITraceControlComponent retrievedParent
= fixture
.getParent();
556 assertNotNull(retrievedParent
);
557 assertEquals(parent
.getName(), retrievedParent
.getName());
558 assertEquals(TraceControlRoot
.TRACE_CONTROL_ROOT_NAME
, retrievedParent
.getName());
559 assertEquals(null, retrievedParent
.getParent());
560 assertEquals(true, retrievedParent
.hasChildren());
564 * Run the void TargetNodeState getTargetNodeState()/etTargetNodeState(TargetNodeState) method tests.
569 public void testGetAndSetTargetNodeState_1()
572 TraceControlComponent parent
= new TraceControlComponent("parent") {
573 private TargetNodeState fState
;
576 public void setTargetNodeState(TargetNodeState state
) {
581 public TargetNodeState
getTargetNodeState() {
586 TraceControlComponent fixture
= new TraceControlComponent("", parent
);
587 parent
.addChild(fixture
);
589 fixture
.setToolTip("");
590 TargetNodeState state
= TargetNodeState
.CONNECTED
;
592 fixture
.setTargetNodeState(state
);
593 TargetNodeState result
= fixture
.getTargetNodeState();
595 assertNotNull(result
);
596 assertEquals(state
, result
);
598 assertEquals(state
, fixture
.getParent().getTargetNodeState());
599 assertEquals("CONNECTED", result
.name());
600 assertEquals("CONNECTED", result
.toString());
601 assertEquals(2, result
.ordinal());
603 fixture
.setTargetNodeState(TargetNodeState
.DISCONNECTED
);
604 result
= fixture
.getTargetNodeState();
605 assertNotNull(result
);
606 assertEquals("DISCONNECTED", result
.name());
607 assertEquals("DISCONNECTED", result
.toString());
608 assertEquals(0, result
.ordinal());
610 state
= TargetNodeState
.CONNECTING
;
612 fixture
.setTargetNodeState(state
);
613 result
= fixture
.getTargetNodeState();
614 assertNotNull(result
);
615 assertEquals("CONNECTING", result
.name());
616 assertEquals("CONNECTING", result
.toString());
617 assertEquals(3, result
.ordinal());
619 fixture
.setTargetNodeState(TargetNodeState
.DISCONNECTING
);
620 result
= fixture
.getTargetNodeState();
621 assertNotNull(result
);
622 assertEquals("DISCONNECTING", result
.name());
623 assertEquals("DISCONNECTING", result
.toString());
624 assertEquals(1, result
.ordinal());
629 * Run the void setToolTip(String) method test.
636 public void testGetSndSetToolTip()
638 TraceControlComponent fixture
= new TraceControlComponent("", new TraceControlRoot());
639 fixture
.setToolTip("This is a tooltip");
640 fixture
.addChild(new TraceControlRoot());
642 String result
= fixture
.getToolTip();
644 assertEquals("This is a tooltip", result
);