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
.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 java
.util
.List
;
22 import java
.util
.Optional
;
24 import org
.eclipse
.core
.runtime
.CoreException
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfAnalysisElement
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfViewsElement
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.ProjectModelTestData
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitTimeoutException
;
33 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.stubs
.analysis
.TestAnalysisUi
;
34 import org
.junit
.After
;
35 import org
.junit
.Before
;
36 import org
.junit
.Test
;
39 * Test suite for the {@link TmfAnalysisElement} class.
41 * @author Geneviève Bastien
43 public class ProjectModelAnalysisTest
{
45 /** ID of analysis module in UI */
46 public static final String MODULE_UI
= "org.eclipse.linuxtools.tmf.ui.tests.test";
47 private TmfProjectElement fixture
;
50 * Perform pre-test initialization.
55 fixture
= ProjectModelTestData
.getFilledProject();
56 } catch (CoreException e
) {
62 * Cleans up the project after tests have been executed
65 public void cleanUp() {
66 ProjectModelTestData
.deleteProject(fixture
);
69 private TmfTraceElement
getTraceElement() {
70 TmfTraceElement trace
= null;
71 for (ITmfProjectModelElement element
: fixture
.getTracesFolder().getChildren()) {
72 if (element
instanceof TmfTraceElement
) {
73 TmfTraceElement traceElement
= (TmfTraceElement
) element
;
74 if (traceElement
.getName().equals(ProjectModelTestData
.getTraceName())) {
84 * Test the getAvailableAnalysis() method
87 public void testListAnalysis() {
88 TmfTraceElement trace
= getTraceElement();
90 /* Make sure the analysis list is not empty */
91 List
<TmfAnalysisElement
> analysisList
= trace
.getAvailableAnalysis();
92 assertFalse(analysisList
.isEmpty());
94 /* Make sure TestAnalysisUi is there */
95 TmfAnalysisElement analysis
= null;
96 for (TmfAnalysisElement analysisElement
: analysisList
) {
97 if (analysisElement
.getAnalysisId().equals(MODULE_UI
)) {
98 analysis
= analysisElement
;
101 assertNotNull(analysis
);
103 assertEquals("Test analysis in UI", analysis
.getName());
107 * Test if the list of available analysis is correctly populated by the
111 public void testPopulate() {
112 TmfTraceElement trace
= getTraceElement();
114 /* Make sure the list of views is there and not empty */
115 Optional
<TmfViewsElement
> possibleViewsElem
= trace
.getChildren()
117 .filter(child
-> child
instanceof TmfViewsElement
)
118 .map(elem
-> (TmfViewsElement
) elem
)
120 assertTrue(possibleViewsElem
.isPresent());
121 TmfViewsElement viewsElem
= possibleViewsElem
.get();
123 /* Make sure TestAnalysisUi is there */
124 Optional
<TmfAnalysisElement
> possibleAnalysisElem
= viewsElem
.getChildren().stream()
125 .filter(child
-> child
instanceof TmfAnalysisElement
)
126 .map(elem
-> (TmfAnalysisElement
) elem
)
127 .filter(analysisElem
-> analysisElem
.getAnalysisId().equals(MODULE_UI
))
129 assertTrue(possibleAnalysisElem
.isPresent());
130 assertEquals("Test analysis in UI", possibleAnalysisElem
.get().getName());
134 * Test the instantiateAnalysis method
137 public void testInstantiate() {
138 TmfTraceElement traceElement
= getTraceElement();
140 TmfAnalysisElement analysis
= traceElement
.getAvailableAnalysis().stream()
141 .filter(availableAnalysis
-> availableAnalysis
.getAnalysisId().equals(MODULE_UI
))
144 /* Instantiate an analysis on a trace that is closed */
145 traceElement
.closeEditors();
146 analysis
.activateParentTrace();
149 ProjectModelTestData
.delayUntilTraceOpened(traceElement
);
150 } catch (WaitTimeoutException e
) {
151 fail("The analysis parent did not open in a reasonable time");
153 ITmfTrace trace
= traceElement
.getTrace();
155 assertNotNull(trace
);
156 TestAnalysisUi module
= (TestAnalysisUi
) trace
.getAnalysisModule(analysis
.getAnalysisId());
157 assertNotNull(module
);