Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b66c0df4f51279d4505283ece4de864e57c3c5c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*******************************************************************************
 * Copyright (c) 2011-2013 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Bernd Hufmann - Initial API and implementation
 *   Alexandre Montplaisir - Port to JUnit4
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs.Criteria;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDGraphNodeSupporter;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfSyncMessage;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Search Test Cases.
 *
 * @author Bernd Hufmann
 */
@SuppressWarnings("nls")
public class TmfUml2SDSyncLoaderFindTest {

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------

    // Test case 002 expected values
    final static private Uml2SDTestTimestamp TC_002_TIME_VALUE       = new Uml2SDTestTimestamp(9788642104149L);
    final static private String              TC_002_MESSAGE_NAME     = "GAME_REQUEST";
    final static private int                 TC_002_PAGE_VALUE       = 0;
    final static private int                 TC_002_START_OCCURRANCE = 3;
    final static private int                 TC_002_END_OCCURRANCE   = TC_002_START_OCCURRANCE;
    final static private String              TC_002_START_LIFELINE   = IUml2SDTestConstants.FIRST_PLAYER_NAME;
    final static private String              TC_002_END_LIFELINE     = IUml2SDTestConstants.MASTER_PLAYER_NAME;

    // Test case 003 expected values
    final static private Uml2SDTestTimestamp TC_003_TIME_VALUE       = new Uml2SDTestTimestamp(9788642113228L);
    final static private String              TC_003_MESSAGE_NAME     = "GAME_REPLY";
    final static private int                 TC_003_PAGE_VALUE       = 0;
    final static private int                 TC_003_START_OCCURRANCE = 4;
    final static private int                 TC_003_END_OCCURRANCE   = TC_003_START_OCCURRANCE;
    final static private String              TC_003_START_LIFELINE   = IUml2SDTestConstants.MASTER_PLAYER_NAME;
    final static private String              TC_003_END_LIFELINE     = IUml2SDTestConstants.FIRST_PLAYER_NAME;

    // Test case 004 expected values
    final static private Uml2SDTestTimestamp TC_004_TIME_VALUE       = new Uml2SDTestTimestamp(9791893030834L);
    final static private String              TC_004_MESSAGE_NAME     = "GAME_REQUEST";
    final static private int                 TC_004_PAGE_VALUE       = 4;
    final static private int                 TC_004_START_OCCURRANCE = 19;
    final static private int                 TC_004_END_OCCURRANCE   = TC_004_START_OCCURRANCE;
    final static private String              TC_004_START_LIFELINE   = IUml2SDTestConstants.SECOND_PLAYER_NAME;
    final static private String              TC_004_END_LIFELINE     = IUml2SDTestConstants.MASTER_PLAYER_NAME;

    // Test case 005 expected values
    final static private int                 TC_005_PAGE_VALUE       = 0;
    final static private String              TC_005_LIFELINE_NAME    = IUml2SDTestConstants.FIRST_PLAYER_NAME;

    // Test case 006 expected values
    final static private int                 TC_006_PAGE_VALUE       = 4;
    final static private String              TC_006_LIFELINE_NAME    = IUml2SDTestConstants.SECOND_PLAYER_NAME;

    // Fields used in tests
    private static Uml2SDTestFacility    fFacility;
    private static Uml2SDSignalValidator fTmfComponent;
    private static Criteria criteria;
    private static List<GraphNode> selection;
    private static TmfSyncMessage msg;
    private static Lifeline lifeline;

    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------

    /**
     * Initialization
     */
    @BeforeClass
    public static void setUpClass() {
        fFacility = Uml2SDTestFacility.getInstance();
        fFacility.selectExperiment();
    }

    /**
     * Cleanup
     */
    @AfterClass
    public static void tearDownClass() {
        fFacility.disposeExperiment();
        fFacility = null;
    }

