Commit | Line | Data |
---|---|---|
c068a752 GB |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 É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.linuxtools.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 | ||
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; | |
36 | ||
37 | /** | |
38 | * Test suite for the {@link TmfAnalysisOutputElement} class. | |
39 | * | |
40 | * @author Geneviève Bastien | |
41 | */ | |
42 | public class ProjectModelOutputTest { | |
43 | ||
44 | private TmfProjectElement fixture; | |
45 | ||
46 | /** | |
47 | * Perform pre-test initialization. | |
48 | */ | |
49 | @Before | |
50 | public void setUp() { | |
51 | try { | |
52 | fixture = ProjectModelTestData.getFilledProject(); | |
53 | } catch (CoreException e) { | |
54 | fail(e.getMessage()); | |
55 | } | |
56 | } | |
57 | ||
58 | /** | |
59 | * Cleans up the project after tests have been executed | |
60 | */ | |
61 | @After | |
62 | public void cleanUp() { | |
63 | ProjectModelTestData.deleteProject(fixture); | |
64 | } | |
65 | ||
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())) { | |
72 | trace = traceElement; | |
73 | } | |
74 | } | |
75 | } | |
76 | assertNotNull(trace); | |
77 | return trace; | |
78 | } | |
79 | ||
80 | private TmfAnalysisElement getTestAnalysisUi() { | |
81 | TmfTraceElement trace = getTraceElement(); | |
82 | ||
83 | /* Make sure the analysis list is not empty */ | |
84 | List<TmfAnalysisElement> analysisList = trace.getAvailableAnalysis(); | |
85 | assertFalse(analysisList.isEmpty()); | |
86 | ||
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; | |
92 | } | |
93 | } | |
94 | assertNotNull(analysis); | |
95 | return analysis; | |
96 | } | |
97 | ||
98 | /** | |
99 | * Test the getAvailableOutputs() method | |
100 | */ | |
101 | @Test | |
102 | public void testListOutputs() { | |
103 | TmfAnalysisElement analysis = getTestAnalysisUi(); | |
104 | ||
105 | /* To get the list of outputs the trace needs to be opened */ | |
106 | analysis.activateParent(); | |
107 | ProjectModelTestData.delayThread(500); | |
108 | ||
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")) { | |
117 | found = true; | |
118 | } | |
119 | } | |
120 | } | |
121 | assertTrue(found); | |
122 | } | |
123 | ||
124 | /** | |
125 | * Test the outputAnalysis method for a view | |
126 | */ | |
127 | @Test | |
128 | public void testOpenView() { | |
129 | TmfAnalysisElement analysis = getTestAnalysisUi(); | |
130 | ||
131 | analysis.activateParent(); | |
132 | ProjectModelTestData.delayThread(1000); | |
133 | ||
134 | List<TmfAnalysisOutputElement> outputList = analysis.getAvailableOutputs(); | |
135 | assertFalse(outputList.isEmpty()); | |
136 | ||
137 | final IWorkbench wb = PlatformUI.getWorkbench(); | |
138 | final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); | |
139 | ||
140 | IViewPart view = activePage.findView(TestAnalysisUi.VIEW_ID); | |
141 | if (view != null) { | |
142 | activePage.hideView(view); | |
143 | } | |
144 | ||
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")) { | |
150 | outputElement = el; | |
151 | } | |
152 | } | |
153 | } | |
154 | assertNotNull(outputElement); | |
155 | ||
156 | outputElement.outputAnalysis(); | |
157 | ProjectModelTestData.delayThread(1000); | |
158 | view = activePage.findView(TestAnalysisUi.VIEW_ID); | |
159 | assertNotNull(view); | |
160 | } | |
161 | } |