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
.TestCase
;
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
;
26 public class TmfUml2SDSyncLoaderFindTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
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
;
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
;
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
;
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
;
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
;
67 private Uml2SDTestFacility fFacility
;
68 private Uml2SDSignalValidator fTmfComponent
;
70 // ------------------------------------------------------------------------
72 // ------------------------------------------------------------------------
73 public TmfUml2SDSyncLoaderFindTest() {
76 // ------------------------------------------------------------------------
78 // ------------------------------------------------------------------------
80 public void setUp() throws Exception
{
82 fFacility
= Uml2SDTestFacility
.getInstance();
83 fFacility
.init(false);
84 fFacility
.selectExperiment();
88 public void tearDown() throws Exception
{
89 fFacility
.disposeExperiment();
95 @SuppressWarnings("nls")
96 public void testFindHandling() {
97 fTmfComponent
= new Uml2SDSignalValidator();
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
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
));
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));
119 fFacility
.getLoader().cancel();
123 * Description: Verify 1st message find within page
124 * Verified Methods: loader.find(), loader.moveToMessage()
125 * Expected result: Correct message is selected
127 Criteria criteria
= new Criteria();
128 criteria
.setSyncMessageSelected(true);
129 criteria
.setExpression("GAME_.*");
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);
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());
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());
158 * Description: Verify 2nd message find within page
159 * Verified Methods: loader.find(), loader.moveToMessage()
160 * Expected result: Correct message is selected
162 // set expected values
163 fTmfComponent
.setSource(fFacility
.getLoader());
164 fTmfComponent
.setCurrentTime(TC_003_TIME_VALUE
);
165 fTmfComponent
.setCurrentRange(null); // not used
167 fTmfComponent
.setSignalReceived(false);
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());
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());
190 * Description: Verify 1st message across page
191 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
192 * Expected result: Correct message is selected
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
199 fTmfComponent
.setSignalReceived(false);
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
);
206 assertTrue("find", fTmfComponent
.isSignalReceived());
207 assertFalse("find", fTmfComponent
.isSignalError());
208 assertFalse("find", fTmfComponent
.isCurrentTimeError());
209 assertFalse("find", fTmfComponent
.isSourceError());
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());
224 // cancel find and go back to first page
225 fFacility
.getLoader().cancel();
226 fFacility
.firstPage();
230 * Description: Verify find of lifeline within page
231 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
232 * Expected result: Correct message is selected
234 criteria
= new Criteria();
235 criteria
.setLifeLineSelected(true);
236 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
237 fFacility
.getLoader().find(criteria
);
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());
249 * Description: Verify lifeline across page
250 * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
251 * Expected result: Correct message is selected
253 criteria
= new Criteria();
254 criteria
.setLifeLineSelected(true);
255 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
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
);
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());
271 // cancel find and go back to first page
272 fFacility
.getLoader().cancel();
273 fFacility
.firstPage();
277 * Description: Verify cancel ongoing search job
278 * Verified Methods: loader.find(), loader.find()
279 * Expected result: Cancelled find
281 criteria
= new Criteria();
282 criteria
.setLifeLineSelected(true);
283 criteria
.setExpression(IUml2SDTestConstants
.SECOND_PLAYER_NAME
);
285 fFacility
.getLoader().find(criteria
);
286 fFacility
.delay(200); // to make sure job was started
287 fFacility
.getLoader().cancel();
289 assertEquals("find", 0, fFacility
.getLoader().currentPage()); // we are still at the first page
290 fTmfComponent
.dispose();