TMF: Added a method in UI tests to delay main thread until trace is opened
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / project / model / ProjectModelAnalysisTest.java
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;
22 import java.util.concurrent.TimeoutException;
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;
29 import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;
30 import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
31 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
32 import org.eclipse.linuxtools.tmf.ui.tests.shared.ProjectModelTestData;
33 import org.eclipse.linuxtools.tmf.ui.tests.stubs.analysis.TestAnalysisUi;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37
38 /**
39 * Test suite for the {@link TmfAnalysisElement} class.
40 *
41 * @author Geneviève Bastien
42 */
43 public class ProjectModelAnalysisTest {
44
45 /** ID of analysis module in UI */
46 public static final String MODULE_UI = "org.eclipse.linuxtools.tmf.ui.tests.test";
47 private TmfProjectElement fixture;
48
49 /**
50 * Perform pre-test initialization.
51 */
52 @Before
53 public void setUp() {
54 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
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 /**
85 * Test the getAvailableAnalysis() method
86 */
87 @Test
88 public void testListAnalysis() {
89 TmfTraceElement trace = getTraceElement();
90
91 /* Make sure the analysis list is not empty */
92 List<TmfAnalysisElement> analysisList = trace.getAvailableAnalysis();
93 assertFalse(analysisList.isEmpty());
94
95 /* Make sure TestAnalysisUi is there */
96 TmfAnalysisElement analysis = null;
97 for (TmfAnalysisElement analysisElement : analysisList) {
98 if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
99 analysis = analysisElement;
100 }
101 }
102 assertNotNull(analysis);
103
104 assertEquals("Test analysis in UI", analysis.getName());
105 }
106
107 /**
108 * Test if the list of available analysis is correctly populated by the
109 * content provider
110 */
111 @Test
112 public void testPopulate() {
113 TmfTraceElement trace = getTraceElement();
114
115 final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
116 // force the model to be populated
117 ncp.getChildren(fixture);
118
119 /* Make sure the analysis list is not empty */
120 List<ITmfProjectModelElement> analysisList = trace.getChildren();
121 assertFalse(analysisList.isEmpty());
122
123 /* Make sure TestAnalysisUi is there */
124 TmfAnalysisElement analysis = null;
125 for (ITmfProjectModelElement element : analysisList) {
126 if (element instanceof TmfAnalysisElement) {
127 TmfAnalysisElement analysisElement = (TmfAnalysisElement) element;
128 if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
129 analysis = analysisElement;
130 }
131 }
132 }
133 assertNotNull(analysis);
134
135 assertEquals("Test analysis in UI", analysis.getName());
136 }
137
138 /**
139 * Test the instantiateAnalysis method
140 */
141 @Test
142 public void testInstantiate() {
143 TmfTraceElement traceElement = getTraceElement();
144
145 TmfAnalysisElement analysis = null;
146 for (TmfAnalysisElement analysisElement : traceElement.getAvailableAnalysis()) {
147 if (analysisElement.getAnalysisId().equals(MODULE_UI)) {
148 analysis = analysisElement;
149 }
150 }
151 assertNotNull(analysis);
152
153 /* Instantiate an analysis on a trace that is closed */
154 traceElement.closeEditors();
155 analysis.activateParent();
156
157 try {
158 ProjectModelTestData.delayUntilTraceOpened(traceElement);
159 } catch (TimeoutException e) {
160 fail("The analysis parent did not open in a reasonable time");
161 }
162 ITmfTrace trace = traceElement.getTrace();
163
164 assertNotNull(trace);
165 TestAnalysisUi module = (TestAnalysisUi) trace.getAnalysisModule(analysis.getAnalysisId());
166 assertNotNull(module);
167
168 }
169 }
This page took 0.034967 seconds and 5 git commands to generate.