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