TMF: Add some non null annotations to TmfTimeRange
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / TmfUml2SDSyncLoaderTimeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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 * Alexandre Montplaisir - Port to JUnit4
12 * Patrick Tasse - Support selection range
13 *******************************************************************************/
14
15 package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
16
17 import static org.junit.Assert.assertEquals;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.List;
22
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.tracecompass.tmf.core.signal.TmfRangeSynchSignal;
25 import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
26 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
27 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
28 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode;
29 import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33
34 /**
35 * Test cases for time synchronization handling.
36 *
37 * @author Bernd Hufmann
38 */
39 public class TmfUml2SDSyncLoaderTimeTest {
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44
45 // Test case 001 expected values
46 final static private @NonNull Uml2SDTestTimestamp TC_001_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
47 final static private String TC_001_MESSAGE_NAME = "START_GAME_REPLY";
48 final static private int TC_001_PAGE_VALUE = 0;
49 final static private int TC_001_START_OCCURRANCE = 6;
50 final static private int TC_001_END_OCCURRANCE = TC_001_START_OCCURRANCE;
51 final static private String TC_001_START_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
52 final static private String TC_001_END_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
53
54 // Test case 002 expected values
55 final static private @NonNull Uml2SDTestTimestamp TC_002_TIME_VALUE = new Uml2SDTestTimestamp(9789689830722L);
56 final static private String TC_002_MESSAGE_NAME = "PAUSE_GAME_REQUEST";
57 final static private int TC_002_PAGE_VALUE = 2;
58 final static private int TC_002_START_OCCURRANCE = 7;
59 final static private int TC_002_END_OCCURRANCE = TC_002_START_OCCURRANCE;
60 final static private String TC_002_START_LIFELINE = IUml2SDTestConstants.FIRST_PLAYER_NAME;
61 final static private String TC_002_END_LIFELINE = IUml2SDTestConstants.MASTER_PLAYER_NAME;
62
63 // Test case 003 expected values
64 final static private @NonNull Uml2SDTestTimestamp TC_003_TIME_VALUE = new Uml2SDTestTimestamp(9790750000000L);
65 final static private int TC_003_PAGE_VALUE = 4;
66
67 // Test case 004 expected values
68 final static private int TC_004_PAGE_VALUE = 0;
69
70 // Test case 005 expected values
71 final static private int TC_005_PAGE_VALUE = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1;
72
73 // Test case 006 expected values
74 final static private @NonNull Uml2SDTestTimestamp TC_006_TIME_VALUE = new Uml2SDTestTimestamp(9792420661655L);
75 final static private int TC_006_PAGE_VALUE = 4;
76 final static private int TC_006_START_OCCURRANCE = IUml2SDTestConstants.MAX_MESSEAGES_PER_PAGE;
77 final static private int TC_006_END_OCCURRANCE = TC_006_START_OCCURRANCE;
78
79 // Test case 007 expected values
80 final static private @NonNull Uml2SDTestTimestamp TC_007_TIME_VALUE = new Uml2SDTestTimestamp(9792420756010L);
81 final static private int TC_007_PAGE_VALUE = 5;
82 final static private int TC_007_START_OCCURRANCE = 1;
83 final static private int TC_007_END_OCCURRANCE = TC_007_START_OCCURRANCE;
84
85 // Test case 008 expected values
86 final static private @NonNull Uml2SDTestTimestamp TC_008_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
87 final static private int TC_008_PAGE_VALUE = 0;
88 final static private @NonNull Uml2SDTestTimestamp TC_008_START_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
89 final static private @NonNull Uml2SDTestTimestamp TC_008_END_TIME_VALUE = new Uml2SDTestTimestamp(9789164833324L);
90
91 // Test case 009 expected values
92 final static private @NonNull Uml2SDTestTimestamp TC_009_TIME_VALUE = new Uml2SDTestTimestamp(9789689220871L);
93 final static private int TC_009_PAGE_VALUE = 1;
94 final static private @NonNull Uml2SDTestTimestamp TC_009_START_TIME_VALUE = TC_009_TIME_VALUE;
95 final static private @NonNull Uml2SDTestTimestamp TC_009_END_TIME_VALUE = new Uml2SDTestTimestamp(9789773881426L);
96
97 // Fields used in tests
98 private static Uml2SDTestFacility fFacility;
99 private static List<GraphNode> selection;
100 private static TmfSyncMessage msg;
101
102 // ------------------------------------------------------------------------
103 // Operations
104 // ------------------------------------------------------------------------
105
106 /**
107 * Initialization
108 */
109 @BeforeClass
110 public static void setUpClass() {
111 fFacility = Uml2SDTestFacility.getInstance();
112 fFacility.selectExperiment();
113 }
114
115 /**
116 * Cleanup
117 */
118 @AfterClass
119 public static void tearDownClass() {
120 fFacility.disposeExperiment();
121 fFacility = null;
122 }
123
124 /**
125 * Test Case: 001
126 * Description: Verify synchToTime (exact time in page), selection of message in page
127 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToMessageInPage()
128 * Expected result: Correct message is selected.
129 */
130 @Test
131 public void verifySynchToTimeInPage() {
132 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_001_TIME_VALUE));
133 fFacility.getLoader().waitForCompletion();
134 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
135 assertEquals("synchToTime", TC_001_PAGE_VALUE, fFacility.getLoader().currentPage());
136 selection = fFacility.getSdView().getSDWidget().getSelection();
137 assertNotNull(selection);
138 assertEquals("synchToTime", 1, selection.size());
139 assertTrue(selection.get(0) instanceof TmfSyncMessage);
140 msg = (TmfSyncMessage) selection.get(0);
141 assertEquals("synchToTime", TC_001_MESSAGE_NAME, msg.getName());
142 assertEquals("synchToTime", 0, TC_001_TIME_VALUE.compareTo(msg.getStartTime()));
143 assertEquals("synchToTime", TC_001_START_OCCURRANCE, msg.getStartOccurrence());
144 assertEquals("synchToTime", TC_001_END_OCCURRANCE, msg.getEndOccurrence());
145 assertEquals("synchToTime", TC_001_START_LIFELINE, msg.getStartLifeline().getName());
146 assertEquals("synchToTime", TC_001_END_LIFELINE, msg.getEndLifeline().getName());
147 }
148
149 /**
150 * Test Case: 002
151 * Description: Verify synchToTime (exact time outside of page), selection of message in page
152 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
153 * Expected result: Correct message is selected.
154 */
155 @Test
156 public void verifySynchToTimeOutsidePage() {
157 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_002_TIME_VALUE));
158 fFacility.getLoader().waitForCompletion();
159 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
160 assertEquals("synchToTime", TC_002_PAGE_VALUE, fFacility.getLoader().currentPage());
161 selection = fFacility.getSdView().getSDWidget().getSelection();
162 assertNotNull("synchToTime", selection);
163 assertEquals("synchToTime", 1, selection.size());
164 assertTrue("synchToTime", selection.get(0) instanceof TmfSyncMessage);
165 msg = (TmfSyncMessage) selection.get(0);
166 assertEquals("synchToTime", TC_002_MESSAGE_NAME, msg.getName());
167 assertEquals(0, TC_002_TIME_VALUE.compareTo(msg.getStartTime()));
168 assertEquals("synchToTime", TC_002_START_OCCURRANCE, msg.getStartOccurrence());
169 assertEquals("synchToTime", TC_002_END_OCCURRANCE, msg.getEndOccurrence());
170 assertEquals(TC_002_START_LIFELINE, msg.getStartLifeline().getName());
171 assertEquals(TC_002_END_LIFELINE, msg.getEndLifeline().getName());
172 }
173
174
175 /**
176 * Test Case: 003
177 * Description: Verify synchToTime (timestamp doesn't exist in trace), no selection of message in page
178 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
179 * Expected result: Move to correct page, currentTime is updated so that focus on the currentTime, but no selection.
180 */
181 @Test
182 public void verifySynchToTimeNonExisting() {
183 fFacility.getLoader().firstPage();
184
185 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_003_TIME_VALUE));
186 fFacility.getLoader().waitForCompletion();
187 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
188 assertEquals("synchToTime", 0, TC_003_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
189 assertEquals("synchToTime", TC_003_PAGE_VALUE, fFacility.getLoader().currentPage());
190 selection = fFacility.getSdView().getSDWidget().getSelection();
191 assertNotNull("synchToTime", selection);
192 assertEquals("synchToTime", 0, selection.size());
193 }
194
195 /**
196 * Test Case: 004
197 * Description: Verify synchToTime (timestamp < experiment time range start)
198 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
199 * Expected result: Move to first page, focus on the beginning of the page, but no selection.
200 */
201 @Test
202 public void verifySynchToTimeBeforeExpStart() {
203 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp.BIG_BANG));
204 fFacility.getLoader().waitForCompletion();
205 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
206 assertEquals("synchToTime", TC_004_PAGE_VALUE, fFacility.getLoader().currentPage());
207 selection = fFacility.getSdView().getSDWidget().getSelection();
208 assertNotNull("synchToTime", selection);
209 assertEquals("synchToTime", 0, selection.size());
210 }
211
212 /**
213 * Test Case: 005
214 * Description: Verify synchToTime (timestamp > experiment time range end)
215 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
216 * Expected result: Move to last page, focus on the end of the page, but no selection.
217 */
218 @Test
219 public void verifySynchToTimeAfterExpEnd() {
220 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp.BIG_CRUNCH));
221 fFacility.getLoader().waitForCompletion();
222 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
223 assertEquals("synchToTime", TC_005_PAGE_VALUE, fFacility.getLoader().currentPage());
224 selection = fFacility.getSdView().getSDWidget().getSelection();
225 assertNotNull(selection);
226 assertEquals("synchToTime", 0, selection.size());
227 }
228
229 /**
230 * Test Case: 006
231 * Description: Verify synchToTime (timestamp of last message in page)
232 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage(), loader.moveToMessageInPage()
233 * Expected result: Move to correct page, selection of last message in page.
234 */
235 @Test
236 public void verifySynchToTimeEqualsLast() {
237 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_006_TIME_VALUE));
238 fFacility.getLoader().waitForCompletion();
239 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
240 assertEquals("synchToTime", TC_006_PAGE_VALUE, fFacility.getLoader().currentPage());
241 selection = fFacility.getSdView().getSDWidget().getSelection();
242 assertNotNull("synchToTime", selection);
243 assertEquals("synchToTime", 1, selection.size());
244 msg = (TmfSyncMessage) selection.get(0);
245 assertEquals("synchToTime", TC_006_START_OCCURRANCE, msg.getStartOccurrence());
246 assertEquals("synchToTime", TC_006_END_OCCURRANCE, msg.getEndOccurrence());
247 }
248
249 /**
250 * Test Case: 007
251 * Description: Verify synchToTime (timestamp of first message in page)
252 * Verified Methods: loader.syncToTime(), loader.moveToMessage(), loader.moveToPage()
253 * Expected result: Move to correct page, selection of last message in page.
254 */
255 @Test
256 public void verifySynchToTimeFirst() {
257 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TC_007_TIME_VALUE));
258 fFacility.getLoader().waitForCompletion();
259 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
260 assertEquals("synchToTime", TC_007_PAGE_VALUE, fFacility.getLoader().currentPage());
261 selection = fFacility.getSdView().getSDWidget().getSelection();
262 assertNotNull("synchToTime", selection);
263 msg = (TmfSyncMessage) selection.get(0);
264 assertEquals("synchToTime", 1, selection.size());
265 assertEquals("synchToTime", TC_007_START_OCCURRANCE, msg.getStartOccurrence());
266 assertEquals("synchToTime", TC_007_END_OCCURRANCE, msg.getEndOccurrence());
267 }
268
269 /**
270 * Test Case: 008
271 * Description: Verify time range signal (start, end time and current time are in same page)
272 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToMessageInPage()
273 * Expected result: Move to correct page(=page of start time of range), set focus on start time of range, but no selection of message.
274 */
275 @Test
276 public void verifyTimeRangeSamePage() {
277 // 9788.642228395 (page 0) -> 9789.164833324 (page 0) with selected time 9788.642228395 (page 0)
278 fFacility.getLoader().firstPage();
279 TmfTimeRange range = new TmfTimeRange(TC_008_START_TIME_VALUE, TC_008_END_TIME_VALUE);
280 fFacility.getLoader().waitForCompletion();
281 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
282 fFacility.getTrace().broadcast(new TmfRangeSynchSignal(this, range));
283 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE, fFacility.getLoader().currentPage());
284 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
285 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
286 selection = fFacility.getSdView().getSDWidget().getSelection();
287 // We actually don't want something to be selected!!!
288 assertNotNull("synchToTimeRange", selection);
289 assertEquals("synchToTimeRange", 0, selection.size());
290 }
291
292 /**
293 * Test Case: 009
294 * Description: Verify time range signal (start and end time are across 2 pages)
295 * Verified Methods: loader.synchToTimeRange(), loader.moveToMessage(), loader.moveToPage()
296 * Expected result: Move to correct page (=page of start time of range), set focus on start time of range, but no selection of message.
297 */
298 @Test
299 public void verifyTimeRangeDifferentPages() {
300 TmfTimeRange range = new TmfTimeRange(TC_009_START_TIME_VALUE, TC_009_END_TIME_VALUE);
301 fFacility.getTrace().broadcast(new TmfRangeSynchSignal(this, range));
302 fFacility.getLoader().waitForCompletion();
303 fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
304 assertEquals("synchToTimeRange", TC_009_PAGE_VALUE, fFacility.getLoader().currentPage());
305 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
306 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
307 selection = fFacility.getSdView().getSDWidget().getSelection();
308 // We actually don't want something to be selected!!!
309 assertNotNull("synchToTimeRange", selection);
310 assertEquals("synchToTimeRange", 0, selection.size());
311 }
312 }
This page took 0.039171 seconds and 5 git commands to generate.