157b07f3375ba14cd6d3c30ef8330f67cad3ae77
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / project / model / ProjectModelOutputTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 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
13 package org.eclipse.tracecompass.tmf.ui.tests.project.model;
14
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;
19
20 import java.util.List;
21 import java.util.concurrent.TimeoutException;
22
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;
38
39 /**
40 * Test suite for the {@link TmfAnalysisOutputElement} class.
41 *
42 * @author Geneviève Bastien
43 */
44 public class ProjectModelOutputTest {
45
46 private TmfProjectElement fixture;
47
48 /**
49 * Perform pre-test initialization.
50 */
51 @Before
52 public void setUp() {
53 try {
54 fixture = ProjectModelTestData.getFilledProject();
55 } catch (CoreException e) {
56 fail(e.getMessage());
57 }
58 }
59
60 /**
61 * Cleans up the project after tests have been executed
62 */
63 @After
64 public void cleanUp() {
65 ProjectModelTestData.deleteProject(fixture);
66 }
67
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())) {
74 trace = traceElement;
75 }
76 }
77 }
78 assertNotNull(trace);
79 return trace;
80 }
81
82 private TmfAnalysisElement getTestAnalysisUi() {
83 TmfTraceElement trace = getTraceElement();
84
85 /* Make sure the analysis list is not empty */
86 List<TmfAnalysisElement> analysisList = trace.getAvailableAnalysis();
87 assertFalse(analysisList.isEmpty());
88
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;
94 }
95 }
96 assertNotNull(analysis);
97 return analysis;
98 }
99
100 /**
101 * Test the getAvailableOutputs() method
102 */
103 @Test
104 public void testListOutputs() {
105 TmfAnalysisElement analysis = getTestAnalysisUi();
106
107 /* To get the list of outputs the trace needs to be opened */
108 analysis.activateParentTrace();
109 try {
110 ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
111 } catch (TimeoutException e) {
112 fail("The analysis parent did not open in a reasonable time");
113 }
114
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")) {
123 found = true;
124 }
125 }
126 }
127 assertTrue(found);
128 }
129
130 /**
131 * Test the outputAnalysis method for a view
132 */
133 @Test
134 public void testOpenView() {
135 TmfAnalysisElement analysis = getTestAnalysisUi();
136
137 analysis.activateParentTrace();
138 try {
139 ProjectModelTestData.delayUntilTraceOpened(analysis.getParent());
140 } catch (TimeoutException e) {
141 fail("The analysis parent did not open in a reasonable time");
142 }
143
144 List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs();
145 assertFalse(outputList.isEmpty());
146
147 final IWorkbench wb = PlatformUI.getWorkbench();
148 final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage();
149
150 IViewPart view = activePage.findView(TestAnalysisUi.VIEW_ID);
151 if (view != null) {
152 activePage.hideView(view);
153 }
154
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")) {
160 outputElement = el;
161 }
162 }
163 }
164 assertNotNull(outputElement);
165
166 outputElement.outputAnalysis();
167 ProjectModelTestData.delayThread(1000);
168 view = activePage.findView(TestAnalysisUi.VIEW_ID);
169 assertNotNull(view);
170 }
171 }
This page took 0.033589 seconds and 4 git commands to generate.