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
CommitLineData
73005152 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2011, 2014 Ericsson
64636df8 3 *
73005152
BH
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
64636df8 8 *
73005152
BH
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
90ed5958 11 * Alexandre Montplaisir - Port to JUnit4
0fcf3b09 12 * Patrick Tasse - Support selection range
73005152 13 *******************************************************************************/
90ed5958 14
2bdf0193 15package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
73005152 16
90ed5958
AM
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.assertTrue;
73005152 20
90ed5958 21import java.util.List;
73005152 22
6cfc180e 23import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
24import org.eclipse.tracecompass.tmf.core.signal.TmfRangeSynchSignal;
25import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
26import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
27import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
28import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode;
29import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
90ed5958
AM
30import org.junit.AfterClass;
31import org.junit.BeforeClass;
32import org.junit.Test;
73005152 33
64636df8
BH
34/**
35 * Test cases for time synchronization handling.
36 *
37 * @author Bernd Hufmann
64636df8 38 */
90ed5958 39public class TmfUml2SDSyncLoaderTimeTest {
73005152
BH
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
90ed5958 44
73005152 45 // Test case 001 expected values
6cfc180e 46 final static private @NonNull Uml2SDTestTimestamp TC_001_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
cad06250 47 final static private String TC_001_MESSAGE_NAME = "START_GAME_REPLY";
73005152
BH
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;
64636df8 53
73005152 54 // Test case 002 expected values
6cfc180e 55 final static private @NonNull Uml2SDTestTimestamp TC_002_TIME_VALUE = new Uml2SDTestTimestamp(9789689830722L);
cad06250 56 final static private String TC_002_MESSAGE_NAME = "PAUSE_GAME_REQUEST";
73005152
BH
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;
64636df8 62
73005152 63 // Test case 003 expected values
6cfc180e 64 final static private @NonNull Uml2SDTestTimestamp TC_003_TIME_VALUE = new Uml2SDTestTimestamp(9790750000000L);
73005152
BH
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;
64636df8 69
73005152
BH
70 // Test case 005 expected values
71 final static private int TC_005_PAGE_VALUE = IUml2SDTestConstants.TOTAL_NUMBER_OF_PAGES - 1;
64636df8 72
73005152 73 // Test case 006 expected values
6cfc180e 74 final static private @NonNull Uml2SDTestTimestamp TC_006_TIME_VALUE = new Uml2SDTestTimestamp(9792420661655L);
73005152
BH
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;
64636df8 78
73005152 79 // Test case 007 expected values
6cfc180e 80 final static private @NonNull Uml2SDTestTimestamp TC_007_TIME_VALUE = new Uml2SDTestTimestamp(9792420756010L);
73005152
BH
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;
64636df8 84
73005152 85 // Test case 008 expected values
6cfc180e 86 final static private @NonNull Uml2SDTestTimestamp TC_008_TIME_VALUE = new Uml2SDTestTimestamp(9788642228395L);
73005152 87 final static private int TC_008_PAGE_VALUE = 0;
6cfc180e
GB
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);
73005152
BH
90
91 // Test case 009 expected values
6cfc180e 92 final static private @NonNull Uml2SDTestTimestamp TC_009_TIME_VALUE = new Uml2SDTestTimestamp(9789689220871L);
7d1ef69c 93 final static private int TC_009_PAGE_VALUE = 1;
6cfc180e
GB
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);
64636df8 96
90ed5958
AM
97 // Fields used in tests
98 private static Uml2SDTestFacility fFacility;
99 private static List<GraphNode> selection;
100 private static TmfSyncMessage msg;
73005152 101
4f5d9f9b 102 // ------------------------------------------------------------------------
90ed5958 103 // Operations
4f5d9f9b
BH
104 // ------------------------------------------------------------------------
105
106 /**
90ed5958 107 * Initialization
64636df8 108 */
90ed5958
AM
109 @BeforeClass
110 public static void setUpClass() {
73005152 111 fFacility = Uml2SDTestFacility.getInstance();
73005152
BH
112 fFacility.selectExperiment();
113 }
114
90ed5958
AM
115 /**
116 * Cleanup
117 */
118 @AfterClass
119 public static void tearDownClass() {
73005152 120 fFacility.disposeExperiment();
73005152 121 fFacility = null;
73005152 122 }
64636df8
BH
123
124 /**
90ed5958
AM
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.
64636df8 129 */
90ed5958
AM
130 @Test
131 public void verifySynchToTimeInPage() {
73005152
BH
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());
90ed5958 136 selection = fFacility.getSdView().getSDWidget().getSelection();
73005152
BH
137 assertNotNull(selection);
138 assertEquals("synchToTime", 1, selection.size());
139 assertTrue(selection.get(0) instanceof TmfSyncMessage);
90ed5958 140 msg = (TmfSyncMessage) selection.get(0);
73005152 141 assertEquals("synchToTime", TC_001_MESSAGE_NAME, msg.getName());
065cc19b 142 assertEquals("synchToTime", 0, TC_001_TIME_VALUE.compareTo(msg.getStartTime()));
73005152
BH
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());
90ed5958 147 }
64636df8 148
90ed5958
AM
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() {
73005152
BH
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());
065cc19b 167 assertEquals(0, TC_002_TIME_VALUE.compareTo(msg.getStartTime()));
73005152
BH
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());
90ed5958 172 }
73005152 173
64636df8 174
90ed5958
AM
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() {
73005152
BH
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);
065cc19b 188 assertEquals("synchToTime", 0, TC_003_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
73005152
BH
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());
90ed5958 193 }
64636df8 194
90ed5958
AM
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() {
a4115405 203 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp.BIG_BANG));
73005152
BH
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());
90ed5958 210 }
64636df8 211
90ed5958
AM
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() {
a4115405 220 fFacility.getTrace().broadcast(new TmfTimeSynchSignal(this, TmfTimestamp.BIG_CRUNCH));
73005152
BH
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());
90ed5958 227 }
73005152 228
90ed5958
AM
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() {
73005152
BH
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());
90ed5958 247 }
64636df8 248
90ed5958
AM
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() {
73005152
BH
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());
90ed5958 267 }
73005152 268
90ed5958
AM
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() {
73005152
BH
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);
0fcf3b09 282 fFacility.getTrace().broadcast(new TmfRangeSynchSignal(this, range));
73005152
BH
283 assertEquals("synchToTimeRange", TC_008_PAGE_VALUE, fFacility.getLoader().currentPage());
284 assertNotNull("synchToTimeRange", fFacility.getLoader().getCurrentTime());
065cc19b 285 assertEquals("synchToTimeRange", 0, TC_008_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
73005152
BH
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());
90ed5958 290 }
64636df8 291
90ed5958
AM
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);
0fcf3b09 301 fFacility.getTrace().broadcast(new TmfRangeSynchSignal(this, range));
73005152
BH
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());
065cc19b 306 assertEquals("synchToTimeRange", 0, TC_009_TIME_VALUE.compareTo(fFacility.getLoader().getCurrentTime()));
73005152
BH
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());
73005152
BH
311 }
312}
This page took 0.114091 seconds and 5 git commands to generate.