tmf: Fix intermittent fail in ProjectModelOutputTest.testListOutputs
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / project / model / ProjectModelAnalysisTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 É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.tracecompass.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.assertTrue;
19 import static org.junit.Assert.fail;
20
21 import java.util.List;
22 import java.util.Optional;
23
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
26 import org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement;
27 import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement;
28 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
29 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
30 import org.eclipse.tracecompass.tmf.ui.project.model.TmfViewsElement;
31 import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
32 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException;
33 import org.eclipse.tracecompass.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 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
114 /* Make sure the list of views is there and not empty */
115 Optional<TmfViewsElement> possibleViewsElem = trace.getChildren()
116 .stream()
117 .filter(child -> child instanceof TmfViewsElement)
118 .map(elem -> (TmfViewsElement) elem)
119 .findFirst();
120 assertTrue(possibleViewsElem.isPresent());
121 TmfViewsElement viewsElem = possibleViewsElem.get();
122
123 /* Make sure TestAnalysisUi is there */
124 Optional<TmfAnalysisElement> possibleAnalysisElem = viewsElem.getChildren().stream()
125 .filter(child -> child instanceof TmfAnalysisElement)
126 .map(elem -> (TmfAnalysisElement) elem)
127 .filter(analysisElem -> analysisElem.getAnalysisId().equals(MODULE_UI))
128 .findFirst();
129 assertTrue(possibleAnalysisElem.isPresent());
130 assertEquals("Test analysis in UI", possibleAnalysisElem.get().getName());
131 }
132
133 /**
134 * Test the instantiateAnalysis method
135 */
136 @Test
137 public void testInstantiate() {
138 TmfTraceElement traceElement = getTraceElement();
139
140 TmfAnalysisElement analysis = traceElement.getAvailableAnalysis().stream()
141 .filter(availableAnalysis -> availableAnalysis.getAnalysisId().equals(MODULE_UI))
142 .findFirst().get();
143
144 /* Instantiate an analysis on a trace that is closed */
145 traceElement.closeEditors();
146 analysis.activateParentTrace();
147
148 try {
149 ProjectModelTestData.delayUntilTraceOpened(traceElement);
150 } catch (WaitTimeoutException e) {
151 fail("The analysis parent did not open in a reasonable time");
152 }
153 ITmfTrace trace = traceElement.getTrace();
154
155 assertNotNull(trace);
156 TestAnalysisUi module = (TestAnalysisUi) trace.getAnalysisModule(analysis.getAnalysisId());
157 assertNotNull(module);
158
159 }
160 }
This page took 0.0346340000000001 seconds and 5 git commands to generate.