tmf: Fix intermittent fail in ProjectModelOutputTest.testListOutputs
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / project / model / ProjectModelTraceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.tests.project.model;
14
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertTrue;
18 import static org.junit.Assert.fail;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
23 import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
24 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
25 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
26 import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
27 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31
32 /**
33 * Test suite for the TmfTraceElement class.
34 *
35 * @author Geneviève Bastien
36 */
37 public class ProjectModelTraceTest {
38
39 private TmfProjectElement fixture;
40
41 /**
42 * Perform pre-test initialization.
43 */
44 @Before
45 public void setUp() {
46 try {
47 fixture = ProjectModelTestData.getFilledProject();
48 } catch (CoreException e) {
49 fail(e.getMessage());
50 }
51 }
52
53 /**
54 * Cleans up the project after tests have been executed
55 */
56 @After
57 public void cleanUp() {
58 ProjectModelTestData.deleteProject(fixture);
59 }
60
61 /**
62 * Test the getTrace() and trace opening
63 */
64 @Test
65 public void testOpenTrace() {
66 assertNotNull(fixture);
67
68 final TmfTraceElement traceElement = fixture.getTracesFolder().getTraces().get(0);
69
70 /*
71 * Get the trace from the element, it is not opened yet, should be null
72 */
73 ITmfTrace trace = traceElement.getTrace();
74 assertNull(trace);
75
76 TmfOpenTraceHelper.openTraceFromElement(traceElement);
77
78 /* Give the trace a chance to open */
79 try {
80 ProjectModelTestData.delayUntilTraceOpened(traceElement);
81 } catch (WaitTimeoutException e) {
82 fail("The trace did not open in a reasonable delay");
83 }
84
85 trace = traceElement.getTrace();
86 assertNotNull(trace);
87
88 /*
89 * Open the trace from project, then get from element, both should be
90 * the exact same element as the active trace
91 */
92 TmfOpenTraceHelper.openTraceFromElement(traceElement);
93 try {
94 ProjectModelTestData.delayUntilTraceOpened(traceElement);
95 } catch (WaitTimeoutException e) {
96 fail("The trace did not open in a reasonable delay");
97 }
98
99 ITmfTrace trace2 = TmfTraceManager.getInstance().getActiveTrace();
100
101 /* The trace was reopened, it should be the same as before */
102 assertTrue(trace2 == trace);
103
104 /* Here, the getTrace() should return the same as active trace */
105 trace = traceElement.getTrace();
106 assertTrue(trace2 == trace);
107 }
108
109 }
This page took 0.032105 seconds and 5 git commands to generate.