From: Marc-Andre Laperle Date: Fri, 26 Aug 2016 03:08:01 +0000 (-0400) Subject: Move ProjectExplorerTraceActionsTest to integration tests X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=a4f6f73b412eb8df3e4587ab3e9b7a25a48f9113;p=deliverable%2Ftracecompass.git Move ProjectExplorerTraceActionsTest to integration tests This class was written as an integration test. Now it has a proper home. It also serves as a first example how TestDirectoryStructureUtil can be used. Change-Id: I4d79efb1bd621a243b4976a55e2b3e8da4f5fc3f Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/79790 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF b/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF index f9311a08dd..2c7d0871dc 100644 --- a/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF @@ -8,5 +8,15 @@ Bundle-SymbolicName: org.eclipse.tracecompass.integration.swtbot.tests;singleton Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer -Require-Bundle: org.eclipse.tracecompass.ctf.core.tests, +Require-Bundle: org.apache.log4j, + org.eclipse.core.resources, + org.eclipse.core.runtime, + org.eclipse.swtbot.eclipse.finder, + org.eclipse.swtbot.junit4_x, + org.eclipse.tracecompass.ctf.core.tests, + org.eclipse.tracecompass.tmf.core, + org.eclipse.tracecompass.tmf.ui, + org.eclipse.tracecompass.tmf.ui.swtbot.tests, + org.eclipse.ui, org.junit +Import-Package: com.google.common.collect;version="15.0.0" diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTraceActionsTest.java b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTraceActionsTest.java new file mode 100644 index 0000000000..0c480c91e3 --- /dev/null +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTraceActionsTest.java @@ -0,0 +1,415 @@ +/****************************************************************************** + * Copyright (c) 2016 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 + *******************************************************************************/ + +package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Logger; +import org.apache.log4j.SimpleLayout; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes; +import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; +import org.eclipse.swtbot.swt.finder.waits.Conditions; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; +import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; +import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; +import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView; +import org.eclipse.ui.IEditorReference; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.common.collect.ImmutableList; + +/** + * SWTBot test for testing Project Explorer Trace actions (context-menus, + * keyboard) + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class ProjectExplorerTraceActionsTest { + private static @NonNull TestTraceInfo CUSTOM_TEXT_LOG = new TestTraceInfo("ExampleCustomTxt.log", "Custom Text : TmfGeneric", 10, "29:52.034"); + private static final String TRACE_PROJECT_NAME = "test"; + private static final String TRACE_NAME = CUSTOM_TEXT_LOG.getTraceName(); + private static final String RENAMED_TRACE_NAME = TRACE_NAME + 2; + + private static File fTestFile = null; + + private static SWTWorkbenchBot fBot; + + /** The Log4j logger instance. */ + private static final Logger fLogger = Logger.getRootLogger(); + + private static final File TEST_TRACES_PATH = new File(new Path(TmfTraceManager.getTemporaryDirPath()).append("testtraces").toOSString()); + private static String getPath(String relativePath) { + return new Path(TEST_TRACES_PATH.getAbsolutePath()).append(relativePath).toOSString(); + } + + /** + * Test Class setup + * + * @throws IOException + * on error + */ + @BeforeClass + public static void init() throws IOException { + TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH); + + SWTBotUtils.initialize(); + + // FIXME: We can't use Manage Custom Parsers > Import because it uses a native dialog. We'll still check that they show up in the dialog + CustomTxtTraceDefinition[] txtDefinitions = CustomTxtTraceDefinition.loadAll(getPath("customParsers/ExampleCustomTxtParser.xml")); + txtDefinitions[0].save(); + /* set up test trace */ + fTestFile = new File(getPath(new Path("import").append(CUSTOM_TEXT_LOG.getTracePath()).toString())); + + assertTrue(fTestFile.exists()); + + /* Set up for swtbot */ + SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ + SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; + fLogger.removeAllAppenders(); + fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); + fBot = new SWTWorkbenchBot(); + + /* Close welcome view */ + SWTBotUtils.closeView("Welcome", fBot); + + /* Switch perspectives */ + SWTBotUtils.switchToTracingPerspective(); + + /* Finish waiting for eclipse to load */ + SWTBotUtils.waitForJobs(); + SWTBotUtils.createProject(TRACE_PROJECT_NAME); + } + + /** + * Test class tear down method. + */ + @AfterClass + public static void tearDown() { + SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot); + fLogger.removeAllAppenders(); + } + + /** + * Test that the expected context menu items are there + *

