Commit | Line | Data |
---|---|---|
c068a752 | 1 | /******************************************************************************* |
60ae41e1 | 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.assertEquals; | |
16 | import static org.junit.Assert.assertFalse; | |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.fail; | |
c068a752 GB |
19 | |
20 | import java.util.List; | |
bc5f2035 | 21 | import java.util.concurrent.TimeoutException; |
c068a752 GB |
22 | |
23 | import org.eclipse.core.runtime.CoreException; | |
2bdf0193 AM |
24 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; |
25 | import org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement; | |
26 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement; | |
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; | |
c068a752 GB |
31 | import org.junit.After; |
32 | import org.junit.Before; | |
33 | import org.junit.Test; | |
34 | ||
35 | /** | |
36 | * Test suite for the {@link TmfAnalysisElement} class. | |
37 | * | |
38 | * @author Geneviève Bastien | |
39 | */ | |
40 | public class ProjectModelAnalysisTest { | |
41 | ||
42 | /** ID of analysis module in UI */ | |
43 | public static final String MODULE_UI = "org.eclipse.linuxtools.tmf.ui.tests.test"; | |
44 | private TmfProjectElement fixture; | |
45 | ||
46 | /** | |
47 | * Perform pre-test initialization. | |
48 | */ | |
49 | @Before | |
50 | public void setUp() { | |
c068a752 GB |
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 | /** | |
81 | * Test the getAvailableAnalysis() method | |
82 | */ | |
83 | @Test | |
84 | public void testListAnalysis() { | |
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(MODULE_UI)) { | |
95 | analysis = analysisElement; | |
96 | } | |
97 | } | |
98 | assertNotNull(analysis); | |
99 | ||
100 | assertEquals("Test analysis in UI", analysis.getName()); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Test if the list of available analysis is correctly populated by the | |
105 | * content provider | |
106 | */ | |
107 | @Test | |
108 | public void testPopulate() { | |
109 | TmfTraceElement trace = getTraceElement(); | |
110 | ||
c068a752 GB |
111 | /* Make sure the analysis list is not empty */ |
112 | List<ITmfProjectModelElement> analysisList = trace.getChildren(); | |
113 | assertFalse(analysisList.isEmpty()); | |
114 | ||
115 | /* Make sure TestAnalysisUi is there */ | |
116 | TmfAnalysisElement analysis = null; | |
117 | for (ITmfProjectModelElement element : analysisList) { | |
118 | if (element instanceof TmfAnalysisElement) { | |
119 | TmfAnalysisElement analysisElement = (TmfAnalysisElement) element; | |
120 | if (analysisElement.getAnalysisId().equals(MODULE_UI)) { | |
121 | analysis = analysisElement; | |
122 | } | |
123 | } | |
124 | } | |
125 | assertNotNull(analysis); | |
126 | ||
127 | assertEquals("Test analysis in UI", analysis.getName()); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Test the instantiateAnalysis method | |
132 | */ | |
133 | @Test | |
134 | public void testInstantiate() { | |
135 | TmfTraceElement traceElement = getTraceElement(); | |
136 | ||
137 | TmfAnalysisElement analysis = null; | |
138 | for (TmfAnalysisElement analysisElement : traceElement.getAvailableAnalysis()) { | |
139 | if (analysisElement.getAnalysisId().equals(MODULE_UI)) { | |
140 | analysis = analysisElement; | |
141 | } | |
142 | } | |
143 | assertNotNull(analysis); | |
144 | ||
145 | /* Instantiate an analysis on a trace that is closed */ | |
146 | traceElement.closeEditors(); | |
147 | analysis.activateParent(); | |
148 | ||
bc5f2035 GB |
149 | try { |
150 | ProjectModelTestData.delayUntilTraceOpened(traceElement); | |
151 | } catch (TimeoutException e) { | |
152 | fail("The analysis parent did not open in a reasonable time"); | |
eb130160 | 153 | } |
bc5f2035 | 154 | ITmfTrace trace = traceElement.getTrace(); |
c068a752 | 155 | |
c068a752 GB |
156 | assertNotNull(trace); |
157 | TestAnalysisUi module = (TestAnalysisUi) trace.getAnalysisModule(analysis.getAnalysisId()); | |
158 | assertNotNull(module); | |
159 | ||
160 | } | |
161 | } |