1 /*******************************************************************************
2 * Copyright (c) 2011-2013 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 * Alexandre Montplaisir - Port to JUnit4
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertFalse
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
21 import java
.util
.List
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.loader
.TmfSyncMessage
;
30 import org
.junit
.AfterClass
;
31 import org
.junit
.BeforeClass
;
32 import org
.junit
.Test
;
37 * @author Bernd Hufmann
39 public class TmfUml2SDSyncLoaderFindTest
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 // Test case 002 expected values
46 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9788642104149L);
47 final static private String TC_002_MESSAGE_NAME
= "GAME_REQUEST";
48 final static private int TC_002_PAGE_VALUE
= 0;
49 final static private int TC_002_START_OCCURRANCE
= 3;
50 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
51 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
52 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
54 // Test case 003 expected values
55 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9788642113228L);
56 final static private String TC_003_MESSAGE_NAME
= "GAME_REPLY";
57 final static private int TC_003_PAGE_VALUE
= 0;
58 final static private int TC_003_START_OCCURRANCE
= 4;
59 final static private int TC_003_END_OCCURRANCE
= TC_003_START_OCCURRANCE
;
60 final static private String TC_003_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
61 final static private String TC_003_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
63 // Test case 004 expected values
64 final static private Uml2SDTestTimestamp TC_004_TIME_VALUE
= new Uml2SDTestTimestamp(9791893030834L);
65 final static private String TC_004_MESSAGE_NAME
= "GAME_REQUEST";
66 final static private int TC_004_PAGE_VALUE
= 4;
67 final static private int TC_004_START_OCCURRANCE
= 19;
68 final static private int TC_004_END_OCCURRANCE
= TC_004_START_OCCURRANCE
;
69 final static private String TC_004_START_LIFELINE
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
70 final static private String TC_004_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
72 // Test case 005 expected values
73 final static private int TC_005_PAGE_VALUE
= 0;
74 final static private String TC_005_LIFELINE_NAME
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
76 // Test case 006 expected values
77 final static private int TC_006_PAGE_VALUE
= 4;
78 final static private String TC_006_LIFELINE_NAME
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
80 // Fields used in tests
81 private static Uml2SDTestFacility fFacility
;
82 private static Uml2SDSignalValidator fTmfComponent
;
83 private static Criteria criteria
;
84 private static List
<GraphNode
> selection
;
85 private static TmfSyncMessage msg
;
86 private static Lifeline lifeline
;
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
96 public static void setUpClass() {
97 fFacility
= Uml2SDTestFacility
.getInstance();
98 fFacility
.selectExperiment();
99 fTmfComponent
= new Uml2SDSignalValidator();
106 public static void tearDownClass() {
107 fTmfComponent
.dispose();
108 fFacility
.disposeExperiment();
113 * Verify the ISDGraphNodeSupporter implementation.
115 * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
116 * Expected result: Correct values are returned, i.e. only lifelines and
117 * sync. messages are supported.
120 public void verifyISDGraphNodeSupporter() {
122 fFacility
.firstPage();
124 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
));
125 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
));
126 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
));
127 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
));
128 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
));
129 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.STOP
));
131 assertEquals("getNodeName", "Lifeline", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.LIFELINE
, null));
132 assertEquals("getNodeName", "Interaction", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, null));
133 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, null));
134 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, null));
135 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, null));
136 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.STOP
, null));
138 fFacility
.getLoader().cancel();
142 * Verify 1st message find within page.
144 * Verified Methods: loader.find(), loader.moveToMessage()
145 * Expected result: Correct message is selected
148 public void verifyFirstMessage() {
149 fFacility
.firstPage();
151 criteria
= new Criteria();
152 criteria
.setSyncMessageSelected(true);
153 criteria
.setExpression("GAME_.*");
155 // set expected values
156 fTmfComponent
.setSource(fFacility
.getLoader());
157 fTmfComponent
.setCurrentTime(TC_002_TIME_VALUE
);
158 fTmfComponent
.setCurrentRange(null); // not used
159 fTmfComponent
.setSignalReceived(false);
161 fFacility
.getLoader().find(criteria
);
162 // Wait for the selection to finish - needed due to new platform behavior in Juno
163 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
164 assertTrue("find", fTmfComponent
.isSignalReceived());
165 assertFalse("find", fTmfComponent
.isSignalError());
166 assertFalse("find", fTmfComponent
.isCurrentTimeError());
167 assertFalse("find", fTmfComponent
.isSourceError());
169 assertEquals("find", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
170 selection
= fFacility
.getSdView().getSDWidget().getSelection();
171 assertNotNull(selection
);
172 assertEquals("find", 1, selection
.size());
173 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
174 msg
= (TmfSyncMessage
) selection
.get(0);
175 assertEquals("find", TC_002_MESSAGE_NAME
, msg
.getName());
176 assertEquals("find", 0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
177 assertEquals("find", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
178 assertEquals("find", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
179 assertEquals("find", TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
180 assertEquals("find", TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
183 * Verify 2nd message find within page.
185 * Verified Methods: loader.find(), loader.moveToMessage()
186 * Expected result: Correct message is selected
189 // set expected values
190 fTmfComponent
.setSource(fFacility
.getLoader());
191 fTmfComponent
.setCurrentTime(TC_003_TIME_VALUE
);
192 fTmfComponent
.setCurrentRange(null); // not used
194 fTmfComponent
.setSignalReceived(false);
196 fFacility
.getLoader().find(criteria
);
197 // Wait for the selection to finish - needed due to new platform behavior in Juno
198 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
199 assertTrue("find", fTmfComponent
.isSignalReceived());
200 assertFalse("find", fTmfComponent
.isSignalError());
201 assertFalse("find", fTmfComponent
.isCurrentTimeError());
202 assertFalse("find", fTmfComponent
.isSourceError());
204 assertEquals("find", TC_003_PAGE_VALUE
, fFacility
.getLoader().currentPage());
205 selection
= fFacility
.getSdView().getSDWidget().getSelection();
206 assertNotNull(selection
);
207 assertEquals("find", 1, selection
.size());
208 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
209 msg
= (TmfSyncMessage
) selection
.get(0);
210 assertEquals("find", TC_003_MESSAGE_NAME
, msg
.getName());
211 assertEquals("find", 0, TC_003_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
212 assertEquals("find", TC_003_START_OCCURRANCE
, msg
.getStartOccurrence());
213 assertEquals("find", TC_003_END_OCCURRANCE
, msg
.getEndOccurrence());
214 assertEquals("find", TC_003_START_LIFELINE
, msg
.getStartLifeline().getName());
215 assertEquals("find", TC_003_END_LIFELINE
, msg
.getEndLifeline().getName());
218 * Verify 1st message across page.
220 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
221 * Expected result: Correct message is selected
223 // set expected values
224 fTmfComponent
.setSource(fFacility
.getLoader());
225 fTmfComponent
.setCurrentTime(TC_004_TIME_VALUE
);
226 fTmfComponent
.setCurrentRange(new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
)); // not used
228 fTmfComponent
.setSignalReceived(false);
230 fFacility
.getLoader().find(criteria
);
231 fFacility
.waitForJobs(); // find across pages uses a job
232 // to make sure pageRequest has been started before calling waitforCompletion()
233 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
234 fFacility
.getLoader().waitForCompletion();
235 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
237 assertTrue("find", fTmfComponent
.isSignalReceived());
238 assertFalse("find", fTmfComponent
.isSignalError());
239 assertFalse("find", fTmfComponent
.isCurrentTimeError());
240 assertFalse("find", fTmfComponent
.isSourceError());
242 assertEquals("find", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
243 selection
= fFacility
.getSdView().getSDWidget().getSelection();
244 assertNotNull(selection
);
245 assertEquals("find", 1, selection
.size());
246 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
247 msg
= (TmfSyncMessage
) selection
.get(0);
248 assertEquals("find", TC_004_MESSAGE_NAME
, msg
.getName());
249 assertEquals("find", 0, TC_004_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
250 assertEquals("find", TC_004_START_OCCURRANCE
, msg
.getStartOccurrence());
251 assertEquals("find", TC_004_END_OCCURRANCE
, msg
.getEndOccurrence());
252 assertEquals("find", TC_004_START_LIFELINE
, msg
.getStartLifeline().getName());
253 assertEquals("find", TC_004_END_LIFELINE
, msg
.getEndLifeline().getName());
255 // cancel find and go back to first page
256 fFacility
.getLoader().cancel();
260 * Verify find of lifeline within page.
262 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
263 * Expected result: Correct message is selected
266 public void verifyFind() {
267 fFacility
.firstPage();
269 criteria
= new Criteria();
270 criteria
.setLifeLineSelected(true);
271 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
272 fFacility
.getLoader().find(criteria
);
273 // Wait for the selection to finish - needed due to new platform behavior in Juno
274 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
276 assertEquals("find", TC_005_PAGE_VALUE
, fFacility
.getLoader().currentPage());
277 selection
= fFacility
.getSdView().getSDWidget().getSelection();
278 assertNotNull(selection
);
279 assertEquals("find", 1, selection
.size());
280 assertTrue(selection
.get(0) instanceof Lifeline
);
281 lifeline
= (Lifeline
) selection
.get(0);
282 assertEquals("find", TC_005_LIFELINE_NAME
, lifeline
.getName());
285 * Verify lifeline across page.
287 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
288 * Expected result: Correct message is selected
290 criteria
= new Criteria();
291 criteria
.setLifeLineSelected(true);
292 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
294 fFacility
.getLoader().find(criteria
);
295 fFacility
.waitForJobs(); // find across pages uses a job
296 // to make sure pageRequest has been started before calling waitforCompletion()
297 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
298 fFacility
.getLoader().waitForCompletion();
299 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
301 assertEquals("find", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
302 selection
= fFacility
.getSdView().getSDWidget().getSelection();
303 assertNotNull(selection
);
304 assertEquals("find", 1, selection
.size());
305 assertTrue(selection
.get(0) instanceof Lifeline
);
306 lifeline
= (Lifeline
) selection
.get(0);
307 assertEquals("find", TC_006_LIFELINE_NAME
, lifeline
.getName());
309 // cancel find and go back to first page
310 fFacility
.getLoader().cancel();
314 * Verify cancel ongoing search job.
316 * Verified Methods: loader.find(), loader.find()
317 * Expected result: Cancelled find
320 public void verifyCancelSearch() {
322 fFacility
.firstPage();
324 criteria
= new Criteria();
325 criteria
.setLifeLineSelected(true);
326 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
328 fFacility
.getLoader().find(criteria
);
329 fFacility
.delay(200); // to make sure job was started
330 fFacility
.getLoader().cancel();
332 assertEquals("find", 0, fFacility
.getLoader().currentPage()); // we are still at the first page
334 // cancel find and go back to first page
335 fFacility
.getLoader().cancel();
336 fFacility
.firstPage();