+ * Action : Trace menu + *

+ * Procedure :Select an LTTng trace and open its context menu + *

+ * Expected Results: Correct menu opens (Open , Copy, Rename, …) + * + */ + @Test + public void test4_01ContextMenuPresence() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + + final List EXPECTED_MENU_LABELS = ImmutableList.of("Open", "Open With", "", "Copy...", "Rename...", "Delete", "", "Delete Supplementary Files...", "", "Export Trace Package...", "", "Select Trace Type...", "", "Apply Time Offset...", + "Clear Time Offset", "", "Refresh"); + List menuItems = traceItem.contextMenu().menuItems(); + assertEquals(EXPECTED_MENU_LABELS, menuItems); + + fBot.closeAllEditors(); + } + + /** + * Test that the trace opens with the context menu + *

+ * Action : Open trace + *

+ * Procedure :Select the Open menu + *

+ * Expected Results: Trace is opened and views are populated + * + */ + @Test + public void test4_02Open() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + + traceItem.contextMenu().menu("Open").click(); + testEventsTable(TRACE_NAME); + testStatisticsView(); + fBot.closeAllEditors(); + } + + /** + * Test that the trace can be copied with the context menu + *

+ * Action : Copy trace + *

+ * Procedure :Select the Copy menu and provide a new name. Open. + *

+ * Expected Results: Trace is replicated under the new name + * + */ + @Test + public void test4_03Copy() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + + createCopy(traceItem); + + fBot.closeAllEditors(); + SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME); + copiedItem.contextMenu().menu("Open").click(); + testEventsTable(RENAMED_TRACE_NAME); + fBot.closeAllEditors(); + SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); + } + + /** + * Test that the trace can be renamed with the context menu + *

+ * Action : Rename trace + *

+ * Procedure :Select the Rename menu and provide a new name. Reopen. + *

+ * Expected Results: Trace is renamed. The trace editor is closed. + */ + @Test + public void test4_04Rename() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + + traceItem.contextMenu().menu("Rename...").click(); + final String RENAME_TRACE_DIALOG_TITLE = "Rename Trace"; + fBot.waitUntil(Conditions.shellIsActive(RENAME_TRACE_DIALOG_TITLE)); + SWTBotShell shell = fBot.shell(RENAME_TRACE_DIALOG_TITLE); + SWTBotText text = shell.bot().textWithLabel("New Trace name:"); + text.setText(RENAMED_TRACE_NAME); + shell.bot().button("OK").click(); + fBot.waitUntil(Conditions.shellCloses(shell)); + fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null)); + + SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME); + copiedItem.contextMenu().menu("Open").click(); + testEventsTable(RENAMED_TRACE_NAME); + fBot.closeAllEditors(); + SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); + } + + /** + * Test that the trace can be deleted with the context menu + *

+ * Action : Delete trace + *

+ * Procedure :Select the Delete menu and confirm deletion + *

+ * Expected Results: Trace is deleted. The trace editor is closed. + * + */ + @Test + public void test4_05Delete() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + + traceItem.contextMenu().menu("Delete").click(); + final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete"; + fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE)); + SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE); + shell.bot().button("Yes").click(); + fBot.waitUntil(Conditions.shellCloses(shell)); + fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null)); + fBot.waitUntil(new TraceDeletedCondition()); + } + + /** + * Test that the trace opens with the keyboard + *

+ * Action : Open Trace (Accelerator) + *

