Commit | Line | Data |
---|---|---|
73005152 | 1 | /******************************************************************************* |
90ed5958 | 2 | * Copyright (c) 2011-2013 Ericsson |
64636df8 | 3 | * |
73005152 BH |
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 | |
64636df8 | 8 | * |
73005152 BH |
9 | * Contributors: |
10 | * Bernd Hufmann - Initial API and implementation | |
90ed5958 | 11 | * Alexandre Montplaisir - Port to JUnit4 |
73005152 | 12 | *******************************************************************************/ |
90ed5958 | 13 | |
df0b8ff4 | 14 | package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader; |
73005152 | 15 | |
90ed5958 AM |
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; | |
73005152 | 20 | |
90ed5958 | 21 | import java.util.List; |
73005152 | 22 | |
3bd46eef AM |
23 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; |
24 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp; | |
73005152 BH |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode; |
26 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline; | |
df0b8ff4 | 27 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria; |
73005152 | 28 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter; |
df0b8ff4 | 29 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfSyncMessage; |
90ed5958 AM |
30 | import org.junit.AfterClass; |
31 | import org.junit.BeforeClass; | |
32 | import org.junit.Test; | |
73005152 | 33 | |
64636df8 BH |
34 | /** |
35 | * Search Test Cases. | |
36 | * | |
37 | * @author Bernd Hufmann | |
38 | */ | |
90ed5958 | 39 | public class TmfUml2SDSyncLoaderFindTest { |
64636df8 | 40 | |
73005152 BH |
41 | // ------------------------------------------------------------------------ |
42 | // Attributes | |
43 | // ------------------------------------------------------------------------ | |
44 | ||
45 | // Test case 002 expected values | |
46 | final static private Uml2SDTestTimestamp TC_002_TIME_VALUE = new Uml2SDTestTimestamp(9788642104149L); | |
90ed5958 | 47 | final static private String TC_002_MESSAGE_NAME = "GAME_REQUEST"; |
73005152 BH |
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; | |
64636df8 | 53 | |
73005152 BH |
54 | // Test case 003 expected values |
55 | final static private Uml2SDTestTimestamp TC_003_TIME_VALUE = new Uml2SDTestTimestamp(9788642113228L); | |
90ed5958 | 56 | final static private String TC_003_MESSAGE_NAME = "GAME_REPLY"; |
73005152 BH |
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; | |
64636df8 | 62 | |
73005152 BH |
63 | // Test case 004 expected values |
64 | final static private Uml2SDTestTimestamp TC_004_TIME_VALUE = new Uml2SDTestTimestamp(9791893030834L); | |
90ed5958 | 65 | final static private String TC_004_MESSAGE_NAME = "GAME_REQUEST"; |
73005152 BH |
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; | |
64636df8 | 69 | final static private String TC_004_START_LIFELINE = IUml2SDTestConstants.SECOND_PLAYER_NAME; |
73005152 | 70 | final static private String TC_004_END_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME; |
64636df8 | 71 | |
73005152 BH |
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 | ||
90ed5958 AM |
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; | |
73005152 | 87 | |
4f5d9f9b | 88 | // ------------------------------------------------------------------------ |
90ed5958 | 89 | // Operations |
64636df8 | 90 | // ------------------------------------------------------------------------ |
4f5d9f9b BH |
91 | |
92 | /** | |
90ed5958 | 93 | * Initialization |
64636df8 | 94 | */ |
90ed5958 AM |
95 | @BeforeClass |
96 | public static void setUpClass() { | |
73005152 | 97 | fFacility = Uml2SDTestFacility.getInstance(); |
73005152 | 98 | fFacility.selectExperiment(); |
f5944f9f | 99 | fTmfComponent = new Uml2SDSignalValidator(); |
73005152 BH |
100 | } |
101 | ||
90ed5958 AM |
102 | /** |
103 | * Cleanup | |
104 | */ | |
105 | @AfterClass | |
106 | public static void tearDownClass() { | |
f5944f9f | 107 | fTmfComponent.dispose(); |
73005152 | 108 | fFacility.disposeExperiment(); |
73005152 | 109 | fFacility = null; |
73005152 | 110 | } |
64636df8 BH |
111 | |
112 | /** | |
90ed5958 AM |
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. | |
64636df8 | 118 | */ |
90ed5958 AM |
119 | @Test |
120 | public void verifyISDGraphNodeSupporter() { | |
f5944f9f BH |
121 | |
122 | fFacility.firstPage(); | |
73005152 | 123 | |
73005152 BH |
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)); | |
64636df8 | 137 | |
73005152 | 138 | fFacility.getLoader().cancel(); |
90ed5958 | 139 | } |
64636df8 | 140 | |
90ed5958 AM |
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() { | |
f5944f9f BH |
149 | fFacility.firstPage(); |
150 | ||
90ed5958 | 151 | criteria = new Criteria(); |
73005152 BH |
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); | |
64636df8 | 160 | |
73005152 | 161 | fFacility.getLoader().find(criteria); |
64636df8 | 162 | // Wait for the selection to finish - needed due to new platform behavior in Juno |
d5efe032 | 163 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); |
73005152 BH |
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()); | |
90ed5958 | 170 | selection = fFacility.getSdView().getSDWidget().getSelection(); |
73005152 BH |
171 | assertNotNull(selection); |
172 | assertEquals("find", 1, selection.size()); | |
173 | assertTrue(selection.get(0) instanceof TmfSyncMessage); | |
90ed5958 | 174 | msg = (TmfSyncMessage) selection.get(0); |
73005152 BH |
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()); | |
64636df8 | 181 | |
f5944f9f BH |
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 | ||
73005152 BH |
189 | // set expected values |
190 | fTmfComponent.setSource(fFacility.getLoader()); | |
191 | fTmfComponent.setCurrentTime(TC_003_TIME_VALUE); | |
192 | fTmfComponent.setCurrentRange(null); // not used | |
64636df8 | 193 | |
73005152 | 194 | fTmfComponent.setSignalReceived(false); |
64636df8 | 195 | |
73005152 | 196 | fFacility.getLoader().find(criteria); |
814969ed | 197 | // Wait for the selection to finish - needed due to new platform behavior in Juno |
d5efe032 | 198 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); |
73005152 BH |
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(), 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()); | |
216 | ||
f5944f9f BH |
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 | */ | |
73005152 BH |
223 | // set expected values |
224 | fTmfComponent.setSource(fFacility.getLoader()); | |
225 | fTmfComponent.setCurrentTime(TC_004_TIME_VALUE); | |
a4115405 | 226 | fTmfComponent.setCurrentRange(new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH)); // not used |
64636df8 | 227 | |
73005152 | 228 | fTmfComponent.setSignalReceived(false); |
64636df8 | 229 | |
73005152 BH |
230 | fFacility.getLoader().find(criteria); |
231 | fFacility.waitForJobs(); // find across pages uses a job | |
30629bbf BH |
232 | // to make sure pageRequest has been started before calling waitforCompletion() |
233 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); | |
73005152 BH |
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(), 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()); | |
254 | ||
255 | // cancel find and go back to first page | |
256 | fFacility.getLoader().cancel(); | |
90ed5958 | 257 | } |
64636df8 | 258 | |
90ed5958 AM |
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() { | |
f5944f9f BH |
267 | fFacility.firstPage(); |
268 | ||
64636df8 | 269 | criteria = new Criteria(); |
73005152 BH |
270 | criteria.setLifeLineSelected(true); |
271 | criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME); | |
272 | fFacility.getLoader().find(criteria); | |
814969ed BH |
273 | // Wait for the selection to finish - needed due to new platform behavior in Juno |
274 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); | |
275 | ||
73005152 BH |
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); | |
90ed5958 | 281 | lifeline = (Lifeline) selection.get(0); |
73005152 | 282 | assertEquals("find", TC_005_LIFELINE_NAME, lifeline.getName()); |
64636df8 | 283 | |
f5944f9f BH |
284 | /** |
285 | * Verify lifeline across page. | |
286 | * | |
287 | * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage() | |
288 | * Expected result: Correct message is selected | |
289 | */ | |
64636df8 | 290 | criteria = new Criteria(); |
73005152 BH |
291 | criteria.setLifeLineSelected(true); |
292 | criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME); | |
64636df8 | 293 | |
73005152 BH |
294 | fFacility.getLoader().find(criteria); |
295 | fFacility.waitForJobs(); // find across pages uses a job | |
30629bbf | 296 | // to make sure pageRequest has been started before calling waitforCompletion() |
64636df8 | 297 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); |
73005152 BH |
298 | fFacility.getLoader().waitForCompletion(); |
299 | fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY); | |
64636df8 | 300 | |
73005152 BH |
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()); | |
64636df8 | 308 | |
73005152 BH |
309 | // cancel find and go back to first page |
310 | fFacility.getLoader().cancel(); | |
90ed5958 | 311 | } |
64636df8 | 312 | |
90ed5958 AM |
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() { | |
f5944f9f BH |
321 | |
322 | fFacility.firstPage(); | |
323 | ||
64636df8 | 324 | criteria = new Criteria(); |
73005152 BH |
325 | criteria.setLifeLineSelected(true); |
326 | criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME); | |
64636df8 | 327 | |
73005152 BH |
328 | fFacility.getLoader().find(criteria); |
329 | fFacility.delay(200); // to make sure job was started | |
330 | fFacility.getLoader().cancel(); | |
64636df8 | 331 | |
73005152 | 332 | assertEquals("find", 0, fFacility.getLoader().currentPage()); // we are still at the first page |
f5944f9f BH |
333 | |
334 | // cancel find and go back to first page | |
335 | fFacility.getLoader().cancel(); | |
336 | fFacility.firstPage(); | |
73005152 BH |
337 | } |
338 | } |