1 /*******************************************************************************
2 * Copyright (c) 2011 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
.tmf
.ui
.tests
.views
.uml2sd
.impl
;
14 import java
.util
.List
;
16 import junit
.framework
.Test
;
17 import junit
.framework
.TestCase
;
18 import junit
.framework
.TestSuite
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.Criteria
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.impl
.TmfSyncMessage
;
28 public class TmfUml2SDSyncLoaderFindTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
34 // Test case 002 expected values
35 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9788642104149L);
36 final static private String TC_002_MESSAGE_NAME
= "GAME_REQUEST"; //$NON-NLS-1$
37 final static private int TC_002_PAGE_VALUE
= 0;
38 final static private int TC_002_START_OCCURRANCE
= 3;
39 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
40 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
41 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
43 // Test case 003 expected values
44 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9788642113228L);
45 final static private String TC_003_MESSAGE_NAME
= "GAME_REPLY"; //$NON-NLS-1$
46 final static private int TC_003_PAGE_VALUE
= 0;
47 final static private int TC_003_START_OCCURRANCE
= 4;
48 final static private int TC_003_END_OCCURRANCE
= TC_003_START_OCCURRANCE
;
49 final static private String TC_003_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
50 final static private String TC_003_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
52 // Test case 004 expected values
53 final static private Uml2SDTestTimestamp TC_004_TIME_VALUE
= new Uml2SDTestTimestamp(9791893030834L);
54 final static private String TC_004_MESSAGE_NAME
= "GAME_REQUEST"; //$NON-NLS-1$
55 final static private int TC_004_PAGE_VALUE
= 4;
56 final static private int TC_004_START_OCCURRANCE
= 19;
57 final static private int TC_004_END_OCCURRANCE
= TC_004_START_OCCURRANCE
;
58 final static private String TC_004_START_LIFELINE
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
59 final static private String TC_004_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
61 // Test case 005 expected values
62 final static private int TC_005_PAGE_VALUE
= 0;
63 final static private String TC_005_LIFELINE_NAME
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
65 // Test case 006 expected values
66 final static private int TC_006_PAGE_VALUE
= 4;
67 final static private String TC_006_LIFELINE_NAME
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
69 private Uml2SDTestFacility fFacility
;
70 private Uml2SDSignalValidator fTmfComponent
;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 * Returns test setup used when executing test case stand-alone.
78 * @return Test setup class
80 public static Test
suite() {
81 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderFindTest
.class));
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
87 public TmfUml2SDSyncLoaderFindTest() {
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 public void setUp() throws Exception
{
96 fFacility
= Uml2SDTestFacility
.getInstance();
97 fFacility
.selectExperiment();
101 public void tearDown() throws Exception
{
102 fFacility
.disposeExperiment();
107 @SuppressWarnings("nls")
108 public void testFindHandling() {
109 fTmfComponent
= new Uml2SDSignalValidator();
113 * Description: Verify the ISDGraphNodeSupporter implementation
114 * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
115 * Expected result: Correct values are returned, i.e. only lifelines and sync. messages are supported
117 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
));
118 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
));
119 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
));
120 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
));
121 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
));
122 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.STOP
));
124 assertEquals("getNodeName", "Lifeline", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.LIFELINE
, null));
125 assertEquals("getNodeName", "Interaction", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, null));
126 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, null));
127 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, null));
128 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, null));
129 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.STOP
, null));
131 fFacility
.getLoader().cancel();
135 * Description: Verify 1st message find within page
136 * Verified Methods: loader.find(), loader.moveToMessage()
137 * Expected result: Correct message is selected
139 Criteria criteria
= new Criteria();
140 criteria
.setSyncMessageSelected(true);
141 criteria
.setExpression("GAME_.*");
143 // set expected values
144 fTmfComponent
.setSource(fFacility
.getLoader());
145 fTmfComponent
.setCurrentTime(TC_002_TIME_VALUE
);
146 fTmfComponent
.setCurrentRange(null); // not used
147 fTmfComponent
.setSignalReceived(false);
149 fFacility
.getLoader().find(criteria
);
150 // Wait for the selection to finish - needed due to new platform behavior in Juno
151 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
152 assertTrue("find", fTmfComponent
.isSignalReceived());
153 assertFalse("find", fTmfComponent
.isSignalError());
154 assertFalse("find", fTmfComponent
.isCurrentTimeError());
155 assertFalse("find", fTmfComponent
.isSourceError());
157 assertEquals("find", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
158 List
<GraphNode
> selection
= fFacility
.getSdView().getSDWidget().getSelection();
159 assertNotNull(selection
);
160 assertEquals("find", 1, selection
.size());
161 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
162 TmfSyncMessage msg
= (TmfSyncMessage
) selection
.get(0);
163 assertEquals("find", TC_002_MESSAGE_NAME
, msg
.getName());
164 assertEquals("find", 0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
165 assertEquals("find", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
166 assertEquals("find", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
167 assertEquals("find", TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
168 assertEquals("find", TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
172 * Description: Verify 2nd message find within page
173 * Verified Methods: loader.find(), loader.moveToMessage()
174 * Expected result: Correct message is selected
176 // set expected values
177 fTmfComponent
.setSource(fFacility
.getLoader());
178 fTmfComponent
.setCurrentTime(TC_003_TIME_VALUE
);
179 fTmfComponent
.setCurrentRange(null); // not used
181 fTmfComponent
.setSignalReceived(false);
183 fFacility
.getLoader().find(criteria
);
184 // Wait for the selection to finish - needed due to new platform behavior in Juno
185 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
186 assertTrue("find", fTmfComponent
.isSignalReceived());
187 assertFalse("find", fTmfComponent
.isSignalError());
188 assertFalse("find", fTmfComponent
.isCurrentTimeError());
189 assertFalse("find", fTmfComponent
.isSourceError());
191 assertEquals("find", TC_003_PAGE_VALUE
, fFacility
.getLoader().currentPage());
192 selection
= fFacility
.getSdView().getSDWidget().getSelection();
193 assertNotNull(selection
);
194 assertEquals("find", 1, selection
.size());
195 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
196 msg
= (TmfSyncMessage
) selection
.get(0);
197 assertEquals("find", TC_003_MESSAGE_NAME
, msg
.getName());
198 assertEquals("find", 0, TC_003_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
199 assertEquals("find", TC_003_START_OCCURRANCE
, msg
.getStartOccurrence());
200 assertEquals("find", TC_003_END_OCCURRANCE
, msg
.getEndOccurrence());
201 assertEquals("find", TC_003_START_LIFELINE
, msg
.getStartLifeline().getName());
202 assertEquals("find", TC_003_END_LIFELINE
, msg
.getEndLifeline().getName());
206 * Description: Verify 1st message across page
207 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
208 * Expected result: Correct message is selected
210 // set expected values
211 fTmfComponent
.setSource(fFacility
.getLoader());
212 fTmfComponent
.setCurrentTime(TC_004_TIME_VALUE
);
213 fTmfComponent
.setCurrentRange(new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
)); // not used
215 fTmfComponent
.setSignalReceived(false);
217 fFacility
.getLoader().find(criteria
);
218 fFacility
.waitForJobs(); // find across pages uses a job
219 // to make sure pageRequest has been started before calling waitforCompletion()
220 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
221 fFacility
.getLoader().waitForCompletion();
222 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
224 assertTrue("find", fTmfComponent
.isSignalReceived());
225 assertFalse("find", fTmfComponent
.isSignalError());
226 assertFalse("find", fTmfComponent
.isCurrentTimeError());
227 assertFalse("find", fTmfComponent
.isSourceError());
229 assertEquals("find", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
230 selection
= fFacility
.getSdView().getSDWidget().getSelection();
231 assertNotNull(selection
);
232 assertEquals("find", 1, selection
.size());
233 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
234 msg
= (TmfSyncMessage
) selection
.get(0);
235 assertEquals("find", TC_004_MESSAGE_NAME
, msg
.getName());
236 assertEquals("find", 0, TC_004_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
237 assertEquals("find", TC_004_START_OCCURRANCE
, msg
.getStartOccurrence());
238 assertEquals("find", TC_004_END_OCCURRANCE
, msg
.getEndOccurrence());
239 assertEquals("find", TC_004_START_LIFELINE
, msg
.getStartLifeline().getName());
240 assertEquals("find", TC_004_END_LIFELINE
, msg
.getEndLifeline().getName());
242 // cancel find and go back to first page
243 fFacility
.getLoader().cancel();
244 fFacility
.firstPage();
248 * Description: Verify find of lifeline within page
249 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
250 * Expected result: Correct message is selected
252 criteria
= new Criteria();
253 criteria
.setLifeLineSelected(true);
254 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
255 fFacility
.getLoader().find(criteria
);
256 // Wait for the selection to finish - needed due to new platform behavior in Juno
257 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
259 assertEquals("find", TC_005_PAGE_VALUE
, fFacility
.getLoader().currentPage());
260 selection
= fFacility
.getSdView().getSDWidget().getSelection();
261 assertNotNull(selection
);
262 assertEquals("find", 1, selection
.size());
263 assertTrue(selection
.get(0) instanceof Lifeline
);
264 Lifeline lifeline
= (Lifeline
) selection
.get(0);
265 assertEquals("find", TC_005_LIFELINE_NAME
, lifeline
.getName());
269 * Description: Verify lifeline across page
270 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
271 * Expected result: Correct message is selected
273 criteria
= new Criteria();
274 criteria
.setLifeLineSelected(true);
275 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
277 fFacility
.getLoader().find(criteria
);
278 fFacility
.waitForJobs(); // find across pages uses a job
279 // to make sure pageRequest has been started before calling waitforCompletion()
280 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
281 fFacility
.getLoader().waitForCompletion();
282 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
284 assertEquals("find", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
285 selection
= fFacility
.getSdView().getSDWidget().getSelection();
286 assertNotNull(selection
);
287 assertEquals("find", 1, selection
.size());
288 assertTrue(selection
.get(0) instanceof Lifeline
);
289 lifeline
= (Lifeline
) selection
.get(0);
290 assertEquals("find", TC_006_LIFELINE_NAME
, lifeline
.getName());
293 // cancel find and go back to first page
294 fFacility
.getLoader().cancel();
295 fFacility
.firstPage();
299 * Description: Verify cancel ongoing search job
300 * Verified Methods: loader.find(), loader.find()
301 * Expected result: Cancelled find
303 criteria
= new Criteria();
304 criteria
.setLifeLineSelected(true);
305 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
307 fFacility
.getLoader().find(criteria
);
308 fFacility
.delay(200); // to make sure job was started
309 fFacility
.getLoader().cancel();
311 assertEquals("find", 0, fFacility
.getLoader().currentPage()); // we are still at the first page
312 fTmfComponent
.dispose();