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