Contribution for Bug352466: [TMF] Implement UML2 Sequence Diagram
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / impl / TmfUml2SDSyncLoaderFindTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011 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.impl;
13
14 import java.util.List;
15
16 import junit.framework.TestCase;
17
18 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
19 import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
20 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
21 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
22 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
23 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.widgets.Criteria;
24 import org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfSyncMessage;
25
26 public class TmfUml2SDSyncLoaderFindTest extends TestCase {
27
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31
32 // Test case 002 expected values
33 final static private Uml2SDTestTimestamp TC_002_TIME_VALUE = new Uml2SDTestTimestamp(9788642104149L);
34 final static private String TC_002_MESSAGE_NAME = "GAME_REQUEST"; //$NON-NLS-1$
35 final static private int TC_002_PAGE_VALUE = 0;
36 final static private int TC_002_START_OCCURRANCE = 3;
37 final static private int TC_002_END_OCCURRANCE = TC_002_START_OCCURRANCE;
38 final static private String TC_002_START_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
39 final static private String TC_002_END_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
40
41 // Test case 003 expected values
42 final static private Uml2SDTestTimestamp TC_003_TIME_VALUE = new Uml2SDTestTimestamp(9788642113228L);
43 final static private String TC_003_MESSAGE_NAME = "GAME_REPLY"; //$NON-NLS-1$
44 final static private int TC_003_PAGE_VALUE = 0;
45 final static private int TC_003_START_OCCURRANCE = 4;
46 final static private int TC_003_END_OCCURRANCE = TC_003_START_OCCURRANCE;
47 final static private String TC_003_START_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
48 final static private String TC_003_END_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
49
50 // Test case 004 expected values
51 final static private Uml2SDTestTimestamp TC_004_TIME_VALUE = new Uml2SDTestTimestamp(9791893030834L);
52 final static private String TC_004_MESSAGE_NAME = "GAME_REQUEST"; //$NON-NLS-1$
53 final static private int TC_004_PAGE_VALUE = 4;
54 final static private int TC_004_START_OCCURRANCE = 19;
55 final static private int TC_004_END_OCCURRANCE = TC_004_START_OCCURRANCE;
56 final static private String TC_004_START_LIFELINE = IUml2SDTestConstants.SECOND_PLAYER_NAME;
57 final static private String TC_004_END_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
58
59 // Test case 005 expected values
60 final static private int TC_005_PAGE_VALUE = 0;
61 final static private String TC_005_LIFELINE_NAME = IUml2SDTestConstants.FIRST_PLAYER_NAME;
62
63 // Test case 006 expected values
64 final static private int TC_006_PAGE_VALUE = 4;
65 final static private String TC_006_LIFELINE_NAME = IUml2SDTestConstants.SECOND_PLAYER_NAME;
66
67 private Uml2SDTestFacility fFacility;
68 private Uml2SDSignalValidator fTmfComponent;
69
70 // ------------------------------------------------------------------------
71 // Constructors
72 // ------------------------------------------------------------------------
73 public TmfUml2SDSyncLoaderFindTest() {
74 }
75
76 // ------------------------------------------------------------------------
77 // Operations
78 // ------------------------------------------------------------------------
79 @Override
80 public void setUp() throws Exception {
81 super.setUp();
82 fFacility = Uml2SDTestFacility.getInstance();
83 fFacility.init(false);
84 fFacility.selectExperiment();
85 }
86
87 @Override
88 public void tearDown() throws Exception {
89 fFacility.disposeExperiment();
90 fFacility.dispose();
91 fFacility = null;
92 super.tearDown();
93 }
94
95 @SuppressWarnings("nls")
96 public void testFindHandling() {
97 fTmfComponent = new Uml2SDSignalValidator();
98
99 /*
100 * Test Case: 001
101 * Description: Verify the ISDGraphNodeSupporter implementation
102 * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
103 * Expected result: Correct values are returned, i.e. only lifelines and sync. messages are supported
104 */
105 assertTrue("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.LIFELINE));
106 assertTrue("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGE));
107 assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGERETURN));
108 assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGE));
109 assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGERETURN));
110 assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.STOP));
111
112 assertEquals("getNodeName", "Lifeline", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.LIFELINE, null));
113 assertEquals("getNodeName", "Interaction", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.SYNCMESSAGE, null));
114 assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.SYNCMESSAGERETURN, null));
115 assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGE, null));
116 assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGERETURN, null));
117 assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.STOP, null));
118
119 fFacility.getLoader().cancel();
120
121 /*
122 * Test Case: 002
123 * Description: Verify 1st message find within page
124 * Verified Methods: loader.find(), loader.moveToMessage()
125 * Expected result: Correct message is selected
126 */
127 Criteria criteria = new Criteria();
128 criteria.setSyncMessageSelected(true);
129 criteria.setExpression("GAME_.*");
130
131 // set expected values
132 fTmfComponent.setSource(fFacility.getLoader());
133 fTmfComponent.setCurrentTime(TC_002_TIME_VALUE);
134 fTmfComponent.setCurrentRange(null); // not used
135 fTmfComponent.setSignalReceived(false);
136
137 fFacility.getLoader().find(criteria);
138 assertTrue("find", fTmfComponent.isSignalReceived());
139 assertFalse("find", fTmfComponent.isSignalError());
140 assertFalse("find", fTmfComponent.isCurrentTimeError());
141 assertFalse("find", fTmfComponent.isSourceError());
142
143 assertEquals("find", TC_002_PAGE_VALUE, fFacility.getLoader().currentPage());
144 List<GraphNode> selection = fFacility.getSdView().getSDWidget().getSelection();
145 assertNotNull(selection);
146 assertEquals("find", 1, selection.size());
147 assertTrue(selection.get(0) instanceof TmfSyncMessage);
148 TmfSyncMessage msg = (TmfSyncMessage) selection.get(0);
149 assertEquals("find", TC_002_MESSAGE_NAME, msg.getName());
150 assertEquals("find", 0, TC_002_TIME_VALUE.compareTo(msg.getStartTime(), false));
151 assertEquals("find", TC_002_START_OCCURRANCE, msg.getStartOccurrence());
152 assertEquals("find", TC_002_END_OCCURRANCE, msg.getEndOccurrence());
153 assertEquals("find", TC_002_START_LIFELINE, msg.getStartLifeline().getName());
154 assertEquals("find", TC_002_END_LIFELINE, msg.getEndLifeline().getName());
155
156 /*
157 * Test Case: 003
158 * Description: Verify 2nd message find within page
159 * Verified Methods: loader.find(), loader.moveToMessage()
160 * Expected result: Correct message is selected
161 */
162 // set expected values
163 fTmfComponent.setSource(fFacility.getLoader());
164 fTmfComponent.setCurrentTime(TC_003_TIME_VALUE);
165 fTmfComponent.setCurrentRange(null); // not used
166
167 fTmfComponent.setSignalReceived(false);
168
169 fFacility.getLoader().find(criteria);
170 assertTrue("find", fTmfComponent.isSignalReceived());
171 assertFalse("find", fTmfComponent.isSignalError());
172 assertFalse("find", fTmfComponent.isCurrentTimeError());
173 assertFalse("find", fTmfComponent.isSourceError());
174
175 assertEquals("find", TC_003_PAGE_VALUE, fFacility.getLoader().currentPage());
176 selection = fFacility.getSdView().getSDWidget().getSelection();
177 assertNotNull(selection);
178 assertEquals("find", 1, selection.size());
179 assertTrue(selection.get(0) instanceof TmfSyncMessage);
180 msg = (TmfSyncMessage) selection.get(0);
181 assertEquals("find", TC_003_MESSAGE_NAME, msg.getName());
182 assertEquals("find", 0, TC_003_TIME_VALUE.compareTo(msg.getStartTime(), false));
183 assertEquals("find", TC_003_START_OCCURRANCE, msg.getStartOccurrence());
184 assertEquals("find", TC_003_END_OCCURRANCE, msg.getEndOccurrence());
185 assertEquals("find", TC_003_START_LIFELINE, msg.getStartLifeline().getName());
186 assertEquals("find", TC_003_END_LIFELINE, msg.getEndLifeline().getName());
187
188 /*
189 * Test Case: 004
190 * Description: Verify 1st message across page
191 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
192 * Expected result: Correct message is selected
193 */
194 // set expected values
195 fTmfComponent.setSource(fFacility.getLoader());
196 fTmfComponent.setCurrentTime(TC_004_TIME_VALUE);
197 fTmfComponent.setCurrentRange(new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch)); // not used
198
199 fTmfComponent.setSignalReceived(false);
200
201 fFacility.getLoader().find(criteria);
202 fFacility.waitForJobs(); // find across pages uses a job
203 fFacility.getLoader().waitForCompletion();
204 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
205
206 assertTrue("find", fTmfComponent.isSignalReceived());
207 assertFalse("find", fTmfComponent.isSignalError());
208 assertFalse("find", fTmfComponent.isCurrentTimeError());
209 assertFalse("find", fTmfComponent.isSourceError());
210
211 assertEquals("find", TC_004_PAGE_VALUE, fFacility.getLoader().currentPage());
212 selection = fFacility.getSdView().getSDWidget().getSelection();
213 assertNotNull(selection);
214 assertEquals("find", 1, selection.size());
215 assertTrue(selection.get(0) instanceof TmfSyncMessage);
216 msg = (TmfSyncMessage) selection.get(0);
217 assertEquals("find", TC_004_MESSAGE_NAME, msg.getName());
218 assertEquals("find", 0, TC_004_TIME_VALUE.compareTo(msg.getStartTime(), false));
219 assertEquals("find", TC_004_START_OCCURRANCE, msg.getStartOccurrence());
220 assertEquals("find", TC_004_END_OCCURRANCE, msg.getEndOccurrence());
221 assertEquals("find", TC_004_START_LIFELINE, msg.getStartLifeline().getName());
222 assertEquals("find", TC_004_END_LIFELINE, msg.getEndLifeline().getName());
223
224 // cancel find and go back to first page
225 fFacility.getLoader().cancel();
226 fFacility.firstPage();
227
228 /*
229 * Test Case: 005
230 * Description: Verify find of lifeline within page
231 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
232 * Expected result: Correct message is selected
233 */
234 criteria = new Criteria();
235 criteria.setLifeLineSelected(true);
236 criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
237 fFacility.getLoader().find(criteria);
238
239 assertEquals("find", TC_005_PAGE_VALUE, fFacility.getLoader().currentPage());
240 selection = fFacility.getSdView().getSDWidget().getSelection();
241 assertNotNull(selection);
242 assertEquals("find", 1, selection.size());
243 assertTrue(selection.get(0) instanceof Lifeline);
244 Lifeline lifeline = (Lifeline) selection.get(0);
245 assertEquals("find", TC_005_LIFELINE_NAME, lifeline.getName());
246
247 /*
248 * Test Case: 006
249 * Description: Verify lifeline across page
250 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
251 * Expected result: Correct message is selected
252 */
253 criteria = new Criteria();
254 criteria.setLifeLineSelected(true);
255 criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);
256
257 fFacility.getLoader().find(criteria);
258 fFacility.waitForJobs(); // find across pages uses a job
259 fFacility.getLoader().waitForCompletion();
260 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
261
262 assertEquals("find", TC_006_PAGE_VALUE, fFacility.getLoader().currentPage());
263 selection = fFacility.getSdView().getSDWidget().getSelection();
264 assertNotNull(selection);
265 assertEquals("find", 1, selection.size());
266 assertTrue(selection.get(0) instanceof Lifeline);
267 lifeline = (Lifeline) selection.get(0);
268 assertEquals("find", TC_006_LIFELINE_NAME, lifeline.getName());
269
270
271 // cancel find and go back to first page
272 fFacility.getLoader().cancel();
273 fFacility.firstPage();
274
275 /*
276 * Test Case: 007
277 * Description: Verify cancel ongoing search job
278 * Verified Methods: loader.find(), loader.find()
279 * Expected result: Cancelled find
280 */
281 criteria = new Criteria();
282 criteria.setLifeLineSelected(true);
283 criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);
284
285 fFacility.getLoader().find(criteria);
286 fFacility.delay(200); // to make sure job was started
287 fFacility.getLoader().cancel();
288
289 assertEquals("find", 0, fFacility.getLoader().currentPage()); // we are still at the first page
290 fTmfComponent.dispose();
291 }
292 }
This page took 0.037363 seconds and 5 git commands to generate.