1 /*******************************************************************************
2 * Copyright (c) 2013, 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
.linuxtools
.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
.fail
;
20 import java
.util
.List
;
21 import java
.util
.concurrent
.TimeoutException
;
23 import org
.eclipse
.core
.runtime
.CoreException
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfAnalysisElement
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectElement
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.shared
.ProjectModelTestData
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.stubs
.analysis
.TestAnalysisUi
;
31 import org
.junit
.After
;
32 import org
.junit
.Before
;
33 import org
.junit
.Test
;
36 * Test suite for the {@link TmfAnalysisElement} class.
38 * @author Geneviève Bastien
40 public class ProjectModelAnalysisTest
{
42 /** ID of analysis module in UI */
43 public static final String MODULE_UI
= "org.eclipse.linuxtools.tmf.ui.tests.test";
44 private TmfProjectElement fixture
;
47 * Perform pre-test initialization.
52 fixture
= ProjectModelTestData
.getFilledProject();
53 } catch (CoreException e
) {
59 * Cleans up the project after tests have been executed
62 public void cleanUp() {
63 ProjectModelTestData
.deleteProject(fixture
);
66 private TmfTraceElement
getTraceElement() {
67 TmfTraceElement trace
= null;
68 for (ITmfProjectModelElement element
: fixture
.getTracesFolder().getChildren()) {
69 if (element
instanceof TmfTraceElement
) {
70 TmfTraceElement traceElement
= (TmfTraceElement
) element
;
71 if (traceElement
.getName().equals(ProjectModelTestData
.getTraceName())) {
81 * Test the getAvailableAnalysis() method
84 public void testListAnalysis() {
85 TmfTraceElement trace
= getTraceElement();
87 /* Make sure the analysis list is not empty */
88 List
<TmfAnalysisElement
> analysisList
= trace
.getAvailableAnalysis();
89 assertFalse(analysisList
.isEmpty());
91 /* Make sure TestAnalysisUi is there */
92 TmfAnalysisElement analysis
= null;
93 for (TmfAnalysisElement analysisElement
: analysisList
) {
94 if (analysisElement
.getAnalysisId().equals(MODULE_UI
)) {
95 analysis
= analysisElement
;
98 assertNotNull(analysis
);
100 assertEquals("Test analysis in UI", analysis
.getName());
104 * Test if the list of available analysis is correctly populated by the
108 public void testPopulate() {
109 TmfTraceElement trace
= getTraceElement();
111 /* Make sure the analysis list is not empty */
112 List
<ITmfProjectModelElement
> analysisList
= trace
.getChildren();
113 assertFalse(analysisList
.isEmpty());
115 /* Make sure TestAnalysisUi is there */
116 TmfAnalysisElement analysis
= null;
117 for (ITmfProjectModelElement element
: analysisList
) {
118 if (element
instanceof TmfAnalysisElement
) {
119 TmfAnalysisElement analysisElement
= (TmfAnalysisElement
) element
;
120 if (analysisElement
.getAnalysisId().equals(MODULE_UI
)) {
121 analysis
= analysisElement
;
125 assertNotNull(analysis
);
127 assertEquals("Test analysis in UI", analysis
.getName());
131 * Test the instantiateAnalysis method
134 public void testInstantiate() {
135 TmfTraceElement traceElement
= getTraceElement();
137 TmfAnalysisElement analysis
= null;
138 for (TmfAnalysisElement analysisElement
: traceElement
.getAvailableAnalysis()) {
139 if (analysisElement
.getAnalysisId().equals(MODULE_UI
)) {
140 analysis
= analysisElement
;
143 assertNotNull(analysis
);
145 /* Instantiate an analysis on a trace that is closed */
146 traceElement
.closeEditors();
147 analysis
.activateParent();
150 ProjectModelTestData
.delayUntilTraceOpened(traceElement
);
151 } catch (TimeoutException e
) {
152 fail("The analysis parent did not open in a reasonable time");
154 ITmfTrace trace
= traceElement
.getTrace();
156 assertNotNull(trace
);
157 TestAnalysisUi module
= (TestAnalysisUi
) trace
.getAnalysisModule(analysis
.getAnalysisId());
158 assertNotNull(module
);