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