From 693ec8296cc80c1c06be1b677479f76e795a1ad9 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 23 Sep 2014 09:50:38 -0400 Subject: [PATCH] tmf: add SWTBot tests for collapsing feature (disabled for now) Change-Id: I67952062a74c744ca7ef8abce474bb92ebfa328c Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/33846 Tested-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../plugin.xml | 8 + .../tests/stubs/trace/text/SyslogEvent.java | 65 +++++- .../testfiles/syslog_collapse | 22 ++ .../.settings/org.eclipse.jdt.core.prefs | 4 +- .../META-INF/MANIFEST.MF | 6 +- .../ui/swtbot/tests/AllTmfUISWTBotTests.java | 5 +- .../tmf/ui/swtbot/tests/SWTBotUtil.java | 36 +++- .../tests/conditions/ConditionHelpers.java | 18 ++ .../tests/conditions/TableCellFilled.java | 56 +++++ .../tmf/ui/swtbot/tests/table/AllTests.java | 28 +++ .../table/CollapseEventsInTableTest.java | 196 ++++++++++++++++++ 11 files changed, 437 insertions(+), 7 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.core.tests/testfiles/syslog_collapse create mode 100644 org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/TableCellFilled.java create mode 100644 org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/AllTests.java create mode 100644 org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java diff --git a/org.eclipse.linuxtools.tmf.core.tests/plugin.xml b/org.eclipse.linuxtools.tmf.core.tests/plugin.xml index bf01118274..74c3626fac 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/plugin.xml +++ b/org.eclipse.linuxtools.tmf.core.tests/plugin.xml @@ -105,6 +105,14 @@ name="Test experiment" experiment_type="org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfExperimentStub"> + + diff --git a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/text/SyslogEvent.java b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/text/SyslogEvent.java index 0286d758c4..8146adc101 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/text/SyslogEvent.java +++ b/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/trace/text/SyslogEvent.java @@ -12,7 +12,11 @@ package org.eclipse.linuxtools.tmf.tests.stubs.trace.text; +import java.util.List; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; +import org.eclipse.linuxtools.tmf.core.event.collapse.ITmfCollapsibleEvent; import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.trace.text.TextTraceEvent; import org.eclipse.linuxtools.tmf.core.trace.text.TextTraceEventContent; @@ -20,7 +24,7 @@ import org.eclipse.linuxtools.tmf.core.trace.text.TextTraceEventContent; /** * System log trace implementation of TmfEvent. */ -public class SyslogEvent extends TextTraceEvent { +public class SyslogEvent extends TextTraceEvent implements ITmfCollapsibleEvent { /** * Default constructor @@ -61,4 +65,63 @@ public class SyslogEvent extends TextTraceEvent { super(parentTrace, timestamp, source, type, content, reference); } + @Override + public boolean isCollapsibleWith(ITmfEvent otherEvent) { + if (this == otherEvent) { + return true; + } + + if (!(otherEvent instanceof SyslogEvent)) { + return false; + } + + final SyslogEvent other = (SyslogEvent) otherEvent; + + if (getTrace() == null) { + if (other.getTrace() != null) { + return false; + } + } else if (!getTrace().equals(other.getTrace())) { + return false; + } + + if (getType() == null) { + if (other.getType() != null) { + return false; + } + } else if (!getType().equals(other.getType())) { + return false; + } + + TextTraceEventContent content = this.getContent(); + TextTraceEventContent otherContent = other.getContent(); + + if (content == null) { + if (otherContent != null) { + return false; + } + return true; + } + + if (otherContent == null) { + return false; + } + + List fields = content.getFields(); + List otherFields = otherContent.getFields(); + int size = fields.size(); + + if (size != otherFields.size()) { + return false; + } + + // At i = 0 the timestamp is stored and needs to be bypassed + for (int i = 1; i < size; i++) { + if (!fields.get(i).equals(otherFields.get(i))) { + return false; + } + } + return true; + } + } diff --git a/org.eclipse.linuxtools.tmf.core.tests/testfiles/syslog_collapse b/org.eclipse.linuxtools.tmf.core.tests/testfiles/syslog_collapse new file mode 100644 index 0000000000..556c0f2b72 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core.tests/testfiles/syslog_collapse @@ -0,0 +1,22 @@ +Jan 1 01:01:01 HostA LoggerA: Message A +Jan 1 02:02:02 HostB LoggerB: Message B +Jan 1 03:03:03 HostC LoggerC: Message C +Jan 1 04:04:04 HostD LoggerD: Message D +Jan 1 05:05:05 HostE LoggerE: +Jan 1 06:06:06 HostF LoggerF: Message F +Jan 1 06:06:07 HostF LoggerF: Message F +Jan 1 06:06:08 HostF LoggerF: Message F +Jan 1 06:06:09 HostF LoggerF: Message F +Jan 1 06:06:10 HostF LoggerF: Message F +Jan 1 06:06:11 HostF LoggerF: Message F +Jan 1 06:06:12 HostF LoggerF: Message F +Jan 1 06:06:13 HostF LoggerF: Message F +Jan 1 06:06:14 HostF LoggerF: Message F +Jan 1 06:06:15 HostF LoggerF: Message F +Jan 1 06:06:16 HostF LoggerF: Message F +Jan 1 06:06:17 HostF LoggerF: Message F +Jan 1 06:06:18 HostF LoggerF: Message F +Jan 1 06:06:19 HostF LoggerF: Message F +Jan 1 06:06:20 HostF LoggerF: Message F +Jan 1 06:06:21 HostF LoggerF: Message D +Jan 1 06:06:22 HostF LoggerF: Message D diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/.settings/org.eclipse.jdt.core.prefs index f3fc64575b..9e6ba79e52 100644 --- a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/.settings/org.eclipse.jdt.core.prefs @@ -21,7 +21,7 @@ org.eclipse.jdt.core.compiler.problem.deadCode=error org.eclipse.jdt.core.compiler.problem.deprecation=error org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=error +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=error @@ -30,7 +30,7 @@ org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=error org.eclipse.jdt.core.compiler.problem.finalParameterBound=error org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF index 19c23459a9..43d48da31c 100644 --- a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF @@ -16,14 +16,18 @@ Require-Bundle: org.junit;bundle-version="4.0.0", org.eclipse.ui.ide, org.eclipse.ui.views, org.eclipse.linuxtools.tmf.ui, - org.eclipse.linuxtools.tmf.core + org.eclipse.linuxtools.tmf.core, + org.eclipse.linuxtools.tmf.core.tests, + org.eclipse.swtbot.junit4_x Import-Package: org.apache.log4j, org.apache.log4j.varia, org.eclipse.swtbot.eclipse.finder, + org.eclipse.swtbot.eclipse.finder.matchers, org.eclipse.swtbot.eclipse.finder.widgets, org.eclipse.swtbot.swt.finder, org.eclipse.swtbot.swt.finder.finders, org.eclipse.swtbot.swt.finder.junit, + org.eclipse.swtbot.swt.finder.keyboard, org.eclipse.swtbot.swt.finder.results, org.eclipse.swtbot.swt.finder.utils, org.eclipse.swtbot.swt.finder.waits, diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/AllTmfUISWTBotTests.java b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/AllTmfUISWTBotTests.java index 701bc4d75b..0695023fae 100644 --- a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/AllTmfUISWTBotTests.java +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/AllTmfUISWTBotTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Ericsson + * Copyright (c) 2013, 2014 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -24,7 +24,8 @@ import org.junit.runners.Suite; @Suite.SuiteClasses({ TestCustomTxtWizard.class, TestCustomXmlWizard.class, - TracingPerspectiveChecker.class + TracingPerspectiveChecker.class, + org.eclipse.linuxtools.tmf.ui.swtbot.tests.table.AllTests.class }) public class AllTmfUISWTBotTests { } diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java index a8d7c4f548..55224d9c67 100644 --- a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java @@ -23,6 +23,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; @@ -30,6 +31,8 @@ import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers; import org.eclipse.linuxtools.tmf.ui.views.TracingPerspectiveFactory; import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; import org.eclipse.swtbot.swt.finder.results.VoidResult; @@ -40,9 +43,12 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; +import org.hamcrest.Matcher; /** * SWTBot Helper functions @@ -118,7 +124,7 @@ public abstract class SWTBotUtil { final SWTBotView projectViewBot = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER); projectViewBot.setFocus(); - SWTBotTree treeBot = bot.tree(); + SWTBotTree treeBot = projectViewBot.bot().tree(); SWTBotTreeItem treeItem = treeBot.getTreeItem(projectName); SWTBotMenu contextMenu = treeItem.contextMenu("Delete"); contextMenu.click(); @@ -238,4 +244,32 @@ public abstract class SWTBotUtil { delay(1000); waitForJobs(); } + + /** + * Opens an editor and sets focus to the editor + * + * @param bot + * the workbench bot + * @param editorName + * the editor name + * @return the corresponding SWTBotEditor + */ + public static SWTBotEditor openEditor(SWTWorkbenchBot bot, String editorName) { + Matcher matcher = WidgetMatcherFactory.withPartName(editorName); + final SWTBotEditor editorBot = bot.editor(matcher); + IEditorPart iep = editorBot.getReference().getEditor(true); + final TmfEventsEditor tmfEd = (TmfEventsEditor) iep; + editorBot.show(); + UIThreadRunnable.syncExec(new VoidResult() { + @Override + public void run() { + tmfEd.setFocus(); + } + }); + + SWTBotUtil.waitForJobs(); + SWTBotUtil.delay(1000); + assertNotNull(tmfEd); + return editorBot; + } } diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/ConditionHelpers.java b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/ConditionHelpers.java index b114436723..e6fb0e7f9a 100644 --- a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/ConditionHelpers.java +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/ConditionHelpers.java @@ -16,6 +16,7 @@ import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.Wizard; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.waits.ICondition; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; @@ -86,4 +87,21 @@ public abstract class ConditionHelpers { public static ICondition ViewIsClosed(SWTBotView view) { return new ViewClosed(view); } + + /** + * Wait till table cell has a given content. + * + * @param table + * the table bot reference + * @param content + * the content to check + * @param row + * the row of the cell + * @param column + * the column of the cell + * @return ICondition for verification + */ + public static ICondition isTableCellFilled(SWTBotTable table, String content, int row, int column) { + return new TableCellFilled(table, content, row, column); + } } diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/TableCellFilled.java b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/TableCellFilled.java new file mode 100644 index 0000000000..29be0e6637 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/conditions/TableCellFilled.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2014 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions; + +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.waits.ICondition; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; + +/** + * Is a table cell filled? tests if the table cell has a given content. + * + * @author Bernd Hufmann + */ +class TableCellFilled implements ICondition { + + private final SWTBotTable fTable; + private final String fContent; + private final int fRow; + private final int fColumn; + + public TableCellFilled(SWTBotTable table, String content, int row, int column) { + fTable = table; + fContent = content; + fRow = row; + fColumn = column; + } + + @Override + public boolean test() throws Exception { + try { + return fContent.equals(fTable.cell(fRow, fColumn)); + } catch (Exception e) { + } + return false; + } + + @Override + public void init(SWTBot bot) { + } + + @Override + public String getFailureMessage() { + return null; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/AllTests.java b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/AllTests.java new file mode 100644 index 0000000000..55d6983991 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/AllTests.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2014 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.swtbot.tests.table; + +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * SWTBot test suite for testing of the TMF events table. + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CollapseEventsInTableTest.class, +}) +@Ignore +public class AllTests { +} diff --git a/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java new file mode 100644 index 0000000000..95e4c328c0 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.swtbot.tests.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.bindings.keys.IKeyLookup; +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; +import org.eclipse.linuxtools.internal.tmf.core.Activator; +import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; +import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimePreferencesConstants; +import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestampFormat; +import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil; +import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * SWTBot test for testing collapsing feature. + * + * @author Bernd Hufmann + */ +@SuppressWarnings("restriction") +@RunWith(SWTBotJunit4ClassRunner.class) +public class CollapseEventsInTableTest { + + private static final String TRACE_PROJECT_NAME = "test"; + private static final String COLLAPSE_TRACE_NAME = "syslog_collapse"; + private static final String COLLAPSE_TRACE_PATH = "testfiles/" + COLLAPSE_TRACE_NAME; + private static final String COLLAPSE_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog"; + + private static File fTestFile = null; + + private static SWTWorkbenchBot fBot; + + /** The Log4j logger instance. */ + private static final Logger fLogger = Logger.getRootLogger(); + + /** + * Test Class setup + */ + @BeforeClass + public static void init() { + SWTBotUtil.failIfUIThread(); + + /* set up test trace*/ + URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLLAPSE_TRACE_PATH), null); + URI uri; + try { + uri = FileLocator.toFileURL(location).toURI(); + fTestFile = new File(uri); + } catch (URISyntaxException | IOException e) { + e.printStackTrace(); + fail(); + } + + assumeTrue(fTestFile.exists()); + + IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); + defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "MMM d HH:mm:ss"); + defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NO_FMT); + TmfTimestampFormat.updateDefaultFormats(); + + /* Set up for swtbot */ + SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ + fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); + fBot = new SWTWorkbenchBot(); + + /* Close welcome view */ + SWTBotUtil.closeView("Welcome", fBot); + + /* Switch perspectives */ + SWTBotUtil.switchToTracingPerspective(); + + /* Finish waiting for eclipse to load */ + SWTBotUtil.waitForJobs(); + } + + /** + * Test class tear down method. + */ + @AfterClass + public static void tearDown() { + /* Set timestamp defaults */ + IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); + defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, ITmfTimePreferencesConstants.TIME_HOUR_FMT); + defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NANO_FMT); + TmfTimestampFormat.updateDefaultFormats(); + } + + /** + * Main test case + */ + @Test + public void test() { + SWTBotUtil.createProject(TRACE_PROJECT_NAME); + SWTBotUtil.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLLAPSE_TRACE_TYPE); + SWTBotEditor editorBot = SWTBotUtil.openEditor(fBot, fTestFile.getName()); + + SWTBotTable tableBot = editorBot.bot().table(); + + /* Maximize editor area */ + maximizeTable(tableBot); + tableBot.click(1, 0); + + /* Collapse Events */ + SWTBotMenu menuBot = tableBot.contextMenu("Collapse Events"); + menuBot.click(); + fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "7/22", 1, 1)); + + String filterString = tableBot.cell(1, 1); + assertEquals("filterString", "7/22", filterString); + + /* Verify collapsed event */ + filterString = tableBot.cell(7, 0); + assertEquals("repeatCount", "+14", filterString); + + filterString = tableBot.cell(7, 1); + assertEquals("first timestamp", "Jan 1 06:06:06", filterString); + + filterString = tableBot.cell(7, 2); + assertEquals("source", "", filterString); + + filterString = tableBot.cell(7, 3); + assertEquals("type", "Syslog", filterString); + + filterString = tableBot.cell(7, 4); + assertEquals("file", "", filterString); + + filterString = tableBot.cell(7, 5); + assertEquals("content", "Timestamp=Jan 1 06:06:06, Host=HostF, Logger=LoggerF, Message=Message F", filterString); + + filterString = tableBot.cell(8, 0); + assertEquals("repeatCount", "+1", filterString); + + filterString = tableBot.cell(8, 1); + assertEquals("first timestamp (2nd collapse)", "Jan 1 06:06:21", filterString); + + filterString = tableBot.cell(8, 5); + assertEquals("content", "Timestamp=Jan 1 06:06:21, Host=HostF, Logger=LoggerF, Message=Message D", filterString); + + /* Clear Filter */ + menuBot = tableBot.contextMenu("Clear Filters"); + menuBot.click(); + fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "Jan 1 01:01:01", 1, 1)); + assertEquals("timestamp", "Jan 1 01:01:01", tableBot.cell(1, 1)); + + maximizeTable(tableBot); + + fBot.closeAllEditors(); + SWTBotUtil.deleteProject(TRACE_PROJECT_NAME, fBot); + } + + private static void maximizeTable(SWTBotTable tableBot) { + try { + tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M")); + } catch (ParseException e) { + fail(); + } + } + +} -- 2.34.1