tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / analysis / xml / ui / swtbot / tests / latency / PatternDensityViewTest.java
CommitLineData
8084800d
JCK
1/*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
10package org.eclipse.tracecompass.tmf.analysis.xml.ui.swtbot.tests.latency;
11
12import static org.eclipse.swtbot.swt.finder.SWTBotAssert.assertVisible;
13import static org.junit.Assert.assertEquals;
14import static org.junit.Assert.assertNotNull;
15import static org.junit.Assert.assertTrue;
16import static org.junit.Assert.fail;
17
18import java.lang.reflect.Field;
19
20import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
21import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
22import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
23import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
24import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
25import org.eclipse.swtbot.swt.finder.results.Result;
26import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
27import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
28import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.density.AbstractSegmentStoreDensityView;
29import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.table.AbstractSegmentStoreTableViewer;
30import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView;
31import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
f0beeb4a 32import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
8084800d
JCK
33import org.eclipse.ui.IViewPart;
34import org.eclipse.ui.IViewReference;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.swtchart.Chart;
38import org.swtchart.ISeries;
39import org.swtchart.ISeriesSet;
40
41/**
42 * Test of the pattern density view
43 *
44 * @author Jean-Christian Kouame
45 */
46@RunWith(SWTBotJunit4ClassRunner.class)
47public class PatternDensityViewTest extends PatternLatencyViewTestBase {
48
49 private static final String COLUMN_HEADER = "Name";
50 private static final String SYSTEM_CALL_PREFIX = "sys_";
51 private static final String VIEW_ID = PatternDensityView.ID;
52 private static final String VIEW_TITLE = "Latency vs Count";
53
54 private AbstractSegmentStoreDensityView fDensityView;
55 private AbstractSegmentStoreTableViewer fDensityViewer;
56 private Chart fDensityChart;
57
58 /**
59 * Set the density viewer
60 *
61 * @throws SecurityException
62 * If a security manager is present and any the wrong class is
63 * loaded or the class loader is not the same as its ancestor's
64 * loader.
65 *
66 * @throws NoSuchFieldException
67 * Field not available
68 * @throws IllegalAccessException
69 * Field is inaccessible
70 * @throws IllegalArgumentException
71 * the object is not the correct class type
72 */
73 public void setDensityViewer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
74 SWTBotView viewBot = fBot.viewById(VIEW_ID);
75 final IViewReference viewReference = viewBot.getViewReference();
76 IViewPart viewPart = UIThreadRunnable.syncExec(new Result<IViewPart>() {
77 @Override
78 public IViewPart run() {
79 return viewReference.getView(true);
80 }
81 });
82 assertNotNull(viewPart);
83 if (!(viewPart instanceof PatternDensityView)) {
84 fail("Could not instanciate view");
85 }
86 fDensityView = (PatternDensityView) viewPart;
87
88 /*
89 * Use reflection to access the table viewer
90 */
91 final Field field = AbstractSegmentStoreDensityView.class.getDeclaredField("fTableViewer");
92 field.setAccessible(true);
93 fDensityViewer = (AbstractSegmentStoreTableViewer) field.get(fDensityView);
94 fDensityChart = viewBot.bot().widget(WidgetOfType.widgetOfType(Chart.class));
95 assertNotNull(fDensityViewer);
96 }
97
98 /**
99 * Test the pattern density view and its viewers data
100 *
101 * @throws SecurityException
102 * If a security manager is present and any the wrong class is
103 * loaded or the class loader is not the same as its ancestor's
104 * loader.
105 *
106 * @throws NoSuchFieldException
107 * Field not available
108 * @throws IllegalAccessException
109 * Field is inaccessible
110 * @throws IllegalArgumentException
111 * the object is not the correct class type
112 *
113 */
114 @Test
115 public void testWithTrace() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
116 setDensityViewer();
f0beeb4a 117 WaitUtils.waitForJobs();
8084800d
JCK
118
119 //Test the table content
120 SWTBotTable tableBot = new SWTBotTable(fDensityViewer.getTableViewer().getTable());
121 fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, SYSTEM_CALL_PREFIX, 0, 3));
122 tableBot.header(COLUMN_HEADER).click();
123 fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, SYSTEM_CALL_PREFIX, 0, 3));
124 tableBot.header(COLUMN_HEADER).click();
125 fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, SYSTEM_CALL_PREFIX, 0, 3));
126
127 //Test the chart content
128 final Chart densityChart = fDensityChart;
129 assertNotNull(densityChart);
aa5b9bd6
MAL
130 fBot.waitUntil(ConditionHelpers.numberOfSeries(densityChart, 1));
131
8084800d
JCK
132 SWTBotChart chartBot = new SWTBotChart(densityChart);
133 assertVisible(chartBot);
134
135 ISeriesSet seriesSet = fDensityChart.getSeriesSet();
136 assertNotNull(seriesSet);
137 ISeries[] series = seriesSet.getSeries();
138 assertNotNull(series);
139
140 // Verify that the chart has 1 series
141 assertEquals(1, series.length);
142 // Verify that the series has data
143 assertTrue(series[0].getXSeries().length > 0);
144 }
145
146 private static class SWTBotChart extends AbstractSWTBotControl<Chart> {
147 public SWTBotChart(Chart w) throws WidgetNotFoundException {
148 super(w);
149 }
150 }
151
152 @Override
153 protected String getViewId() {
154 return VIEW_ID;
155 }
156
157 @Override
158 protected String getViewTitle() {
159 return VIEW_TITLE;
160 }
161}
This page took 0.03427 seconds and 5 git commands to generate.