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.assertEquals; | |
16 | import static org.junit.Assert.assertFalse; | |
17 | import static org.junit.Assert.assertNotNull; | |
18 | import static org.junit.Assert.fail; | |
19 | import static org.junit.Assume.assumeTrue; | |
20 | ||
21 | import java.util.List; | |
bc5f2035 | 22 | import java.util.concurrent.TimeoutException; |
c068a752 GB |
23 | |
24 | import org.eclipse.core.runtime.CoreException; | |
25 | import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTrace; | |
26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
27 | import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; | |
28 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfAnalysisElement; | |
c068a752 GB |
29 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; |
30 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; | |
3d2e4ad3 | 31 | import org.eclipse.linuxtools.tmf.ui.tests.shared.ProjectModelTestData; |
c068a752 GB |
32 | import org.eclipse.linuxtools.tmf.ui.tests.stubs.analysis.TestAnalysisUi; |
33 | import org.junit.After; | |
34 | import org.junit.Before; | |
35 | import org.junit.Test; | |
36 | ||
37 | /** | |
38 | * Test suite for the {@link TmfAnalysisElement} class. | |
39 | * | |
40 | * @author Geneviève Bastien | |
41 | */ | |
42 | public class ProjectModelAnalysisTest { | |
43 | ||
44 | /** ID of analysis module in UI */ | |
45 | public static final String MODULE_UI = "org.eclipse.linuxtools.tmf.ui.tests.test"; | |
46 | private TmfProjectElement fixture; | |
47 | ||
48 | /** | |
49 | * Perform pre-test initialization. | |
50 | */ | |
51 | @Before | |
52 | public void setUp() { | |
53 | assumeTrue(CtfTmfTestTrace.KERNEL.exists()); | |
54 | try { | |
55 | fixture = ProjectModelTestData.getFilledProject(); | |
56 | } catch (CoreException e) { | |
57 | fail(e.getMessage()); | |
58 | } | |
59 | } | |
60 | ||
61 | /** | |
62 | * Cleans up the project after tests have been executed | |
63 | */ | |
64 | @After | |
65 | public void cleanUp() { | |
66 | ProjectModelTestData.deleteProject(fixture); | |
67 | } | |
68 | ||
69 | private TmfTraceElement getTraceElement() { | |
70 | TmfTraceElement trace = null; | |
71 | for (ITmfProjectModelElement element : fixture.getTracesFolder().getChildren()) { | |
72 | if (element instanceof TmfTraceElement) { | |
73 | TmfTraceElement traceElement = (TmfTraceElement) element; | |
74 | if (traceElement.getName().equals(ProjectModelTestData.getTraceName())) { | |
75 | trace = traceElement; | |
76 | } | |
77 | } | |
78 | } | |
79 | assertNotNull(trace); | |
80 | return trace; | |
81 | } | |
82 | ||
83 | /** | |
84 | * Test the getAvailableAnalysis() method | |
85 | */ | |
86 | @Test | |
87 | public void testListAnalysis() { | |
88 | TmfTraceElement trace = getTraceElement(); | |
89 | ||
90 | /* Make sure the analysis list is not empty */ | |
91 | List<TmfAnalysisElement> analysisList = trace.getAvailableAnalysis(); | |
92 | assertFalse(analysisList.isEmpty()); | |
93 | ||
94 | /* Make sure TestAnalysisUi is there */ | |
95 | TmfAnalysisElement analysis = null; | |
96 | for (TmfAnalysisElement analysisElement : analysisList) { | |
97 | if (analysisElement.getAnalysisId().equals(MODULE_UI)) { | |
98 | analysis = analysisElement; | |
99 | } | |
100 | } | |
101 | assertNotNull(analysis); | |
102 | ||
103 | assertEquals("Test analysis in UI", analysis.getName()); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Test if the list of available analysis is correctly populated by the | |
108 | * content provider | |
109 | */ | |
110 | @Test | |
111 | public void testPopulate() { | |
112 | TmfTraceElement trace = getTraceElement(); | |
113 | ||
c068a752 GB |
114 | /* Make sure the analysis list is not empty */ |
115 | List<ITmfProjectModelElement> analysisList = trace.getChildren(); | |
116 | assertFalse(analysisList.isEmpty()); | |
117 | ||
118 | /* Make sure TestAnalysisUi is there */ | |
119 | TmfAnalysisElement analysis = null; | |
120 | for (ITmfProjectModelElement element : analysisList) { | |
121 | if (element instanceof TmfAnalysisElement) { | |
122 | TmfAnalysisElement analysisElement = (TmfAnalysisElement) element; | |
123 | if (analysisElement.getAnalysisId().equals(MODULE_UI)) { | |
124 | analysis = analysisElement; | |
125 | } | |
126 | } | |
127 | } | |
128 | assertNotNull(analysis); | |
129 | ||
130 | assertEquals("Test analysis in UI", analysis.getName()); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Test the instantiateAnalysis method | |
135 | */ | |
136 | @Test | |
137 | public void testInstantiate() { | |
138 | TmfTraceElement traceElement = getTraceElement(); | |
139 | ||
140 | TmfAnalysisElement analysis = null; | |
141 | for (TmfAnalysisElement analysisElement : traceElement.getAvailableAnalysis()) { | |
142 | if (analysisElement.getAnalysisId().equals(MODULE_UI)) { | |
143 | analysis = analysisElement; | |
144 | } | |
145 | } | |
146 | assertNotNull(analysis); | |
147 | ||
148 | /* Instantiate an analysis on a trace that is closed */ | |
149 | traceElement.closeEditors(); | |
150 | analysis.activateParent(); | |
151 | ||
bc5f2035 GB |
152 | try { |
153 | ProjectModelTestData.delayUntilTraceOpened(traceElement); | |
154 | } catch (TimeoutException e) { | |
155 | fail("The analysis parent did not open in a reasonable time"); | |
eb130160 | 156 | } |
bc5f2035 | 157 | ITmfTrace trace = traceElement.getTrace(); |
c068a752 | 158 | |
c068a752 GB |
159 | assertNotNull(trace); |
160 | TestAnalysisUi module = (TestAnalysisUi) trace.getAnalysisModule(analysis.getAnalysisId()); | |
161 | assertNotNull(module); | |
162 | ||
163 | } | |
164 | } |