1 /*******************************************************************************
2 * Copyright (c) 2011, 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
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
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
.dialogs
.Criteria
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
.TmfSyncMessage
;
31 * @author Bernd Hufmann
33 public class TmfUml2SDSyncLoaderFindTest
extends TestCase
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 // Test case 002 expected values
40 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9788642104149L);
41 final static private String TC_002_MESSAGE_NAME
= "GAME_REQUEST"; //$NON-NLS-1$
42 final static private int TC_002_PAGE_VALUE
= 0;
43 final static private int TC_002_START_OCCURRANCE
= 3;
44 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
45 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
46 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
48 // Test case 003 expected values
49 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9788642113228L);
50 final static private String TC_003_MESSAGE_NAME
= "GAME_REPLY"; //$NON-NLS-1$
51 final static private int TC_003_PAGE_VALUE
= 0;
52 final static private int TC_003_START_OCCURRANCE
= 4;
53 final static private int TC_003_END_OCCURRANCE
= TC_003_START_OCCURRANCE
;
54 final static private String TC_003_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
55 final static private String TC_003_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
57 // Test case 004 expected values
58 final static private Uml2SDTestTimestamp TC_004_TIME_VALUE
= new Uml2SDTestTimestamp(9791893030834L);
59 final static private String TC_004_MESSAGE_NAME
= "GAME_REQUEST"; //$NON-NLS-1$
60 final static private int TC_004_PAGE_VALUE
= 4;
61 final static private int TC_004_START_OCCURRANCE
= 19;
62 final static private int TC_004_END_OCCURRANCE
= TC_004_START_OCCURRANCE
;
63 final static private String TC_004_START_LIFELINE
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
64 final static private String TC_004_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
66 // Test case 005 expected values
67 final static private int TC_005_PAGE_VALUE
= 0;
68 final static private String TC_005_LIFELINE_NAME
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
70 // Test case 006 expected values
71 final static private int TC_006_PAGE_VALUE
= 4;
72 final static private String TC_006_LIFELINE_NAME
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
74 private Uml2SDTestFacility fFacility
;
75 private Uml2SDSignalValidator fTmfComponent
;
77 // ------------------------------------------------------------------------
79 // ------------------------------------------------------------------------
82 * Returns test setup used when executing test case stand-alone.
83 * @return Test setup class
85 public static Test
suite() {
86 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderFindTest
.class));
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
95 public TmfUml2SDSyncLoaderFindTest() {
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
102 public void setUp() throws Exception
{
104 fFacility
= Uml2SDTestFacility
.getInstance();
105 fFacility
.selectExperiment();
109 public void tearDown() throws Exception
{
110 fFacility
.disposeExperiment();
116 * Main method with test cases.
118 @SuppressWarnings("nls")
119 public void testFindHandling() {
120 fTmfComponent
= new Uml2SDSignalValidator();
124 * Description: Verify the ISDGraphNodeSupporter implementation
125 * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
126 * Expected result: Correct values are returned, i.e. only lifelines and sync. messages are supported
128 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
));
129 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
));
130 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
));
131 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
));
132 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
));
133 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.STOP
));
135 assertEquals("getNodeName", "Lifeline", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.LIFELINE
, null));
136 assertEquals("getNodeName", "Interaction", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, null));
137 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, null));
138 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, null));
139 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, null));
140 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.STOP
, null));
142 fFacility
.getLoader().cancel();
146 * Description: Verify 1st message find within page
147 * Verified Methods: loader.find(), loader.moveToMessage()
148 * Expected result: Correct message is selected
150 Criteria criteria
= new Criteria();
151 criteria
.setSyncMessageSelected(true);
152 criteria
.setExpression("GAME_.*");
154 // set expected values
155 fTmfComponent
.setSource(fFacility
.getLoader());
156 fTmfComponent
.setCurrentTime(TC_002_TIME_VALUE
);
157 fTmfComponent
.setCurrentRange(null); // not used
158 fTmfComponent
.setSignalReceived(false);
160 fFacility
.getLoader().find(criteria
);
161 // Wait for the selection to finish - needed due to new platform behavior in Juno
162 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
163 assertTrue("find", fTmfComponent
.isSignalReceived());
164 assertFalse("find", fTmfComponent
.isSignalError());
165 assertFalse("find", fTmfComponent
.isCurrentTimeError());
166 assertFalse("find", fTmfComponent
.isSourceError());
168 assertEquals("find", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
169 List
<GraphNode
> selection
= fFacility
.getSdView().getSDWidget().getSelection();
170 assertNotNull(selection
);
171 assertEquals("find", 1, selection
.size());
172 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
173 TmfSyncMessage msg
= (TmfSyncMessage
) selection
.get(0);
174 assertEquals("find", TC_002_MESSAGE_NAME
, msg
.getName());
175 assertEquals("find", 0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
176 assertEquals("find", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
177 assertEquals("find", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
178 assertEquals("find", TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
179 assertEquals("find", TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
183 * Description: Verify 2nd message find within page
184 * Verified Methods: loader.find(), loader.moveToMessage()
185 * Expected result: Correct message is selected
187 // set expected values
188 fTmfComponent
.setSource(fFacility
.getLoader());
189 fTmfComponent
.setCurrentTime(TC_003_TIME_VALUE
);
190 fTmfComponent
.setCurrentRange(null); // not used
192 fTmfComponent
.setSignalReceived(false);
194 fFacility
.getLoader().find(criteria
);
195 // Wait for the selection to finish - needed due to new platform behavior in Juno
196 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
197 assertTrue("find", fTmfComponent
.isSignalReceived());
198 assertFalse("find", fTmfComponent
.isSignalError());
199 assertFalse("find", fTmfComponent
.isCurrentTimeError());
200 assertFalse("find", fTmfComponent
.isSourceError());
202 assertEquals("find", TC_003_PAGE_VALUE
, fFacility
.getLoader().currentPage());
203 selection
= fFacility
.getSdView().getSDWidget().getSelection();
204 assertNotNull(selection
);
205 assertEquals("find", 1, selection
.size());
206 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
207 msg
= (TmfSyncMessage
) selection
.get(0);
208 assertEquals("find", TC_003_MESSAGE_NAME
, msg
.getName());
209 assertEquals("find", 0, TC_003_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
210 assertEquals("find", TC_003_START_OCCURRANCE
, msg
.getStartOccurrence());
211 assertEquals("find", TC_003_END_OCCURRANCE
, msg
.getEndOccurrence());
212 assertEquals("find", TC_003_START_LIFELINE
, msg
.getStartLifeline().getName());
213 assertEquals("find", TC_003_END_LIFELINE
, msg
.getEndLifeline().getName());
217 * Description: Verify 1st message across page
218 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
219 * Expected result: Correct message is selected
221 // set expected values
222 fTmfComponent
.setSource(fFacility
.getLoader());
223 fTmfComponent
.setCurrentTime(TC_004_TIME_VALUE
);
224 fTmfComponent
.setCurrentRange(new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
)); // not used
226 fTmfComponent
.setSignalReceived(false);
228 fFacility
.getLoader().find(criteria
);
229 fFacility
.waitForJobs(); // find across pages uses a job
230 // to make sure pageRequest has been started before calling waitforCompletion()
231 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
232 fFacility
.getLoader().waitForCompletion();
233 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
235 assertTrue("find", fTmfComponent
.isSignalReceived());
236 assertFalse("find", fTmfComponent
.isSignalError());
237 assertFalse("find", fTmfComponent
.isCurrentTimeError());
238 assertFalse("find", fTmfComponent
.isSourceError());
240 assertEquals("find", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
241 selection
= fFacility
.getSdView().getSDWidget().getSelection();
242 assertNotNull(selection
);
243 assertEquals("find", 1, selection
.size());
244 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
245 msg
= (TmfSyncMessage
) selection
.get(0);
246 assertEquals("find", TC_004_MESSAGE_NAME
, msg
.getName());
247 assertEquals("find", 0, TC_004_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
248 assertEquals("find", TC_004_START_OCCURRANCE
, msg
.getStartOccurrence());
249 assertEquals("find", TC_004_END_OCCURRANCE
, msg
.getEndOccurrence());
250 assertEquals("find", TC_004_START_LIFELINE
, msg
.getStartLifeline().getName());
251 assertEquals("find", TC_004_END_LIFELINE
, msg
.getEndLifeline().getName());
253 // cancel find and go back to first page
254 fFacility
.getLoader().cancel();
255 fFacility
.firstPage();
259 * Description: Verify find of lifeline within page
260 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
261 * Expected result: Correct message is selected
263 criteria
= new Criteria();
264 criteria
.setLifeLineSelected(true);
265 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
266 fFacility
.getLoader().find(criteria
);
267 // Wait for the selection to finish - needed due to new platform behavior in Juno
268 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
270 assertEquals("find", TC_005_PAGE_VALUE
, fFacility
.getLoader().currentPage());
271 selection
= fFacility
.getSdView().getSDWidget().getSelection();
272 assertNotNull(selection
);
273 assertEquals("find", 1, selection
.size());
274 assertTrue(selection
.get(0) instanceof Lifeline
);
275 Lifeline lifeline
= (Lifeline
) selection
.get(0);
276 assertEquals("find", TC_005_LIFELINE_NAME
, lifeline
.getName());
280 * Description: Verify lifeline across page
281 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
282 * Expected result: Correct message is selected
284 criteria
= new Criteria();
285 criteria
.setLifeLineSelected(true);
286 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
288 fFacility
.getLoader().find(criteria
);
289 fFacility
.waitForJobs(); // find across pages uses a job
290 // to make sure pageRequest has been started before calling waitforCompletion()
291 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
292 fFacility
.getLoader().waitForCompletion();
293 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
295 assertEquals("find", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
296 selection
= fFacility
.getSdView().getSDWidget().getSelection();
297 assertNotNull(selection
);
298 assertEquals("find", 1, selection
.size());
299 assertTrue(selection
.get(0) instanceof Lifeline
);
300 lifeline
= (Lifeline
) selection
.get(0);
301 assertEquals("find", TC_006_LIFELINE_NAME
, lifeline
.getName());
304 // cancel find and go back to first page
305 fFacility
.getLoader().cancel();
306 fFacility
.firstPage();
310 * Description: Verify cancel ongoing search job
311 * Verified Methods: loader.find(), loader.find()
312 * Expected result: Cancelled find
314 criteria
= new Criteria();
315 criteria
.setLifeLineSelected(true);
316 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
318 fFacility
.getLoader().find(criteria
);
319 fFacility
.delay(200); // to make sure job was started
320 fFacility
.getLoader().cancel();
322 assertEquals("find", 0, fFacility
.getLoader().currentPage()); // we are still at the first page
323 fTmfComponent
.dispose();