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