    /**
     * Verify the ISDGraphNodeSupporter implementation.
     *
     * Verified Methods: loader.isNodeSupported(), loader.getNodeName()
     * Expected result: Correct values are returned, i.e. only lifelines and
     *                  sync. messages are supported.
     */
    @Test
    public void verifyISDGraphNodeSupporter() {
        fTmfComponent = new Uml2SDSignalValidator();

        assertTrue("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.LIFELINE));
        assertTrue("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGE));
        assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.SYNCMESSAGERETURN));
        assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGE));
        assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.ASYNCMESSAGERETURN));
        assertFalse("isNodeSupported", fFacility.getLoader().isNodeSupported(ISDGraphNodeSupporter.STOP));

        assertEquals("getNodeName", "Lifeline", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.LIFELINE, null));
        assertEquals("getNodeName", "Interaction", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.SYNCMESSAGE, null));
        assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.SYNCMESSAGERETURN, null));
        assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGE, null));
        assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.ASYNCMESSAGERETURN, null));
        assertEquals("getNodeName", "", fFacility.getLoader().getNodeName(ISDGraphNodeSupporter.STOP, null));

        fFacility.getLoader().cancel();
    }

    /**
     * Verify 1st message find within page.
     *
     * Verified Methods: loader.find(), loader.moveToMessage()
     * Expected result: Correct message is selected
     */
    @Test
    public void verifyFirstMessage() {
        criteria = new Criteria();
        criteria.setSyncMessageSelected(true);
        criteria.setExpression("GAME_.*");

        // set expected values
        fTmfComponent.setSource(fFacility.getLoader());
        fTmfComponent.setCurrentTime(TC_002_TIME_VALUE);
        fTmfComponent.setCurrentRange(null); // not used
        fTmfComponent.setSignalReceived(false);

        fFacility.getLoader().find(criteria);
        // Wait for the selection to finish - needed due to new platform behavior in Juno
	    fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
        assertTrue("find", fTmfComponent.isSignalReceived());
        assertFalse("find", fTmfComponent.isSignalError());
        assertFalse("find", fTmfComponent.isCurrentTimeError());
        assertFalse("find", fTmfComponent.isSourceError());

        assertEquals("find", TC_002_PAGE_VALUE, fFacility.getLoader().currentPage());
        selection = fFacility.getSdView().getSDWidget().getSelection();
        assertNotNull(selection);
        assertEquals("find", 1, selection.size());
        assertTrue(selection.get(0) instanceof TmfSyncMessage);
        msg = (TmfSyncMessage) selection.get(0);
        assertEquals("find", TC_002_MESSAGE_NAME, msg.getName());
        assertEquals("find", 0, TC_002_TIME_VALUE.compareTo(msg.getStartTime(), false));
        assertEquals("find", TC_002_START_OCCURRANCE, msg.getStartOccurrence());
        assertEquals("find", TC_002_END_OCCURRANCE, msg.getEndOccurrence());
        assertEquals("find", TC_002_START_LIFELINE, msg.getStartLifeline().getName());
        assertEquals("find", TC_002_END_LIFELINE, msg.getEndLifeline().getName());
    }

    /**
     * Verify 2nd message find within page.
     *
     * Verified Methods: loader.find(), loader.moveToMessage()
     * Expected result: Correct message is selected
     */
    @Test
    public void verifySecondMessage() {
        // set expected values
        fTmfComponent.setSource(fFacility.getLoader());
        fTmfComponent.setCurrentTime(TC_003_TIME_VALUE);
        fTmfComponent.setCurrentRange(null); // not used

        fTmfComponent.setSignalReceived(false);

        fFacility.getLoader().find(criteria);
        // Wait for the selection to finish - needed due to new platform behavior in Juno
		fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
        assertTrue("find", fTmfComponent.isSignalReceived());
        assertFalse("find", fTmfComponent.isSignalError());
        assertFalse("find", fTmfComponent.isCurrentTimeError());
        assertFalse("find", fTmfComponent.isSourceError());

        assertEquals("find", TC_003_PAGE_VALUE, fFacility.getLoader().currentPage());
        selection = fFacility.getSdView().getSDWidget().getSelection();
        assertNotNull(selection);
        assertEquals("find", 1, selection.size());
        assertTrue(selection.get(0) instanceof TmfSyncMessage);
        msg = (TmfSyncMessage) selection.get(0);
        assertEquals("find", TC_003_MESSAGE_NAME, msg.getName());
        assertEquals("find", 0, TC_003_TIME_VALUE.compareTo(msg.getStartTime(), false));
        assertEquals("find", TC_003_START_OCCURRANCE, msg.getStartOccurrence());
        assertEquals("find", TC_003_END_OCCURRANCE, msg.getEndOccurrence());
        assertEquals("find", TC_003_START_LIFELINE, msg.getStartLifeline().getName());
        assertEquals("find", TC_003_END_LIFELINE, msg.getEndLifeline().getName());
    }

    /**
     * Verify 1st message across page.
     *
     * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
     * Expected result: Correct message is selected
     */
    @Test
    public void verifyFirstMesage() {
        // set expected values
        fTmfComponent.setSource(fFacility.getLoader());
        fTmfComponent.setCurrentTime(TC_004_TIME_VALUE);
        fTmfComponent.setCurrentRange(new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH)); // not used

        fTmfComponent.setSignalReceived(false);

        fFacility.getLoader().find(criteria);
        fFacility.waitForJobs(); // find across pages uses a job
        // to make sure pageRequest has been started before calling waitforCompletion()
        fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
        fFacility.getLoader().waitForCompletion();
        fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);

        assertTrue("find", fTmfComponent.isSignalReceived());
        assertFalse("find", fTmfComponent.isSignalError());
        assertFalse("find", fTmfComponent.isCurrentTimeError());
        assertFalse("find", fTmfComponent.isSourceError());

        assertEquals("find", TC_004_PAGE_VALUE, fFacility.getLoader().currentPage());
        selection = fFacility.getSdView().getSDWidget().getSelection();
        assertNotNull(selection);
        assertEquals("find", 1, selection.size());
        assertTrue(selection.get(0) instanceof TmfSyncMessage);
        msg = (TmfSyncMessage) selection.get(0);
        assertEquals("find", TC_004_MESSAGE_NAME, msg.getName());
        assertEquals("find", 0, TC_004_TIME_VALUE.compareTo(msg.getStartTime(), false));
        assertEquals("find", TC_004_START_OCCURRANCE, msg.getStartOccurrence());
        assertEquals("find", TC_004_END_OCCURRANCE, msg.getEndOccurrence());
        assertEquals("find", TC_004_START_LIFELINE, msg.getStartLifeline().getName());
        assertEquals("find", TC_004_END_LIFELINE, msg.getEndLifeline().getName());

        // cancel find and go back to first page
        fFacility.getLoader().cancel();
        fFacility.firstPage();
    }

    /**
     * Verify find of lifeline within page.
     *
     * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
     * Expected result: Correct message is selected
     */
    @Test
    public void verifyFind() {
        criteria = new Criteria();
        criteria.setLifeLineSelected(true);
        criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
        fFacility.getLoader().find(criteria);
        // Wait for the selection to finish - needed due to new platform behavior in Juno
        fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);

        assertEquals("find", TC_005_PAGE_VALUE, fFacility.getLoader().currentPage());
        selection = fFacility.getSdView().getSDWidget().getSelection();
        assertNotNull(selection);
        assertEquals("find", 1, selection.size());
        assertTrue(selection.get(0) instanceof Lifeline);
        lifeline = (Lifeline) selection.get(0);
        assertEquals("find", TC_005_LIFELINE_NAME, lifeline.getName());
    }

    /**
     * Verify lifeline across page.
     *
     * Verified Methods: loader.find(), loader.moveToPage(), loader.moveToMessage()
     * Expected result: Correct message is selected
     */
    @Test
    public void verifyLifeline() {
        criteria = new Criteria();
        criteria.setLifeLineSelected(true);
        criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);

        fFacility.getLoader().find(criteria);
        fFacility.waitForJobs(); // find across pages uses a job
        // to make sure pageRequest has been started before calling waitforCompletion()
        fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
        fFacility.getLoader().waitForCompletion();
        fFacility.delay(IUml2SDTestConstants.GUI_REFESH_DELAY);

        assertEquals("find", TC_006_PAGE_VALUE, fFacility.getLoader().currentPage());
        selection = fFacility.getSdView().getSDWidget().getSelection();
        assertNotNull(selection);
        assertEquals("find", 1, selection.size());
        assertTrue(selection.get(0) instanceof Lifeline);
        lifeline = (Lifeline) selection.get(0);
        assertEquals("find", TC_006_LIFELINE_NAME, lifeline.getName());


        // cancel find and go back to first page
        fFacility.getLoader().cancel();
        fFacility.firstPage();
    }

    /**
     * Verify cancel ongoing search job.
     *
     * Verified Methods: loader.find(), loader.find()
     * Expected result: Cancelled find
     */
    @Test
    public void verifyCancelSearch() {
        criteria = new Criteria();
        criteria.setLifeLineSelected(true);
        criteria.setExpression(IUml2SDTestConstants.SECOND_PLAYER_NAME);

        fFacility.getLoader().find(criteria);
        fFacility.delay(200); // to make sure job was started
        fFacility.getLoader().cancel();

        assertEquals("find", 0, fFacility.getLoader().currentPage()); // we are still at the first page
        fTmfComponent.dispose();
    }
}

Back to the top