+ * Procedure :Select trace and press Enter + *

+ * Expected Results: Trace is opened + * + * + * @throws WidgetNotFoundException + * when a widget is not found + */ + @Test + public void test4_06OpenKeyboard() throws WidgetNotFoundException { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + traceItem.select(); + fBot.activeShell().pressShortcut(Keystrokes.CR); + + testEventsTable(TRACE_NAME); + testStatisticsView(); + fBot.closeAllEditors(); + } + + /** + * Test that the trace can be deleted with the keyboard + *

+ * Action : Delete Trace (Accelerator) + *

+ * Procedure :Select trace and press Delete and confirm deletion + *

+ * Expected Results: Trace is deleted. The trace editor is closed. + */ + @Test + public void test4_07DeleteKeyboard() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + traceItem.select(); + fBot.activeShell().pressShortcut(Keystrokes.DELETE); + final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete"; + fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE)); + SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE); + shell.bot().button("Yes").click(); + fBot.waitUntil(Conditions.shellCloses(shell)); + fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null)); + fBot.waitUntil(new TraceDeletedCondition()); + } + + /** + * Test that the trace opens with double-click + *

+ * Action : Open Trace (double click) + *

+ * Procedure :Double-click a trace + *

+ * Expected Results: Trace is opened + * + * @throws WidgetNotFoundException + * when a widget is not found + */ + @Test + public void test4_08OpenDoubleClick() throws WidgetNotFoundException { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + traceItem.select(); + traceItem.doubleClick(); + + testEventsTable(TRACE_NAME); + testStatisticsView(); + fBot.closeAllEditors(); + } + + /** + * Test that the trace is brought to top if already opened + *

+ * Action : Open Trace (already open) + *

+ * Procedure :Open two traces. Open the first trace again. + *

+ * Expected Results: The first trace editor is simply brought to front. + */ + @Test + public void test4_09BringToTop() { + SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType()); + SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); + traceItem.select(); + traceItem.doubleClick(); + fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME)); + IEditorReference originalEditor = fBot.activeEditor().getReference(); + + createCopy(traceItem); + + SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME); + copiedItem.select(); + copiedItem.doubleClick(); + copiedItem.doubleClick(); + fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, RENAMED_TRACE_NAME)); + SWTBotUtils.delay(1000); + traceItem.select(); + traceItem.doubleClick(); + fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME)); + assertTrue(originalEditor == fBot.activeEditor().getReference()); + + fBot.closeAllEditors(); + SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); + } + + private static void createCopy(SWTBotTreeItem traceItem) { + traceItem.contextMenu().menu("Copy...").click(); + final String COPY_TRACE_DIALOG_TITLE = "Copy Trace"; + fBot.waitUntil(Conditions.shellIsActive(COPY_TRACE_DIALOG_TITLE)); + SWTBotShell shell = fBot.shell(COPY_TRACE_DIALOG_TITLE); + SWTBotText text = shell.bot().textWithLabel("New Trace name:"); + text.setText(RENAMED_TRACE_NAME); + shell.bot().button("OK").click(); + fBot.waitUntil(Conditions.shellCloses(shell)); + } + + private static void testEventsTable(String editorName) { + SWTBotEditor editor = SWTBotUtils.activeEventsEditor(fBot, editorName); + fBot.waitUntil(ConditionHelpers.numberOfEventsInTrace(TmfTraceManager.getInstance().getActiveTrace(), CUSTOM_TEXT_LOG.getNbEvents())); + + SWTBotTable table = editor.bot().table(); + fBot.waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + return table.rowCount() > 1; + } + + @Override + public String getFailureMessage() { + return "No items in table"; + } + }); + // Select first event (skip filter/search row) + table.getTableItem(1).select(); + + editor.bot().waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + return table.selection().rowCount() == 1 && table.selection().get(0).toString().contains(CUSTOM_TEXT_LOG.getFirstEventTimestamp()); + } + + @Override + public String getFailureMessage() { + return "First event not selected"; + } + }); + } + + private static void testStatisticsView() { + SWTBotUtils.openView(TmfStatisticsView.ID); + SWTBotView view = fBot.viewById(TmfStatisticsView.ID); + assertTrue(view.bot().tree().hasItems()); + view.bot().tree().cell(0, 1).equals(Long.toString(CUSTOM_TEXT_LOG.getNbEvents())); + } + + private final class TraceDeletedCondition extends DefaultCondition { + @Override + public boolean test() throws Exception { + return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME).findMember(new Path("Traces/" + TRACE_NAME)) == null; + } + + @Override + public String getFailureMessage() { + return TRACE_NAME + " was not deleted successfully."; + } + } +} diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestTraceInfo.java b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestTraceInfo.java new file mode 100644 index 0000000000..675ead742a --- /dev/null +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestTraceInfo.java @@ -0,0 +1,100 @@ +/****************************************************************************** + * Copyright (c) 2016 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 + *******************************************************************************/ + +package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer; + +/** + * A helper class to store information about a test trace. + */ +public class TestTraceInfo { + private final String fTraceName; + private final String fTracePath; + private final String fTraceType; + private final long fNbEvents; + private final String fFirstEventTimestamp; + + /** + * + * @param traceName + * the name of the trace + * @param traceType + * the trace type (Category with name format) + * @param nbEvents + * the number of events in the trace + * @param firstEventTimestamp + * he first event timestamp in string form. See + * {@link #getFirstEventTimestamp()} + */ + public TestTraceInfo(String traceName, String traceType, long nbEvents, String firstEventTimestamp) { + this(traceName, traceName, traceType, nbEvents, firstEventTimestamp); + } + + /** + * + * @param traceName + * the name of the trace + * @param tracePath + * the path of the trace. Whether or not this is absolute or + * relative is up to the client. + * @param traceType + * the trace type (Category with name format) + * @param nbEvents + * the number of events in the trace + * @param firstEventTimestamp + * he first event timestamp in string form. See + * {@link #getFirstEventTimestamp()} + */ + public TestTraceInfo(String traceName, String tracePath, String traceType, long nbEvents, String firstEventTimestamp) { + fTraceName = traceName; + fTracePath = tracePath; + fTraceType = traceType; + fNbEvents = nbEvents; + fFirstEventTimestamp = firstEventTimestamp; + } + + /** + * @return the name of the trace + */ + public String getTraceName() { + return fTraceName; + } + + /** + * @return the path of the trace. Whether or not this is absolute or relative is up to the client. + */ + public String getTracePath() { + return fTracePath; + } + + /** + * @return the trace type (Category with name format) + */ + public String getTraceType() { + return fTraceType; + } + + /** + * @return the number of events in the trace + */ + public long getNbEvents() { + return fNbEvents; + } + + /** + * The first event timestamp in string form. Tests use this to see if the + * cell contains this text (String.contains()). Since there can be timezone + * issues with hours and days, this value should only specify minutes and + * more precise digits. For example: 04:32.650 993 664 + * + * @return the first event timestamp in string form + */ + public String getFirstEventTimestamp() { + return fFirstEventTimestamp; + } +} \ No newline at end of file diff --git a/releng/org.eclipse.tracecompass.testing/feature.xml b/releng/org.eclipse.tracecompass.testing/feature.xml index 03917fcb2a..9b47b91411 100644 --- a/releng/org.eclipse.tracecompass.testing/feature.xml +++ b/releng/org.eclipse.tracecompass.testing/feature.xml @@ -215,4 +215,11 @@ version="0.0.0" unpack="false"/> + + diff --git a/releng/pom.xml b/releng/pom.xml index d319a999da..2766c408db 100644 --- a/releng/pom.xml +++ b/releng/pom.xml @@ -26,6 +26,7 @@ org.eclipse.tracecompass.alltests + org.eclipse.tracecompass.integration.swtbot.tests org.eclipse.tracecompass.releng-site org.eclipse.tracecompass.target org.eclipse.tracecompass.testing diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF index fd4c42285d..f4f683abb9 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/META-INF/MANIFEST.MF @@ -36,7 +36,6 @@ Import-Package: com.google.common.collect, org.swtchart Export-Package: org.eclipse.tracecompass.tmf.ui.swtbot.tests.parsers.custom;x-internal:=true, org.eclipse.tracecompass.tmf.ui.swtbot.tests.perspectives;x-internal:=true, - org.eclipse.tracecompass.tmf.ui.swtbot.tests.projectexplorer, org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared, org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;x-internal:=true, org.eclipse.tracecompass.tmf.ui.swtbot.tests.wizards;x-internal:=true diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/projectexplorer/ProjectExplorerTraceActionsTest.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/projectexplorer/ProjectExplorerTraceActionsTest.java deleted file mode 100644 index 5b2dec22cd..0000000000 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/projectexplorer/ProjectExplorerTraceActionsTest.java +++ /dev/null @@ -1,430 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2016 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 - *******************************************************************************/ - -package org.eclipse.tracecompass.tmf.ui.swtbot.tests.projectexplorer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Logger; -import org.apache.log4j.SimpleLayout; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; -import org.eclipse.swtbot.swt.finder.finders.ContextMenuFinder; -import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; -import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; -import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes; -import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; -import org.eclipse.swtbot.swt.finder.waits.Conditions; -import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; -import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; -import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; -import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView; -import org.eclipse.ui.IEditorReference; -import org.hamcrest.core.IsAnything; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.google.common.collect.ImmutableList; - -/** - * SWTBot test for testing Project Explorer Trace actions (context-menus, - * keyboard) - */ -@RunWith(SWTBotJunit4ClassRunner.class) -public class ProjectExplorerTraceActionsTest { - private static final String TRACE_PROJECT_NAME = "test"; - private static final String TRACE_NAME = "syslog_collapse"; - private static final String RENAMED_TRACE_NAME = TRACE_NAME + 2; - private static final String TRACE_PATH = "testfiles/" + TRACE_NAME; - private static final String 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(); - private static final long NB_EVENTS = 22; - - /** - * Test Class setup - */ - @BeforeClass - public static void init() { - SWTBotUtils.initialize(); - - /* set up test trace */ - URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TRACE_PATH), null); - URI uri; - try { - uri = FileLocator.toFileURL(location).toURI(); - fTestFile = new File(uri); - } catch (URISyntaxException | IOException e) { - e.printStackTrace(); - fail(); - } - - assertTrue(fTestFile.exists()); - - /* Set up for swtbot */ - SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ - SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; - fLogger.removeAllAppenders(); - fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); - fBot = new SWTWorkbenchBot(); - - /* Close welcome view */ - SWTBotUtils.closeView("Welcome", fBot); - - /* Switch perspectives */ - SWTBotUtils.switchToTracingPerspective(); - - /* Finish waiting for eclipse to load */ - SWTBotUtils.waitForJobs(); - SWTBotUtils.createProject(TRACE_PROJECT_NAME); - } - - /** - * Test class tear down method. - */ - @AfterClass - public static void tearDown() { - SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot); - fLogger.removeAllAppenders(); - } - - /** - * Test that the expected context menu items are there - *

