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
.assertFalse
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assert
.assertTrue
;
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
.tracecompass
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfAnalysisElement
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfAnalysisOutputElement
;
27 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
28 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.ProjectModelTestData
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.stubs
.analysis
.TestAnalysisUi
;
31 import org
.eclipse
.ui
.IViewPart
;
32 import org
.eclipse
.ui
.IWorkbench
;
33 import org
.eclipse
.ui
.IWorkbenchPage
;
34 import org
.eclipse
.ui
.PlatformUI
;
35 import org
.junit
.After
;
36 import org
.junit
.Before
;
37 import org
.junit
.Test
;
40 * Test suite for the {@link TmfAnalysisOutputElement} class.
42 * @author Geneviève Bastien
44 public class ProjectModelOutputTest
{
46 private TmfProjectElement fixture
;
49 * Perform pre-test initialization.
54 fixture
= ProjectModelTestData
.getFilledProject();
55 } catch (CoreException e
) {
61 * Cleans up the project after tests have been executed
64 public void cleanUp() {
65 ProjectModelTestData
.deleteProject(fixture
);
68 private TmfTraceElement
getTraceElement() {
69 TmfTraceElement trace
= null;
70 for (ITmfProjectModelElement element
: fixture
.getTracesFolder().getChildren()) {
71 if (element
instanceof TmfTraceElement
) {
72 TmfTraceElement traceElement
= (TmfTraceElement
) element
;
73 if (traceElement
.getName().equals(ProjectModelTestData
.getTraceName())) {
82 private TmfAnalysisElement
getTestAnalysisUi() {
83 TmfTraceElement trace
= getTraceElement();
85 /* Make sure the analysis list is not empty */
86 List
<TmfAnalysisElement
> analysisList
= trace
.getAvailableAnalysis();
87 assertFalse(analysisList
.isEmpty());
89 /* Make sure TestAnalysisUi is there */
90 TmfAnalysisElement analysis
= null;
91 for (TmfAnalysisElement analysisElement
: analysisList
) {
92 if (analysisElement
.getAnalysisId().equals(ProjectModelAnalysisTest
.MODULE_UI
)) {
93 analysis
= analysisElement
;
96 assertNotNull(analysis
);
101 * Test the getAvailableOutputs() method
104 public void testListOutputs() {
105 TmfAnalysisElement analysis
= getTestAnalysisUi();
107 /* To get the list of outputs the trace needs to be opened */
108 analysis
.activateParent();
110 ProjectModelTestData
.delayUntilTraceOpened(analysis
.getParent());
111 } catch (TimeoutException e
) {
112 fail("The analysis parent did not open in a reasonable time");
115 /* Make sure the output list is not empty */
116 List
<TmfAnalysisOutputElement
> outputList
= analysis
.getAvailableOutputs();
117 assertFalse(outputList
.isEmpty());
118 boolean found
= false;
119 for (ITmfProjectModelElement element
: outputList
) {
120 if (element
instanceof TmfAnalysisOutputElement
) {
121 TmfAnalysisOutputElement outputElement
= (TmfAnalysisOutputElement
) element
;
122 if (outputElement
.getName().equals("Test Analysis View")) {
131 * Test the outputAnalysis method for a view
134 public void testOpenView() {
135 TmfAnalysisElement analysis
= getTestAnalysisUi();
137 analysis
.activateParent();
139 ProjectModelTestData
.delayUntilTraceOpened(analysis
.getParent());
140 } catch (TimeoutException e
) {
141 fail("The analysis parent did not open in a reasonable time");
144 List
<TmfAnalysisOutputElement
> outputList
= analysis
.getAvailableOutputs();
145 assertFalse(outputList
.isEmpty());
147 final IWorkbench wb
= PlatformUI
.getWorkbench();
148 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
150 IViewPart view
= activePage
.findView(TestAnalysisUi
.VIEW_ID
);
152 activePage
.hideView(view
);
155 TmfAnalysisOutputElement outputElement
= null;
156 for (ITmfProjectModelElement element
: outputList
) {
157 if (element
instanceof TmfAnalysisOutputElement
) {
158 TmfAnalysisOutputElement el
= (TmfAnalysisOutputElement
) element
;
159 if (el
.getName().equals("Test Analysis View")) {
164 assertNotNull(outputElement
);
166 outputElement
.outputAnalysis();
167 ProjectModelTestData
.delayThread(1000);
168 view
= activePage
.findView(TestAnalysisUi
.VIEW_ID
);