analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderFindTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
15
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;
20
21 import java.util.List;
22
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;
33
34 /**
35 * Search Test Cases.
36 *
37 * @author Bernd Hufmann
38 */
39 public class TmfUml2SDSyncLoaderFindTest {
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44
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;
53
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;
62
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;
71
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;
75
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;
79
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;
87
88 // ------------------------------------------------------------------------
89 // Operations
90 // ------------------------------------------------------------------------
91
92 /**
93 * Initialization
94 */
95 @BeforeClass
96 public static void setUpClass() {
97 fFacility = Uml2SDTestFacility.getInstance();
98 fFacility.selectExperiment();
99 fTmfComponent = new Uml2SDSignalValidator();
100 }
101
102 /**
103 * Cleanup
104 */
105 @AfterClass
106 public static void tearDownClass() {
107 fTmfComponent.dispose();
108 fFacility.disposeExperiment();
109 fFacility = null;
110 }
111
112 /**
113 * Verify the ISDGraphNodeSupporter implementation.
114 *
115 * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
116 * Expected result: Correct values are returned, i.e. only lifelines and
117 * sync. messages are supported.
118 */
119 @Test
120 public void verifyISDGraphNodeSupporter() {
121
122 fFacility.firstPage();
123
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));
130
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));
137
138 fFacility.getLoader().cancel();
139 }
140
141 /**
142 * Verify 1st message find within page.
143 *
144 * Verified Methods: loader.find(), loader.moveToMessage()
145 * Expected result: Correct message is selected
146 */
147 @Test
148 public void verifyFirstMessage() {
149 fFacility.firstPage();
150
151 criteria = new Criteria();
152 criteria.setSyncMessageSelected(true);
153 criteria.setExpression("GAME_.*");
154
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);
160
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());
168
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()));
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());
181
182 /**
183 * Verify 2nd message find within page.
184 *
185 * Verified Methods: loader.find(), loader.moveToMessage()
186 * Expected result: Correct message is selected
187 */
188
189 // set expected values
190 fTmfComponent.setSource(fFacility.getLoader());
191 fTmfComponent.setCurrentTime(TC_003_TIME_VALUE);
192 fTmfComponent.setCurrentRange(null); // not used
193
194 fTmfComponent.setSignalReceived(false);
195
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());
203
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()));
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());
216
217 /**
218 * Verify 1st message across page.
219 *
220 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
221 * Expected result: Correct message is selected
222 */
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
227
228 fTmfComponent.setSignalReceived(false);
229
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);
236
237 assertTrue("find", fTmfComponent.isSignalReceived());
238 assertFalse("find", fTmfComponent.isSignalError());
239 assertFalse("find", fTmfComponent.isCurrentTimeError());
240 assertFalse("find", fTmfComponent.isSourceError());
241
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()));
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());
254
255 // cancel find and go back to first page
256 fFacility.getLoader().cancel();
257 }
258
259 /**
260 * Verify find of lifeline within page.
261 *
262 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
263 * Expected result: Correct message is selected
264 */
265 @Test
266 public void verifyFind() {
267 fFacility.firstPage();
268
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);
275
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());
283
284 /**
285 * Verify lifeline across page.
286 *
287 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
288 * Expected result: Correct message is selected
289 */
290 criteria = new Criteria();
291 criteria.setLifeLineSelected(true);
292 criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);
293
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);
300
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());
308
309 // cancel find and go back to first page
310 fFacility.getLoader().cancel();
311 }
312
313 /**
314 * Verify cancel ongoing search job.
315 *
316 * Verified Methods: loader.find(), loader.find()
317 * Expected result: Cancelled find
318 */
319 @Test
320 public void verifyCancelSearch() {
321
322 fFacility.firstPage();
323
324 criteria = new Criteria();
325 criteria.setLifeLineSelected(true);
326 criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);
327
328 fFacility.getLoader().find(criteria);
329 fFacility.delay(200); // to make sure job was started
330 fFacility.getLoader().cancel();
331
332 assertEquals("find", 0, fFacility.getLoader().currentPage()); // we are still at the first page
333
334 // cancel find and go back to first page
335 fFacility.getLoader().cancel();
336 fFacility.firstPage();
337 }
338 }
This page took 0.072486 seconds and 5 git commands to generate.