- * Action : Trace menu - *

- * Procedure :Select an LTTng trace and open its context menu - *

- * Expected Results: Correct menu opens (Open , Copy, Rename, …) - * - */ - @Test - public void test4_01ContextMenuPresence() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - - final List EXPECTED_MENU_LABELS = ImmutableList.of( - "&Open\tShift+Ctrl+R", "Open With", "&Copy...\tCtrl+C", "Rena&me...\tF2", "&Delete\tDelete", "Delete &Supplementary Files...", "&Export Trace Package...", "Select &Trace Type...", "Apply Time Offset...", "Clear Time Offset", - "Refresh\tF5"); - - // TODO: SWTBot needs a better way to do this - ContextMenuFinder finder = new ContextMenuFinder(fBot.tree().widget); - List menuItems = finder.findMenus(traceItem.contextMenu().widget, new IsAnything<>(), false); - @NonNull - List menuLabels = menuItems.stream().map((item) -> { - return UIThreadRunnable.syncExec(() -> item.getText()); - }).collect(Collectors.toList()); - assertEquals(EXPECTED_MENU_LABELS, menuLabels); - - fBot.closeAllEditors(); - } - - /** - * Test that the trace opens with the context menu - *

- * Action : Open trace - *

- * Procedure :Select the Open menu - *

