1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.tests
.project
.model
;
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
;
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
;
44 * Some unit tests for trace types and experiment types
46 * @author Geneviève Bastien
48 public class TraceAndExperimentTypeTest
{
50 /** Test experiment type id */
51 public final static String TEST_EXPERIMENT_TYPE
= "org.eclipse.linuxtools.tmf.core.tests.experimenttype";
53 private TmfProjectElement fixture
;
54 private TmfExperimentElement fExperiment
;
55 private final String EXPERIMENT_NAME
= "exp_test";
58 * Perform pre-test initialization.
63 fixture
= ProjectModelTestData
.getFilledProject();
64 fExperiment
= ProjectModelTestData
.addExperiment(fixture
, EXPERIMENT_NAME
);
65 assertNotNull(fExperiment
);
66 } catch (CoreException e
) {
72 * Cleans up the project after tests have been executed
75 public void cleanUp() {
76 ProjectModelTestData
.deleteProject(fixture
);
80 * Test whether a newly created experiment has the default experiment type,
81 * even though none was specified
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());
93 * Test that the experiment opened is of the right class
96 public void testExperimentType() {
98 IResource resource
= fExperiment
.getResource();
100 resource
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TEST_EXPERIMENT_TYPE
);
101 fExperiment
.refreshTraceType();
102 } catch (CoreException e
) {
103 fail(e
.getMessage());
106 TmfOpenTraceHelper
.openTraceFromElement(fExperiment
);
107 ProjectModelTestData
.delayUntilTraceOpened(fExperiment
);
109 ITmfTrace trace
= fExperiment
.getTrace();
110 assertTrue(trace
instanceof TmfExperimentStub
);
114 * Test that event editor, event table and statistics viewer are the default
115 * ones for a generic experiment
118 public void testNoExperimentTypeChildren() {
119 TmfOpenTraceHelper
.openTraceFromElement(fExperiment
);
121 ProjectModelTestData
.delayUntilTraceOpened(fExperiment
);
123 final IWorkbench wb
= PlatformUI
.getWorkbench();
124 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
125 IEditorPart editor
= activePage
.getActiveEditor();
127 /* Test the editor class. Cannot test table class since it is unexposed */
128 assertNotNull(editor
);
129 assertTrue(editor
.getClass().equals(TmfEventsEditor
.class));
133 * Test that event editor, event table and statistics viewer are built
134 * correctly when specified
137 public void testExperimentTypeChildren() {
139 /* Set the trace type of the experiment */
140 IResource resource
= fExperiment
.getResource();
142 resource
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TEST_EXPERIMENT_TYPE
);
143 fExperiment
.refreshTraceType();
144 } catch (CoreException e
) {
145 fail(e
.getMessage());
148 TmfOpenTraceHelper
.openTraceFromElement(fExperiment
);
150 ProjectModelTestData
.delayThread(500);
152 /* Test the editor class */
153 final IWorkbench wb
= PlatformUI
.getWorkbench();
154 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
155 IEditorPart editor
= activePage
.getActiveEditor();
157 assertNotNull(editor
);
158 assertTrue(editor
.getClass().equals(TmfEventsEditorStub
.class));
160 /* Test the event table class */
161 TmfEventsEditorStub editorStub
= (TmfEventsEditorStub
) editor
;
162 TmfEventsTable table
= editorStub
.getNewEventsTable();
164 assertNotNull(table
);
165 assertTrue(table
.getClass().equals(TmfEventsTable
.class));
170 * Test that the analysis get populated under an experiment of the proper type
173 public void testExperimentTypeAnalysis() {
175 /* Set the trace type of the experiment */
176 IResource resource
= fExperiment
.getResource();
178 resource
.setPersistentProperty(TmfCommonConstants
.TRACETYPE
, TEST_EXPERIMENT_TYPE
);
179 fExperiment
.refreshTraceType();
180 } catch (CoreException e
) {
181 fail(e
.getMessage());
184 /* Force the refresh of the experiment */
185 fExperiment
.getParent().refresh();
186 assertFalse(fExperiment
.getAvailableAnalysis().isEmpty());