1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.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
;
22 import org
.eclipse
.core
.runtime
.CoreException
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.ITmfProjectModelElement
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfAnalysisElement
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfAnalysisOutputElement
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfProjectElement
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.stubs
.analysis
.TestAnalysisUi
;
29 import org
.eclipse
.ui
.IViewPart
;
30 import org
.eclipse
.ui
.IWorkbench
;
31 import org
.eclipse
.ui
.IWorkbenchPage
;
32 import org
.eclipse
.ui
.PlatformUI
;
33 import org
.junit
.After
;
34 import org
.junit
.Before
;
35 import org
.junit
.Test
;
38 * Test suite for the {@link TmfAnalysisOutputElement} class.
40 * @author Geneviève Bastien
42 public class ProjectModelOutputTest
{
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())) {
80 private TmfAnalysisElement
getTestAnalysisUi() {
81 TmfTraceElement trace
= getTraceElement();
83 /* Make sure the analysis list is not empty */
84 List
<TmfAnalysisElement
> analysisList
= trace
.getAvailableAnalysis();
85 assertFalse(analysisList
.isEmpty());
87 /* Make sure TestAnalysisUi is there */
88 TmfAnalysisElement analysis
= null;
89 for (TmfAnalysisElement analysisElement
: analysisList
) {
90 if (analysisElement
.getAnalysisId().equals(ProjectModelAnalysisTest
.MODULE_UI
)) {
91 analysis
= analysisElement
;
94 assertNotNull(analysis
);
99 * Test the getAvailableOutputs() method
102 public void testListOutputs() {
103 TmfAnalysisElement analysis
= getTestAnalysisUi();
105 /* To get the list of outputs the trace needs to be opened */
106 analysis
.activateParent();
107 ProjectModelTestData
.delayThread(500);
109 /* Make sure the output list is not empty */
110 List
<TmfAnalysisOutputElement
> outputList
= analysis
.getAvailableOutputs();
111 assertFalse(outputList
.isEmpty());
112 boolean found
= false;
113 for (ITmfProjectModelElement element
: outputList
) {
114 if (element
instanceof TmfAnalysisOutputElement
) {
115 TmfAnalysisOutputElement outputElement
= (TmfAnalysisOutputElement
) element
;
116 if (outputElement
.getName().equals("Test Analysis View")) {
125 * Test the outputAnalysis method for a view
128 public void testOpenView() {
129 TmfAnalysisElement analysis
= getTestAnalysisUi();
131 analysis
.activateParent();
132 ProjectModelTestData
.delayThread(1000);
134 List
<TmfAnalysisOutputElement
> outputList
= analysis
.getAvailableOutputs();
135 assertFalse(outputList
.isEmpty());
137 final IWorkbench wb
= PlatformUI
.getWorkbench();
138 final IWorkbenchPage activePage
= wb
.getActiveWorkbenchWindow().getActivePage();
140 IViewPart view
= activePage
.findView(TestAnalysisUi
.VIEW_ID
);
142 activePage
.hideView(view
);
145 TmfAnalysisOutputElement outputElement
= null;
146 for (ITmfProjectModelElement element
: outputList
) {
147 if (element
instanceof TmfAnalysisOutputElement
) {
148 TmfAnalysisOutputElement el
= (TmfAnalysisOutputElement
) element
;
149 if (el
.getName().equals("Test Analysis View")) {
154 assertNotNull(outputElement
);
156 outputElement
.outputAnalysis();
157 ProjectModelTestData
.delayThread(1000);
158 view
= activePage
.findView(TestAnalysisUi
.VIEW_ID
);