Commit | Line | Data |
---|---|---|
c068a752 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
c068a752 GB |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.tests.project.model; |
c068a752 GB |
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 | ||
22 | import org.eclipse.core.runtime.CoreException; | |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement; |
24 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement; | |
25 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisOutputElement; | |
26 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
27 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
6db82092 | 28 | import org.eclipse.tracecompass.tmf.ui.tests.shared.IWaitCondition; |
2bdf0193 | 29 | import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData; |
6db82092 MAL |
30 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException; |
31 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; | |
2bdf0193 | 32 | import org.eclipse.tracecompass.tmf.ui.tests.stubs.analysis.TestAnalysisUi; |
c068a752 GB |
33 | import org.eclipse.ui.IViewPart; |
34 | import org.eclipse.ui.IWorkbench; | |
35 | import org.eclipse.ui.IWorkbenchPage; | |
36 | import org.eclipse.ui.PlatformUI; | |
37 | import org.junit.After; | |
38 | import org.junit.Before; | |
39 | import org.junit.Test; | |
40 | ||
41 | /** | |
42 | * Test suite for the {@link TmfAnalysisOutputElement} class. | |
43 | * | |
44 | * @author Geneviève Bastien | |
45 | */ | |
46 | public class ProjectModelOutputTest { | |
47 | ||
48 | private TmfProjectElement fixture; | |
49 | ||
50 | /** | |
51 | * Perform pre-test initialization. | |
52 | */ | |
53 | @Before | |
54 | public void setUp() { | |
55 | try { | |
56 | fixture = ProjectModelTestData.getFilledProject(); | |
57 | } catch (CoreException e) { | |
58 | fail(e.getMessage()); | |
59 | } | |
60 | } | |
61 | ||
62 | /** | |
63 | * Cleans up the project after tests have been executed | |
64 | */ | |
65 | @After | |
66 | public void cleanUp() { | |
67 | ProjectModelTestData.deleteProject(fixture); | |
68 | } | |
69 | ||
70 | private TmfTraceElement getTraceElement() { | |
71 | TmfTraceElement trace = null; | |
72 | for (ITmfProjectModelElement element : fixture.getTracesFolder().getChildren()) { | |
73 | if (element instanceof TmfTraceElement) { | |
74 | TmfTraceElement traceElement = (TmfTraceElement) element; | |
75 | if (traceElement.getName().equals(ProjectModelTestData.getTraceName())) { | |
76 | trace = traceElement; | |
77 | } | |
78 | } | |
79 | } | |
80 | assertNotNull(trace); | |
81 | return trace; | |
82 | } | |
83 | ||
84 | private TmfAnalysisElement getTestAnalysisUi() { | |
85 | TmfTraceElement trace = getTraceElement(); | |
86 | ||
87 | /* Make sure the analysis list is not empty */ | |
88 | List<TmfAnalysisElement> analysisList = trace.getAvailableAnalysis(); | |
89 | assertFalse(analysisList.isEmpty()); | |
90 | ||
91 | /* Make sure TestAnalysisUi is there */ | |
92 | TmfAnalysisElement analysis = null; | |
93 | for (TmfAnalysisElement analysisElement : analysisList) { | |
94 | if (analysisElement.getAnalysisId().equals(ProjectModelAnalysisTest.MODULE_UI)) { | |
95 | analysis = analysisElement; | |
96 | } | |
97 | } | |
98 | assertNotNull(analysis); | |
99 | return analysis; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Test the getAvailableOutputs() method | |
104 | */ | |
105 | @Test | |
106 | public void testListOutputs() { | |
107 | TmfAnalysisElement analysis = getTestAnalysisUi(); | |
108 | ||
109 | /* To get the list of outputs the trace needs to be opened */ | |
5c727157 | 110 | analysis.activateParentTrace(); |
bc5f2035 GB |
111 | try { |
112 | ProjectModelTestData.delayUntilTraceOpened(analysis.getParent()); | |
6db82092 | 113 | } catch (WaitTimeoutException e) { |
bc5f2035 GB |
114 | fail("The analysis parent did not open in a reasonable time"); |
115 | } | |
c068a752 GB |
116 | |
117 | /* Make sure the output list is not empty */ | |
6db82092 | 118 | WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1)); |
c068a752 GB |
119 | List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs(); |
120 | assertFalse(outputList.isEmpty()); | |
121 | boolean found = false; | |
122 | for (ITmfProjectModelElement element : outputList) { | |
123 | if (element instanceof TmfAnalysisOutputElement) { | |
124 | TmfAnalysisOutputElement outputElement = (TmfAnalysisOutputElement) element; | |
125 | if (outputElement.getName().equals("Test Analysis View")) { | |
126 | found = true; | |
127 | } | |
128 | } | |
129 | } | |
130 | assertTrue(found); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Test the outputAnalysis method for a view | |
135 | */ | |
136 | @Test | |
137 | public void testOpenView() { | |
138 | TmfAnalysisElement analysis = getTestAnalysisUi(); | |
139 | ||
5c727157 | 140 | analysis.activateParentTrace(); |
bc5f2035 GB |
141 | try { |
142 | ProjectModelTestData.delayUntilTraceOpened(analysis.getParent()); | |
6db82092 | 143 | } catch (WaitTimeoutException e) { |
bc5f2035 GB |
144 | fail("The analysis parent did not open in a reasonable time"); |
145 | } | |
c068a752 | 146 | |
6db82092 | 147 | WaitUtils.waitUntil(new ConditionTraceChildrenElements(analysis, 1)); |
c068a752 GB |
148 | List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs(); |
149 | assertFalse(outputList.isEmpty()); | |
150 | ||
151 | final IWorkbench wb = PlatformUI.getWorkbench(); | |
152 | final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); | |
153 | ||
154 | IViewPart view = activePage.findView(TestAnalysisUi.VIEW_ID); | |
155 | if (view != null) { | |
156 | activePage.hideView(view); | |
157 | } | |
158 | ||
159 | TmfAnalysisOutputElement outputElement = null; | |
160 | for (ITmfProjectModelElement element : outputList) { | |
161 | if (element instanceof TmfAnalysisOutputElement) { | |
162 | TmfAnalysisOutputElement el = (TmfAnalysisOutputElement) element; | |
163 | if (el.getName().equals("Test Analysis View")) { | |
164 | outputElement = el; | |
165 | } | |
166 | } | |
167 | } | |
168 | assertNotNull(outputElement); | |
169 | ||
170 | outputElement.outputAnalysis(); | |
171 | ProjectModelTestData.delayThread(1000); | |
172 | view = activePage.findView(TestAnalysisUi.VIEW_ID); | |
173 | assertNotNull(view); | |
174 | } | |
6db82092 MAL |
175 | |
176 | private static final class ConditionTraceChildrenElements implements IWaitCondition { | |
177 | private final ITmfProjectModelElement fProjectElement; | |
178 | private int fCurNumChildren; | |
179 | private int fExpectedChildNum; | |
180 | ||
181 | private ConditionTraceChildrenElements(ITmfProjectModelElement projectElement, int childNum) { | |
182 | fProjectElement = projectElement; | |
183 | fExpectedChildNum = childNum; | |
184 | } | |
185 | ||
186 | @Override | |
187 | public boolean test() throws Exception { | |
188 | fCurNumChildren = fProjectElement.getChildren().size(); | |
189 | return fCurNumChildren == fExpectedChildNum; | |
190 | } | |
191 | ||
192 | @Override | |
193 | public String getFailureMessage() { | |
194 | return "Timeout while waiting for " + fProjectElement + " to have number of children. Expected: " + fExpectedChildNum + " Actual: " + fCurNumChildren; | |
195 | } | |
196 | } | |
c068a752 | 197 | } |