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 / TraceAndExperimentTypeTest.java
1 /*******************************************************************************
2 * Copyright (c) 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.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
24 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
25 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
26 import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
27 import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub;
28 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
29 import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
30 import org.eclipse.tracecompass.tmf.ui.project.model.TmfOpenTraceHelper;
31 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
32 import org.eclipse.tracecompass.tmf.ui.tests.experiment.type.TmfEventsEditorStub;
33 import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
34 import org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable;
35 import org.eclipse.ui.IEditorPart;
36 import org.eclipse.ui.IWorkbench;
37 import org.eclipse.ui.IWorkbenchPage;
38 import org.eclipse.ui.PlatformUI;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42
43 /**
44 * Some unit tests for trace types and experiment types
45 *
46 * @author Geneviève Bastien
47 */
48 public class TraceAndExperimentTypeTest {
49
50 /** Test experiment type id */
51 public final static String TEST_EXPERIMENT_TYPE = "org.eclipse.linuxtools.tmf.core.tests.experimenttype";
52
53 private TmfProjectElement fixture;
54 private TmfExperimentElement fExperiment;
55 private final String EXPERIMENT_NAME = "exp_test";
56
57 /**
58 * Perform pre-test initialization.
59 */
60 @Before
61 public void setUp() {
62 try {
63 fixture = ProjectModelTestData.getFilledProject();
64 fExperiment = ProjectModelTestData.addExperiment(fixture, EXPERIMENT_NAME);
65 assertNotNull(fExperiment);
66 } catch (CoreException e) {
67 fail(e.getMessage());
68 }
69 }
70
71 /**
72 * Cleans up the project after tests have been executed
73 */
74 @After
75 public void cleanUp() {
76 ProjectModelTestData.deleteProject(fixture);
77 }
78
79 /**
80 * Test whether a newly created experiment has the default experiment type,
81 * even though none was specified
82 */
83 @Test
84 public void testDefaultExperimentType() {
85 TmfExperimentElement experimentElement = ProjectModelTestData.addExperiment(fixture, "testDefaultExpType");
86 assertNotNull(experimentElement);
87 TmfExperiment experiment = experimentElement.instantiateTrace();
88 assertNotNull(experiment);
89 assertEquals(TmfTraceType.DEFAULT_EXPERIMENT_TYPE, experimentElement.getTraceType());
90 }
91
92 /**
93 * Test that the experiment opened is of the right class
94 */
95 @Test
96 public void testExperimentType() {
97
98 IResource resource = fExperiment.getResource();
99 try {
100 resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, TEST_EXPERIMENT_TYPE);
101 fExperiment.refreshTraceType();
102 } catch (CoreException e) {
103 fail(e.getMessage());
104 }
105
106 TmfOpenTraceHelper.openTraceFromElement(fExperiment);
107 ProjectModelTestData.delayUntilTraceOpened(fExperiment);
108
109 ITmfTrace trace = fExperiment.getTrace();
110 assertTrue(trace instanceof TmfExperimentStub);
111 }
112
113 /**
114 * Test that event editor, event table and statistics viewer are the default
115 * ones for a generic experiment
116 */
117 @Test
118 public void testNoExperimentTypeChildren() {
119 TmfOpenTraceHelper.openTraceFromElement(fExperiment);
120
121 ProjectModelTestData.delayUntilTraceOpened(fExperiment);
122
123 final IWorkbench wb = PlatformUI.getWorkbench();
124 final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
125 IEditorPart editor = activePage.getActiveEditor();
126
127 /* Test the editor class. Cannot test table class since it is unexposed */
128 assertNotNull(editor);
129 assertTrue(editor.getClass().equals(TmfEventsEditor.class));
130 }
131
132 /**
133 * Test that event editor, event table and statistics viewer are built
134 * correctly when specified
135 */
136 @Test
137 public void testExperimentTypeChildren() {
138
139 /* Set the trace type of the experiment */
140 IResource resource = fExperiment.getResource();
141 try {
142 resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, TEST_EXPERIMENT_TYPE);
143 fExperiment.refreshTraceType();
144 } catch (CoreException e) {
145 fail(e.getMessage());
146 }
147
148 TmfOpenTraceHelper.openTraceFromElement(fExperiment);
149
150 ProjectModelTestData.delayThread(500);
151
152 /* Test the editor class */
153 final IWorkbench wb = PlatformUI.getWorkbench();
154 final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
155 IEditorPart editor = activePage.getActiveEditor();
156
157 assertNotNull(editor);
158 assertTrue(editor.getClass().equals(TmfEventsEditorStub.class));
159
160 /* Test the event table class */
161 TmfEventsEditorStub editorStub = (TmfEventsEditorStub) editor;
162 TmfEventsTable table = editorStub.getNewEventsTable();
163
164 assertNotNull(table);
165 assertTrue(table.getClass().equals(TmfEventsTable.class));
166
167 }
168
169 /**
170 * Test that the analysis get populated under an experiment of the proper type
171 */
172 @Test
173 public void testExperimentTypeAnalysis() {
174
175 /* Set the trace type of the experiment */
176 IResource resource = fExperiment.getResource();
177 try {
178 resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, TEST_EXPERIMENT_TYPE);
179 fExperiment.refreshTraceType();
180 } catch (CoreException e) {
181 fail(e.getMessage());
182 }
183
184 /* Force the refresh of the experiment */
185 fExperiment.getParent().refresh();
186 assertFalse(fExperiment.getAvailableAnalysis().isEmpty());
187 }
188
189 }
This page took 0.035299 seconds and 5 git commands to generate.