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
.linuxtools
.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
.linuxtools
.tmf
.core
.timestamp
.TmfTimeRange
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
29 import org
.eclipse
.linuxtools
.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 @SuppressWarnings("nls")
40 public class TmfUml2SDSyncLoaderFindTest
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 // Test case 002 expected values
47 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE
= new Uml2SDTestTimestamp(9788642104149L);
48 final static private String TC_002_MESSAGE_NAME
= "GAME_REQUEST";
49 final static private int TC_002_PAGE_VALUE
= 0;
50 final static private int TC_002_START_OCCURRANCE
= 3;
51 final static private int TC_002_END_OCCURRANCE
= TC_002_START_OCCURRANCE
;
52 final static private String TC_002_START_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
53 final static private String TC_002_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
55 // Test case 003 expected values
56 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE
= new Uml2SDTestTimestamp(9788642113228L);
57 final static private String TC_003_MESSAGE_NAME
= "GAME_REPLY";
58 final static private int TC_003_PAGE_VALUE
= 0;
59 final static private int TC_003_START_OCCURRANCE
= 4;
60 final static private int TC_003_END_OCCURRANCE
= TC_003_START_OCCURRANCE
;
61 final static private String TC_003_START_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
62 final static private String TC_003_END_LIFELINE
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
64 // Test case 004 expected values
65 final static private Uml2SDTestTimestamp TC_004_TIME_VALUE
= new Uml2SDTestTimestamp(9791893030834L);
66 final static private String TC_004_MESSAGE_NAME
= "GAME_REQUEST";
67 final static private int TC_004_PAGE_VALUE
= 4;
68 final static private int TC_004_START_OCCURRANCE
= 19;
69 final static private int TC_004_END_OCCURRANCE
= TC_004_START_OCCURRANCE
;
70 final static private String TC_004_START_LIFELINE
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
71 final static private String TC_004_END_LIFELINE
= IUml2SDTestConstants
.MASTER_PLAYER_NAME
;
73 // Test case 005 expected values
74 final static private int TC_005_PAGE_VALUE
= 0;
75 final static private String TC_005_LIFELINE_NAME
= IUml2SDTestConstants
.FIRST_PLAYER_NAME
;
77 // Test case 006 expected values
78 final static private int TC_006_PAGE_VALUE
= 4;
79 final static private String TC_006_LIFELINE_NAME
= IUml2SDTestConstants
.SECOND_PLAYER_NAME
;
81 // Fields used in tests
82 private static Uml2SDTestFacility fFacility
;
83 private static Uml2SDSignalValidator fTmfComponent
;
84 private static Criteria criteria
;
85 private static List
<GraphNode
> selection
;
86 private static TmfSyncMessage msg
;
87 private static Lifeline lifeline
;
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
97 public static void setUpClass() {
98 fFacility
= Uml2SDTestFacility
.getInstance();
99 fFacility
.selectExperiment();
106 public static void tearDownClass() {
107 fFacility
.disposeExperiment();
112 * Verify the ISDGraphNodeSupporter implementation.
114 * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
115 * Expected result: Correct values are returned, i.e. only lifelines and
116 * sync. messages are supported.
119 public void verifyISDGraphNodeSupporter() {
120 fTmfComponent
= new Uml2SDSignalValidator();
122 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.LIFELINE
));
123 assertTrue("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGE
));
124 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
));
125 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGE
));
126 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
));
127 assertFalse("isNodeSupported", fFacility
.getLoader().isNodeSupported(ISDGraphNodeSupporter
.STOP
));
129 assertEquals("getNodeName", "Lifeline", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.LIFELINE
, null));
130 assertEquals("getNodeName", "Interaction", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGE
, null));
131 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.SYNCMESSAGERETURN
, null));
132 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGE
, null));
133 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
, null));
134 assertEquals("getNodeName", "", fFacility
.getLoader().getNodeName(ISDGraphNodeSupporter
.STOP
, null));
136 fFacility
.getLoader().cancel();
140 * Verify 1st message find within page.
142 * Verified Methods: loader.find(), loader.moveToMessage()
143 * Expected result: Correct message is selected
146 public void verifyFirstMessage() {
147 criteria
= new Criteria();
148 criteria
.setSyncMessageSelected(true);
149 criteria
.setExpression("GAME_.*");
151 // set expected values
152 fTmfComponent
.setSource(fFacility
.getLoader());
153 fTmfComponent
.setCurrentTime(TC_002_TIME_VALUE
);
154 fTmfComponent
.setCurrentRange(null); // not used
155 fTmfComponent
.setSignalReceived(false);
157 fFacility
.getLoader().find(criteria
);
158 // Wait for the selection to finish - needed due to new platform behavior in Juno
159 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
160 assertTrue("find", fTmfComponent
.isSignalReceived());
161 assertFalse("find", fTmfComponent
.isSignalError());
162 assertFalse("find", fTmfComponent
.isCurrentTimeError());
163 assertFalse("find", fTmfComponent
.isSourceError());
165 assertEquals("find", TC_002_PAGE_VALUE
, fFacility
.getLoader().currentPage());
166 selection
= fFacility
.getSdView().getSDWidget().getSelection();
167 assertNotNull(selection
);
168 assertEquals("find", 1, selection
.size());
169 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
170 msg
= (TmfSyncMessage
) selection
.get(0);
171 assertEquals("find", TC_002_MESSAGE_NAME
, msg
.getName());
172 assertEquals("find", 0, TC_002_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
173 assertEquals("find", TC_002_START_OCCURRANCE
, msg
.getStartOccurrence());
174 assertEquals("find", TC_002_END_OCCURRANCE
, msg
.getEndOccurrence());
175 assertEquals("find", TC_002_START_LIFELINE
, msg
.getStartLifeline().getName());
176 assertEquals("find", TC_002_END_LIFELINE
, msg
.getEndLifeline().getName());
180 * Verify 2nd message find within page.
182 * Verified Methods: loader.find(), loader.moveToMessage()
183 * Expected result: Correct message is selected
186 public void verifySecondMessage() {
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 * Verify 1st message across page.
219 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
220 * Expected result: Correct message is selected
223 public void verifyFirstMesage() {
224 // set expected values
225 fTmfComponent
.setSource(fFacility
.getLoader());
226 fTmfComponent
.setCurrentTime(TC_004_TIME_VALUE
);
227 fTmfComponent
.setCurrentRange(new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
)); // not used
229 fTmfComponent
.setSignalReceived(false);
231 fFacility
.getLoader().find(criteria
);
232 fFacility
.waitForJobs(); // find across pages uses a job
233 // to make sure pageRequest has been started before calling waitforCompletion()
234 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
235 fFacility
.getLoader().waitForCompletion();
236 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
238 assertTrue("find", fTmfComponent
.isSignalReceived());
239 assertFalse("find", fTmfComponent
.isSignalError());
240 assertFalse("find", fTmfComponent
.isCurrentTimeError());
241 assertFalse("find", fTmfComponent
.isSourceError());
243 assertEquals("find", TC_004_PAGE_VALUE
, fFacility
.getLoader().currentPage());
244 selection
= fFacility
.getSdView().getSDWidget().getSelection();
245 assertNotNull(selection
);
246 assertEquals("find", 1, selection
.size());
247 assertTrue(selection
.get(0) instanceof TmfSyncMessage
);
248 msg
= (TmfSyncMessage
) selection
.get(0);
249 assertEquals("find", TC_004_MESSAGE_NAME
, msg
.getName());
250 assertEquals("find", 0, TC_004_TIME_VALUE
.compareTo(msg
.getStartTime(), false));
251 assertEquals("find", TC_004_START_OCCURRANCE
, msg
.getStartOccurrence());
252 assertEquals("find", TC_004_END_OCCURRANCE
, msg
.getEndOccurrence());
253 assertEquals("find", TC_004_START_LIFELINE
, msg
.getStartLifeline().getName());
254 assertEquals("find", TC_004_END_LIFELINE
, msg
.getEndLifeline().getName());
256 // cancel find and go back to first page
257 fFacility
.getLoader().cancel();
258 fFacility
.firstPage();
262 * Verify find of lifeline within page.
264 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
265 * Expected result: Correct message is selected
268 public void verifyFind() {
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());
286 * Verify lifeline across page.
288 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
289 * Expected result: Correct message is selected
292 public void verifyLifeline() {
293 criteria
= new Criteria();
294 criteria
.setLifeLineSelected(true);
295 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
297 fFacility
.getLoader().find(criteria
);
298 fFacility
.waitForJobs(); // find across pages uses a job
299 // to make sure pageRequest has been started before calling waitforCompletion()
300 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
301 fFacility
.getLoader().waitForCompletion();
302 fFacility
.delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
304 assertEquals("find", TC_006_PAGE_VALUE
, fFacility
.getLoader().currentPage());
305 selection
= fFacility
.getSdView().getSDWidget().getSelection();
306 assertNotNull(selection
);
307 assertEquals("find", 1, selection
.size());
308 assertTrue(selection
.get(0) instanceof Lifeline
);
309 lifeline
= (Lifeline
) selection
.get(0);
310 assertEquals("find", TC_006_LIFELINE_NAME
, lifeline
.getName());
313 // cancel find and go back to first page
314 fFacility
.getLoader().cancel();
315 fFacility
.firstPage();
319 * Verify cancel ongoing search job.
321 * Verified Methods: loader.find(), loader.find()
322 * Expected result: Cancelled find
325 public void verifyCancelSearch() {
326 criteria
= new Criteria();
327 criteria
.setLifeLineSelected(true);
328 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
330 fFacility
.getLoader().find(criteria
);
331 fFacility
.delay(200); // to make sure job was started
332 fFacility
.getLoader().cancel();
334 assertEquals("find", 0, fFacility
.getLoader().currentPage()); // we are still at the first page
335 fTmfComponent
.dispose();