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
CommitLineData
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 13package org.eclipse.tracecompass.tmf.ui.tests.project.model;
c068a752
GB
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertNotNull;
5c727157 18import static org.junit.Assert.assertTrue;
c068a752 19import static org.junit.Assert.fail;
c068a752
GB
20
21import java.util.List;
5c727157 22import java.util.Optional;
c068a752
GB
23
24import org.eclipse.core.runtime.CoreException;
2bdf0193
AM
25import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
26import org.eclipse.tracecompass.tmf.ui.project.model.ITmfProjectModelElement;
27import org.eclipse.tracecompass.tmf.ui.project.model.TmfAnalysisElement;
28import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
29import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
5c727157 30import org.eclipse.tracecompass.tmf.ui.project.model.TmfViewsElement;
2bdf0193 31import org.eclipse.tracecompass.tmf.ui.tests.shared.ProjectModelTestData;
6db82092 32import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitTimeoutException;
2bdf0193 33import org.eclipse.tracecompass.tmf.ui.tests.stubs.analysis.TestAnalysisUi;
c068a752
GB
34import org.junit.After;
35import org.junit.Before;
36import org.junit.Test;
37
38/**
39 * Test suite for the {@link TmfAnalysisElement} class.
40 *
41 * @author Geneviève Bastien
42 */
43public 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() {
c068a752
GB
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
5c727157
AM
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();
c068a752
GB
122
123 /* Make sure TestAnalysisUi is there */
5c727157
AM
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());
c068a752
GB
131 }
132
133 /**
134 * Test the instantiateAnalysis method
135 */
136 @Test
137 public void testInstantiate() {
138 TmfTraceElement traceElement = getTraceElement();
139
5c727157
AM
140 TmfAnalysisElement analysis = traceElement.getAvailableAnalysis().stream()
141 .filter(availableAnalysis -> availableAnalysis.getAnalysisId().equals(MODULE_UI))
142 .findFirst().get();
c068a752
GB
143
144 /* Instantiate an analysis on a trace that is closed */
145 traceElement.closeEditors();
5c727157 146 analysis.activateParentTrace();
c068a752 147
bc5f2035
GB
148 try {
149 ProjectModelTestData.delayUntilTraceOpened(traceElement);
6db82092 150 } catch (WaitTimeoutException e) {
bc5f2035 151 fail("The analysis parent did not open in a reasonable time");
eb130160 152 }
bc5f2035 153 ITmfTrace trace = traceElement.getTrace();
c068a752 154
c068a752
GB
155 assertNotNull(trace);
156 TestAnalysisUi module = (TestAnalysisUi) trace.getAnalysisModule(analysis.getAnalysisId());
157 assertNotNull(module);
158
159 }
160}
This page took 0.08028 seconds and 5 git commands to generate.