- * Expected Results: Trace is opened and views are populated - * - */ - @Test - public void test4_02Open() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - - traceItem.contextMenu().menu("Open").click(); - testEventsTable(TRACE_NAME); - testStatisticsView(); - fBot.closeAllEditors(); - } - - /** - * Test that the trace can be copied with the context menu - *

- * Action : Copy trace - *

- * Procedure :Select the Copy menu and provide a new name. Open. - *

- * Expected Results: Trace is replicated under the new name - * - */ - @Test - public void test4_03Copy() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - - createCopy(traceItem); - - fBot.closeAllEditors(); - SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME); - copiedItem.contextMenu().menu("Open").click(); - testEventsTable(RENAMED_TRACE_NAME); - fBot.closeAllEditors(); - SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); - } - - /** - * Test that the trace can be renamed with the context menu - *

- * Action : Rename trace - *

- * Procedure :Select the Rename menu and provide a new name. Reopen. - *

- * Expected Results: Trace is renamed. The trace editor is closed. - */ - @Test - public void test4_04Rename() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - - traceItem.contextMenu().menu("Rename...").click(); - final String RENAME_TRACE_DIALOG_TITLE = "Rename Trace"; - fBot.waitUntil(Conditions.shellIsActive(RENAME_TRACE_DIALOG_TITLE)); - SWTBotShell shell = fBot.shell(RENAME_TRACE_DIALOG_TITLE); - SWTBotText text = shell.bot().textWithLabel("New Trace name:"); - text.setText(RENAMED_TRACE_NAME); - shell.bot().button("OK").click(); - fBot.waitUntil(Conditions.shellCloses(shell)); - fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null)); - - SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME); - copiedItem.contextMenu().menu("Open").click(); - testEventsTable(RENAMED_TRACE_NAME); - fBot.closeAllEditors(); - SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); - } - - /** - * Test that the trace can be deleted with the context menu - *

- * Action : Delete trace - *

- * Procedure :Select the Delete menu and confirm deletion - *

- * Expected Results: Trace is deleted. The trace editor is closed. - * - */ - @Test - public void test4_05Delete() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - - traceItem.contextMenu().menu("Delete").click(); - final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete"; - fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE)); - SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE); - shell.bot().button("Yes").click(); - fBot.waitUntil(Conditions.shellCloses(shell)); - fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null)); - fBot.waitUntil(new TraceDeletedCondition()); - } - - /** - * Test that the trace opens with the keyboard - *

