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