tmf: Enable the ctfadaptor and statistics unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderFindTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 *******************************************************************************/
12 package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;
13
14 import java.util.List;
15
16 import junit.framework.Test;
17 import junit.framework.TestCase;
18 import junit.framework.TestSuite;
19
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;
27
28 /**
29 * Search Test Cases.
30 *
31 * @author Bernd Hufmann
32 */
33 public class TmfUml2SDSyncLoaderFindTest extends TestCase {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38
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;
47
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;
56
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;
65
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;
69
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;
73
74 private Uml2SDTestFacility fFacility;
75 private Uml2SDSignalValidator fTmfComponent;
76
77 // ------------------------------------------------------------------------
78 // Static methods
79 // ------------------------------------------------------------------------
80
81 /**
82 * Returns test setup used when executing test case stand-alone.
83 * @return Test setup class
84 */
85 public static Test suite() {
86 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderFindTest.class));
87 }
88
89 // ------------------------------------------------------------------------
90 // Constructors
91 // ------------------------------------------------------------------------
92 /**
93 * Constructor
94 */
95 public TmfUml2SDSyncLoaderFindTest() {
96 }
97
98 // ------------------------------------------------------------------------
99 // Operations
100 // ------------------------------------------------------------------------
101 @Override
102 public void setUp() throws Exception {
103 super.setUp();
104 fFacility = Uml2SDTestFacility.getInstance();
105 fFacility.selectExperiment();
106 }
107
108 @Override
109 public void tearDown() throws Exception {
110 fFacility.disposeExperiment();
111 fFacility = null;
112 super.tearDown();
113 }
114
115 /**
116 * Main method with test cases.
117 */
118 @SuppressWarnings("nls")
119 public void testFindHandling() {
120 fTmfComponent = new Uml2SDSignalValidator();
121
122 /*
123 * Test Case: 001
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
127 */
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));
134
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));
141
142 fFacility.getLoader().cancel();
143
144 /*
145 * Test Case: 002
146 * Description: Verify 1st message find within page
147 * Verified Methods: loader.find(), loader.moveToMessage()
148 * Expected result: Correct message is selected
149 */
150 Criteria criteria = new Criteria();
151 criteria.setSyncMessageSelected(true);
152 criteria.setExpression("GAME_.*");
153
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);
159
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());
167
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());
180
181 /*
182 * Test Case: 003
183 * Description: Verify 2nd message find within page
184 * Verified Methods: loader.find(), loader.moveToMessage()
185 * Expected result: Correct message is selected
186 */
187 // set expected values
188 fTmfComponent.setSource(fFacility.getLoader());
189 fTmfComponent.setCurrentTime(TC_003_TIME_VALUE);
190 fTmfComponent.setCurrentRange(null); // not used
191
192 fTmfComponent.setSignalReceived(false);
193
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());
201
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());
214
215 /*
216 * Test Case: 004
217 * Description: Verify 1st message across page
218 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
219 * Expected result: Correct message is selected
220 */
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
225
226 fTmfComponent.setSignalReceived(false);
227
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);
234
235 assertTrue("find", fTmfComponent.isSignalReceived());
236 assertFalse("find", fTmfComponent.isSignalError());
237 assertFalse("find", fTmfComponent.isCurrentTimeError());
238 assertFalse("find", fTmfComponent.isSourceError());
239
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());
252
253 // cancel find and go back to first page
254 fFacility.getLoader().cancel();
255 fFacility.firstPage();
256
257 /*
258 * Test Case: 005
259 * Description: Verify find of lifeline within page
260 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
261 * Expected result: Correct message is selected
262 */
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);
269
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());
277
278 /*
279 * Test Case: 006
280 * Description: Verify lifeline across page
281 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
282 * Expected result: Correct message is selected
283 */
284 criteria = new Criteria();
285 criteria.setLifeLineSelected(true);
286 criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);
287
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);
294
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());
302
303
304 // cancel find and go back to first page
305 fFacility.getLoader().cancel();
306 fFacility.firstPage();
307
308 /*
309 * Test Case: 007
310 * Description: Verify cancel ongoing search job
311 * Verified Methods: loader.find(), loader.find()
312 * Expected result: Cancelled find
313 */
314 criteria = new Criteria();
315 criteria.setLifeLineSelected(true);
316 criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);
317
318 fFacility.getLoader().find(criteria);
319 fFacility.delay(200); // to make sure job was started
320 fFacility.getLoader().cancel();
321
322 assertEquals("find", 0, fFacility.getLoader().currentPage()); // we are still at the first page
323 fTmfComponent.dispose();
324 }
325 }
This page took 0.049006 seconds and 5 git commands to generate.