- * Action : Open Trace (Accelerator) - *

- * Procedure :Select trace and press Enter - *

- * Expected Results: Trace is opened - * - * - * @throws WidgetNotFoundException - * when a widget is not found - */ - @Test - public void test4_06OpenKeyboard() throws WidgetNotFoundException { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - traceItem.select(); - fBot.activeShell().pressShortcut(Keystrokes.CR); - - testEventsTable(TRACE_NAME); - testStatisticsView(); - fBot.closeAllEditors(); - } - - /** - * Test that the trace can be deleted with the keyboard - *

- * Action : Delete Trace (Accelerator) - *

- * Procedure :Select trace and press Delete and confirm deletion - *

- * Expected Results: Trace is deleted. The trace editor is closed. - */ - @Test - public void test4_07DeleteKeyboard() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - traceItem.select(); - fBot.activeShell().pressShortcut(Keystrokes.DELETE); - final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete"; - fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE)); - SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE); - shell.bot().button("Yes").click(); - fBot.waitUntil(Conditions.shellCloses(shell)); - fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null)); - fBot.waitUntil(new TraceDeletedCondition()); - } - - /** - * Test that the trace opens with double-click - *

- * Action : Open Trace (double click) - *

- * Procedure :Double-click a trace - *

- * Expected Results: Trace is opened - * - * @throws WidgetNotFoundException - * when a widget is not found - */ - @Test - public void test4_08OpenDoubleClick() throws WidgetNotFoundException { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - traceItem.select(); - traceItem.doubleClick(); - - testEventsTable(TRACE_NAME); - testStatisticsView(); - fBot.closeAllEditors(); - } - - /** - * Test that the trace is brought to top if already opened - *

- * Action : Open Trace (already open) - *

- * Procedure :Open two traces. Open the first trace again. - *

- * Expected Results: The first trace editor is simply brought to front. - */ - @Test - public void test4_09BringToTop() { - SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE); - SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME); - traceItem.select(); - traceItem.doubleClick(); - fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME)); - IEditorReference originalEditor = fBot.activeEditor().getReference(); - - createCopy(traceItem); - - SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME); - copiedItem.select(); - copiedItem.doubleClick(); - copiedItem.doubleClick(); - fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, RENAMED_TRACE_NAME)); - SWTBotUtils.delay(1000); - traceItem.select(); - traceItem.doubleClick(); - fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME)); - assertTrue(originalEditor == fBot.activeEditor().getReference()); - - fBot.closeAllEditors(); - SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); - } - - private static void createCopy(SWTBotTreeItem traceItem) { - traceItem.contextMenu().menu("Copy...").click(); - final String COPY_TRACE_DIALOG_TITLE = "Copy Trace"; - fBot.waitUntil(Conditions.shellIsActive(COPY_TRACE_DIALOG_TITLE)); - SWTBotShell shell = fBot.shell(COPY_TRACE_DIALOG_TITLE); - SWTBotText text = shell.bot().textWithLabel("New Trace name:"); - text.setText(RENAMED_TRACE_NAME); - shell.bot().button("OK").click(); - fBot.waitUntil(Conditions.shellCloses(shell)); - } - - private static void testEventsTable(String editorName) { - SWTBotEditor editor = SWTBotUtils.activeEventsEditor(fBot, editorName); - fBot.waitUntil(ConditionHelpers.numberOfEventsInTrace(TmfTraceManager.getInstance().getActiveTrace(), NB_EVENTS)); - - SWTBotTable table = editor.bot().table(); - fBot.waitUntil(new DefaultCondition() { - @Override - public boolean test() throws Exception { - return table.rowCount() > 1; - } - - @Override - public String getFailureMessage() { - return "No items in table"; - } - }); - // Select first event (skip filter/search row) - table.getTableItem(1).select(); - - editor.bot().waitUntil(new DefaultCondition() { - @Override - public boolean test() throws Exception { - return table.selection().rowCount() == 1 && table.selection().get(0).toString().contains("01:01"); - } - - @Override - public String getFailureMessage() { - return "First event not selected"; - } - }); - } - - private static void testStatisticsView() { - SWTBotUtils.openView(TmfStatisticsView.ID); - SWTBotView view = fBot.viewById(TmfStatisticsView.ID); - assertTrue(view.bot().tree().hasItems()); - view.bot().tree().cell(0, 1).equals(Long.toString(NB_EVENTS)); - } - - private final class TraceDeletedCondition extends DefaultCondition { - @Override - public boolean test() throws Exception { - return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME).findMember(new Path("Traces/" + TRACE_NAME)) == null; - } - - @Override - public String getFailureMessage() { - return TRACE_NAME + " was not deleted successfully."; - } - } -}