1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.impl
;
14 import java
.util
.List
;
16 import junit
.framework
.Test
;
17 import junit
.framework
.TestCase
;
18 import junit
.framework
.TestSuite
;
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
.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
;
28 public class TmfUml2SDSyncLoaderFindTest
extends TestCase
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
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
;
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
;
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
;
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
;
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
;
69 private Uml2SDTestFacility fFacility
;
70 private Uml2SDSignalValidator fTmfComponent
;
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
77 * Returns test setup used when executing test case stand-alone.
78 * @return Test setup class
80 public static Test
suite() {
81 return new Uml2SDTestSetup(new TestSuite(TmfUml2SDSyncLoaderFindTest
.class));
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
87 public TmfUml2SDSyncLoaderFindTest() {
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 public void setUp() throws Exception
{
96 fFacility
= Uml2SDTestFacility
.getInstance();
97 fFacility
.selectExperiment();
101 public void tearDown() throws Exception
{
102 fFacility
.disposeExperiment();
107 @SuppressWarnings("nls")
108 public void testFindHandling() {
109 fTmfComponent
= new Uml2SDSignalValidator();
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
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
));
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));
131 fFacility
.getLoader().cancel();
135 * Description: Verify 1st message find within page
136 * Verified Methods: loader.find(), loader.moveToMessage()
137 * Expected result: Correct message is selected
139 Criteria criteria
= new Criteria();
140 criteria
.setSyncMessageSelected(true);
141 criteria
.setExpression("GAME_.*");
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);
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());
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());
170 * Description: Verify 2nd message find within page
171 * Verified Methods: loader.find(), loader.moveToMessage()
172 * Expected result: Correct message is selected
174 // set expected values
175 fTmfComponent
.setSource(fFacility
.getLoader());
176 fTmfComponent
.setCurrentTime(TC_003_TIME_VALUE
);
177 fTmfComponent
.setCurrentRange(null); // not used
179 fTmfComponent
.setSignalReceived(false);
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());
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());
202 * Description: Verify 1st message across page
203 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
204 * Expected result: Correct message is selected
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
211 fTmfComponent
.setSignalReceived(false);
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
);
218 assertTrue("find", fTmfComponent
.isSignalReceived());
219 assertFalse("find", fTmfComponent
.isSignalError());
220 assertFalse("find", fTmfComponent
.isCurrentTimeError());
221 assertFalse("find", fTmfComponent
.isSourceError());
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());
236 // cancel find and go back to first page
237 fFacility
.getLoader().cancel();
238 fFacility
.firstPage();
242 * Description: Verify find of lifeline within page
243 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
244 * Expected result: Correct message is selected
246 criteria
= new Criteria();
247 criteria
.setLifeLineSelected(true);
248 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
249 fFacility
.getLoader().find(criteria
);
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());
261 * Description: Verify lifeline across page
262 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
263 * Expected result: Correct message is selected
265 criteria
= new Criteria();
266 criteria
.setLifeLineSelected(true);
267 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
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
);
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());
283 // cancel find and go back to first page
284 fFacility
.getLoader().cancel();
285 fFacility
.firstPage();
289 * Description: Verify cancel ongoing search job
290 * Verified Methods: loader.find(), loader.find()
291 * Expected result: Cancelled find
293 criteria
= new Criteria();
294 criteria
.setLifeLineSelected(true);
295 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
297 fFacility
.getLoader().find(criteria
);
298 fFacility
.delay(200); // to make sure job was started
299 fFacility
.getLoader().cancel();
301 assertEquals("find", 0, fFacility
.getLoader().currentPage()); // we are still at the first page
302 fTmfComponent
.dispose();