swtbot: Help stabilize SWTChart tests by waiting for number of series
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / ust / ui / swtbot / tests / MemoryUsageViewTest.java
CommitLineData
7b583932
BH
1/*******************************************************************************
2 * Copyright (c) 2015 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.lttng2.ust.ui.swtbot.tests;
11
7b583932
BH
12import static org.junit.Assert.assertNotNull;
13import static org.junit.Assert.assertTrue;
14
15import java.io.File;
16
17import org.apache.log4j.ConsoleAppender;
18import org.apache.log4j.Logger;
19import org.apache.log4j.SimpleLayout;
20import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
21import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
22import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
23import org.eclipse.swtbot.swt.finder.matchers.WidgetOfType;
24import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
25import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
26import org.eclipse.tracecompass.internal.lttng2.ust.ui.views.memusage.MemoryUsageView;
27import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
28import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
aa5b9bd6 29import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
7b583932
BH
30import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
31import org.hamcrest.Matcher;
32import org.junit.After;
33import org.junit.Before;
34import org.junit.BeforeClass;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.swtchart.Chart;
38import org.swtchart.ILineSeries;
39import org.swtchart.ISeries;
40import org.swtchart.ISeriesSet;
41
42/**
43 * Test for the Memory Usage view in trace compass
44 */
45@RunWith(SWTBotJunit4ClassRunner.class)
46public class MemoryUsageViewTest {
47
b2d6540e
MAL
48 private static final int EXPECTED_NUM_SERIES = 4;
49
7b583932
BH
50 private static final String UST_ID = "org.eclipse.linuxtools.lttng2.ust.tracetype";
51
52 private static final String PROJECT_NAME = "TestForMemory";
53
54 /** The Log4j logger instance. */
55 private static final Logger fLogger = Logger.getRootLogger();
56 private static SWTWorkbenchBot fBot;
57
58 /**
59 * Initialization
60 */
61 @BeforeClass
62 public static void init() {
63 SWTBotUtils.initialize();
64
65 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
66 /* set up for swtbot */
67 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
68 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
69 fBot = new SWTWorkbenchBot();
70
71 SWTBotUtils.closeView("welcome", fBot);
72
73 SWTBotUtils.switchToTracingPerspective();
74
75 /* finish waiting for eclipse to load */
76 SWTBotUtils.waitForJobs();
77 }
78
79 /**
80 * Open a trace in an editor
81 */
82 @Before
83 public void beforeTest() {
84 SWTBotUtils.createProject(PROJECT_NAME);
85 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
86 assertNotNull(treeItem);
87 final CtfTestTrace cygProfile = CtfTestTrace.MEMORY_ANALYSIS;
88 final File file = new File(CtfTmfTestTraceUtils.getTrace(cygProfile).getPath());
89 SWTBotUtils.openTrace(PROJECT_NAME, file.getAbsolutePath(), UST_ID);
90 SWTBotUtils.openView(MemoryUsageView.ID);
91 SWTBotUtils.waitForJobs();
92 }
93
94 /**
95 * Close the editor
96 */
97 @After
98 public void tearDown() {
99 fBot.closeAllEditors();
100 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
101 }
102
103 /**
104 * Test if Memory Usage is populated
105 */
106 @Test
107 public void testOpenMemoryUsage() {
108 SWTBotView viewBot = fBot.viewById(MemoryUsageView.ID);
109 viewBot.setFocus();
110
111 // Do some basic validation
112 Matcher<Chart> matcher = WidgetOfType.widgetOfType(Chart.class);
113 Chart chart = viewBot.bot().widget(matcher);
7b583932
BH
114
115 // Verify that the chart has 4 series
aa5b9bd6 116 fBot.waitUntil(ConditionHelpers.numberOfSeries(chart, EXPECTED_NUM_SERIES));
b2d6540e
MAL
117
118 ISeriesSet seriesSet = chart.getSeriesSet();
119 ISeries[] series = seriesSet.getSeries();
7b583932
BH
120 // Verify that each series is a ILineSeries
121 for (int i = 0; i < series.length; i++) {
122 assertTrue(series[i] instanceof ILineSeries);
123 }
124 }
125
126}
This page took 0.035898 seconds and 5 git commands to generate.