From a028e224425ca8602278d1071fd47fd316354cf6 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Mon, 5 Apr 2021 09:28:47 -0400 Subject: [PATCH] Bug 572593: reenable disabled meson tests Upgrade the tests to JUnit5 so they can be marked as flaky and slow. Also removed a bunch of unused code. This partially reverts commit 8220215a2e35334b16ef48c76e9c9e33ba03d07e. Reason for revert: These tests were "temporarily" disabled a while ago as part of the JIRO migration in Bug 545624. Change-Id: I111cf4d9d9f5e07e49074ca2355a3d1f52fb1070 --- .../META-INF/MANIFEST.MF | 5 +- .../ui/tests/AutomatedIntegrationSuite.java | 23 - .../meson/ui/tests/NewManualNinjaTest.java | 42 +- .../meson/ui/tests/NewMesonConfigureTest.java | 41 +- .../meson/ui/tests/NewMesonProjectTest.java | 41 +- .../meson/ui/tests/utils/CloseShellRule.java | 59 --- ...comePageRule.java => CloseWelcomePag.java} | 22 +- .../meson/ui/tests/utils/ConsoleViewRule.java | 39 -- .../tests/utils/ProjectExplorerViewRule.java | 52 -- .../meson/ui/tests/utils/SWTBotViewRule.java | 68 --- .../meson/ui/tests/utils/SWTUtils.java | 471 ------------------ .../meson/ui/tests/utils/TestLoggerRule.java | 29 -- 12 files changed, 72 insertions(+), 820 deletions(-) delete mode 100644 build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/AutomatedIntegrationSuite.java delete mode 100644 build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseShellRule.java rename build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/{CloseWelcomePageRule.java => CloseWelcomePag.java} (76%) delete mode 100644 build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ConsoleViewRule.java delete mode 100644 build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ProjectExplorerViewRule.java delete mode 100644 build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTBotViewRule.java delete mode 100644 build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/TestLoggerRule.java diff --git a/build/org.eclipse.cdt.meson.ui.tests/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.meson.ui.tests/META-INF/MANIFEST.MF index 705bc164367..7b9273943cd 100644 --- a/build/org.eclipse.cdt.meson.ui.tests/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.meson.ui.tests/META-INF/MANIFEST.MF @@ -8,7 +8,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.cdt.meson.core;bundle-version="1.0.0", org.eclipse.cdt.meson.ui;bundle-version="1.0.0", org.eclipse.swtbot.junit4_x;bundle-version="2.6.0", - org.junit, org.eclipse.cdt.core, org.eclipse.swtbot.eclipse.finder, org.eclipse.core.resources, @@ -21,6 +20,8 @@ Require-Bundle: org.eclipse.cdt.meson.core;bundle-version="1.0.0", org.eclipse.ui.console;bundle-version="3.8.0", org.eclipse.ui.views;bundle-version="3.9.100", org.eclipse.ui.views.properties.tabbed;bundle-version="3.8.100" -Import-Package: org.assertj.core.api;version="1.7.1" +Import-Package: org.assertj.core.api;version="1.7.1", + org.junit.jupiter.api;version="5.7.1", + org.junit.jupiter.api.extension;version="5.7.1" Automatic-Module-Name: org.eclipse.cdt.meson.ui.tests Bundle-Localization: plugin diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/AutomatedIntegrationSuite.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/AutomatedIntegrationSuite.java deleted file mode 100644 index 103de2cdf54..00000000000 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/AutomatedIntegrationSuite.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2018 QNX Software Systems and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc. - modified for use in Meson testing - *******************************************************************************/ -package org.eclipse.cdt.internal.meson.ui.tests; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ NewMesonProjectTest.class, NewMesonConfigureTest.class, NewManualNinjaTest.class }) -public class AutomatedIntegrationSuite { - -} diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewManualNinjaTest.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewManualNinjaTest.java index f57ee012252..637ada6637a 100644 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewManualNinjaTest.java +++ b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewManualNinjaTest.java @@ -13,18 +13,19 @@ *******************************************************************************/ package org.eclipse.cdt.internal.meson.ui.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.List; +import java.util.concurrent.TimeUnit; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.meson.ui.tests.utils.CloseWelcomePageRule; +import org.eclipse.cdt.internal.meson.ui.tests.utils.CloseWelcomePag; import org.eclipse.cdt.meson.core.MesonNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; @@ -39,26 +40,24 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.ExtendWith; -@SuppressWarnings("nls") -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Ignore +@TestMethodOrder(MethodName.class) +@ExtendWith(CloseWelcomePag.class) +@Tag("flakyTest"/*BaseTestCase5.FLAKY_TEST_TAG*/) +@Tag("slowTest"/*BaseTestCase5.SLOW_TEST_TAG*/) public class NewManualNinjaTest { private static SWTWorkbenchBot bot; - @ClassRule - public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule( - CloseWelcomePageRule.CDT_PERSPECTIVE_ID); - - @BeforeClass + @BeforeAll public static void beforeClass() { SWTBotPreferences.TIMEOUT = 50000; SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; @@ -66,12 +65,13 @@ public class NewManualNinjaTest { bot = new SWTWorkbenchBot(); } - @Before + @BeforeEach public void before() { bot.resetWorkbench(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 2, unit = TimeUnit.MINUTES) public void addNewMesonProject() throws Exception { // open C++ perspective if (!"C/C++".equals(bot.activePerspective().getLabel())) { diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonConfigureTest.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonConfigureTest.java index 6fd1354b93e..e14fb92b57b 100644 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonConfigureTest.java +++ b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonConfigureTest.java @@ -14,15 +14,17 @@ package org.eclipse.cdt.internal.meson.ui.tests; import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.concurrent.TimeUnit; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.meson.ui.tests.utils.CloseWelcomePageRule; +import org.eclipse.cdt.internal.meson.ui.tests.utils.CloseWelcomePag; import org.eclipse.cdt.meson.core.MesonNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; @@ -36,26 +38,24 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.ExtendWith; -@SuppressWarnings("nls") -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Ignore +@TestMethodOrder(MethodName.class) +@ExtendWith(CloseWelcomePag.class) +@Tag("flakyTest"/*BaseTestCase5.FLAKY_TEST_TAG*/) +@Tag("slowTest"/*BaseTestCase5.SLOW_TEST_TAG*/) public class NewMesonConfigureTest { private static SWTWorkbenchBot bot; - @ClassRule - public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule( - CloseWelcomePageRule.CDT_PERSPECTIVE_ID); - - @BeforeClass + @BeforeAll public static void beforeClass() { SWTBotPreferences.TIMEOUT = 50000; SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; @@ -63,12 +63,13 @@ public class NewMesonConfigureTest { bot = new SWTWorkbenchBot(); } - @Before + @BeforeEach public void before() { bot.resetWorkbench(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 2, unit = TimeUnit.MINUTES) public void addNewMesonProject() throws Exception { // open C++ perspective if (!"C/C++".equals(bot.activePerspective().getLabel())) { diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonProjectTest.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonProjectTest.java index 468539f1030..5019e71e0fd 100644 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonProjectTest.java +++ b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/NewMesonProjectTest.java @@ -14,15 +14,17 @@ package org.eclipse.cdt.internal.meson.ui.tests; import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.concurrent.TimeUnit; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.internal.meson.ui.tests.utils.CloseWelcomePageRule; +import org.eclipse.cdt.internal.meson.ui.tests.utils.CloseWelcomePag; import org.eclipse.cdt.meson.core.MesonNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; @@ -36,26 +38,24 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem; import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer.MethodName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.ExtendWith; -@SuppressWarnings("nls") -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Ignore +@TestMethodOrder(MethodName.class) +@ExtendWith(CloseWelcomePag.class) +@Tag("flakyTest"/*BaseTestCase5.FLAKY_TEST_TAG*/) +@Tag("slowTest"/*BaseTestCase5.SLOW_TEST_TAG*/) public class NewMesonProjectTest { private static SWTWorkbenchBot bot; - @ClassRule - public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule( - CloseWelcomePageRule.CDT_PERSPECTIVE_ID); - - @BeforeClass + @BeforeAll public static void beforeClass() { SWTBotPreferences.TIMEOUT = 50000; SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; @@ -63,12 +63,13 @@ public class NewMesonProjectTest { bot = new SWTWorkbenchBot(); } - @Before + @BeforeEach public void before() { bot.resetWorkbench(); } - @Test(timeout = 120000) + @Test + @Timeout(value = 2, unit = TimeUnit.MINUTES) public void addNewMesonProject() throws Exception { // open C++ perspective if (!"C/C++".equals(bot.activePerspective().getLabel())) { diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseShellRule.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseShellRule.java deleted file mode 100644 index 2bda34a4587..00000000000 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseShellRule.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Red Hat. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat - Initial Contribution - *******************************************************************************/ - -package org.eclipse.cdt.internal.meson.ui.tests.utils; - -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; -import org.eclipse.ui.PlatformUI; -import org.junit.rules.ExternalResource; - -/** - * Closes the wizard(s) after each test, if the "Cancel" button is available - */ -public class CloseShellRule extends ExternalResource { - - private final String buttonLabel; - - public CloseShellRule(final String buttonLabel) { - this.buttonLabel = buttonLabel; - } - - @Override - protected void after() { - final SWTWorkbenchBot bot = new SWTWorkbenchBot(); - try { - while (isInDialog(bot) && getButton(bot, this.buttonLabel) != null) { - getButton(bot, this.buttonLabel).click(); - } - - } catch (WidgetNotFoundException e) { - // ignoring - } - } - - private static boolean isInDialog(final SWTWorkbenchBot bot) { - final SWTBotShell activeShell = bot.activeShell(); - final String text = SWTUtils - .syncExec(() -> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getText()); - final String shellText = activeShell.getText(); - return text != null && !text.equals(shellText); - } - - private static SWTBotButton getButton(final SWTWorkbenchBot bot, final String buttonLabel) { - return bot.button(buttonLabel); - } -} diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseWelcomePageRule.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseWelcomePag.java similarity index 76% rename from build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseWelcomePageRule.java rename to build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseWelcomePag.java index a7f214d559d..c286684fe70 100644 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseWelcomePageRule.java +++ b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/CloseWelcomePag.java @@ -19,35 +19,25 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.WorkbenchException; -import org.junit.rules.ExternalResource; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; /** * Closes the Welcome page and optionally opens a given perspective */ -public class CloseWelcomePageRule extends ExternalResource { - - public static final String DOCKER_PERSPECTIVE_ID = "org.eclipse.linuxtools.docker.ui.perspective"; +public class CloseWelcomePag implements BeforeEachCallback { public static final String CDT_PERSPECTIVE_ID = "org.eclipse.cdt.ui.CPerspective"; - public static final String JAVA_PERSPECTIVE_ID = "org.eclipse.jdt.ui.JavaPerspective"; - /** the Id of the perspective to open. */ private final String defaultPerspectiveId; - /** - * Custom constructor with the id of the perspective to open once the - * welcome page was closed. - * - * @param perspectiveId - * the id of the perspective to open. - */ - public CloseWelcomePageRule(final String perspectiveId) { - this.defaultPerspectiveId = perspectiveId; + public CloseWelcomePag() { + this.defaultPerspectiveId = CloseWelcomePag.CDT_PERSPECTIVE_ID; } @Override - protected void before() { + public void beforeEach(ExtensionContext context) throws Exception { Display.getDefault().syncExec(() -> { final IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench.getIntroManager().getIntro() != null) { diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ConsoleViewRule.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ConsoleViewRule.java deleted file mode 100644 index 7a64cc93b15..00000000000 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ConsoleViewRule.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Red Hat. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat - Initial Contribution - *******************************************************************************/ - -package org.eclipse.cdt.internal.meson.ui.tests.utils; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.ui.console.IConsoleConstants; -import org.junit.rules.ExternalResource; - -/** - * An {@link ExternalResource} to close the Console view. - */ -public class ConsoleViewRule extends ExternalResource { - - @Override - protected void before() { - Display.getDefault().syncExec(() -> { - final SWTBotView consoleView = SWTUtils.getSWTBotView(new SWTWorkbenchBot(), - IConsoleConstants.ID_CONSOLE_VIEW); - if (consoleView != null) { - consoleView.close(); - } - }); - } - -} diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ProjectExplorerViewRule.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ProjectExplorerViewRule.java deleted file mode 100644 index 99933555779..00000000000 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/ProjectExplorerViewRule.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Red Hat. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat - Initial Contribution - *******************************************************************************/ - -package org.eclipse.cdt.internal.meson.ui.tests.utils; - -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.junit.Rule; -import org.junit.rules.ExternalResource; - -/** - * A JUnit {@link Rule} to open the Project Explorer view. - */ -public class ProjectExplorerViewRule extends ExternalResource { - - private SWTBotView projectExplorerBotView; - - public static final String PROJECT_EXPLORER_VIEW_ID = "org.eclipse.ui.navigator.ProjectExplorer"; - - @Override - protected void before() { - final SWTWorkbenchBot bot = new SWTWorkbenchBot(); - SWTUtils.syncExec(() -> { - try { - return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .showView(PROJECT_EXPLORER_VIEW_ID); - } catch (PartInitException e) { - e.printStackTrace(); - return null; - } - }); - this.projectExplorerBotView = bot.viewById(PROJECT_EXPLORER_VIEW_ID); - this.projectExplorerBotView.setFocus(); - } - - public SWTBotView getProjectExplorerBotView() { - return this.projectExplorerBotView; - } -} diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTBotViewRule.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTBotViewRule.java deleted file mode 100644 index 42ed786baff..00000000000 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTBotViewRule.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Red Hat. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat - Initial Contribution - *******************************************************************************/ - -package org.eclipse.cdt.internal.meson.ui.tests.utils; - -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.PlatformUI; -import org.junit.Assert; -import org.junit.rules.ExternalResource; - -/** - * - */ -public class SWTBotViewRule extends ExternalResource { - - private final SWTWorkbenchBot bot = new SWTWorkbenchBot(); - - private final String viewId; - - private SWTBotView botView = null; - - private IViewPart view = null; - - public SWTBotViewRule(final String viewId) { - this.viewId = viewId; - } - - @Override - protected void before() { - SWTUtils.asyncExec(() -> { - try { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(this.viewId); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail("Failed to open view with id '" + this.viewId + "': " + e.getMessage()); - } - }); - this.botView = this.bot.viewById(this.viewId); - this.botView.show(); - this.view = this.botView.getViewReference().getView(true); - } - - public SWTBotView bot() { - return this.botView; - } - - @SuppressWarnings("unchecked") - public T view() { - return (T) view; - } - - public void close() { - this.botView.close(); - } -} diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTUtils.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTUtils.java index faf04a9e62b..dda4d836f16 100644 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTUtils.java +++ b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/SWTUtils.java @@ -13,47 +13,11 @@ *******************************************************************************/ package org.eclipse.cdt.internal.meson.ui.tests.utils; -import static org.assertj.core.api.Assertions.fail; - -import java.util.List; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.TimeUnit; import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTException; -import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; -import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; -import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; -import org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper; -import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; -import org.eclipse.swtbot.swt.finder.results.Result; -import org.eclipse.swtbot.swt.finder.results.VoidResult; -import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; -import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.eclipse.ui.console.IConsoleConstants; -import org.eclipse.ui.progress.UIJob; -import org.junit.Assert; -import org.junit.ComparisonFailure; /** * Utility class for SWT @@ -73,439 +37,4 @@ public class SWTUtils { Display.getDefault().syncExec(() -> result.add(supplier.get())); return result.poll(); } - - /** - * Executes synchronously the given {@link Runnable} in the - * default Display - * - * @param runnable - * the {@link Runnable} to execute - */ - public static void syncExec(final Runnable runnable) { - Display.getDefault().syncExec(runnable); - } - - /** - * Executes synchronously the given {@link Runnable} in the - * default Display. The given {@link Runnable} is ran into a rapping - * {@link Runnable} that will catch the {@link ComparisonFailure} that may - * be raised during an assertion. - * - * @param runnable - * the {@link Runnable} to execute - * @throws ComparisonFailure - * if an assertion failed. - * @throws SWTException - * if an {@link SWTException} occurred - */ - public static void syncAssert(final Runnable runnable) throws SWTException, ComparisonFailure { - final Queue failure = new ArrayBlockingQueue<>(1); - final Queue swtException = new ArrayBlockingQueue<>(1); - Display.getDefault().syncExec(() -> { - try { - runnable.run(); - } catch (ComparisonFailure e1) { - failure.add(e1); - } catch (SWTException e2) { - swtException.add(e2); - } - }); - if (!failure.isEmpty()) { - throw failure.poll(); - } - if (!swtException.isEmpty()) { - throw swtException.poll(); - } - } - - /** - * Executes the given {@link Runnable} asynchronously in - * the default {@link Display} and waits until all jobs are done before - * completing. - * - * @param runnable - * @throws InterruptedException - */ - public static void asyncExec(final Runnable runnable) { - asyncExec(runnable, true); - } - - /** - * Executes the given {@link Runnable} asynchronously in - * the default {@link Display} and waits until all jobs are done before - * completing. - * - * @param runnable - * the {@link Runnable} to execute - * @param waitForJobsToComplete - * boolean flag to indicate if the method should wait for all - * jobs to complete before finishing - * @throws InterruptedException - */ - public static void asyncExec(final Runnable runnable, final boolean waitForJobsToComplete) { - final Queue failure = new ArrayBlockingQueue<>(1); - final Queue swtException = new ArrayBlockingQueue<>(1); - Display.getDefault().asyncExec(() -> { - try { - runnable.run(); - } catch (ComparisonFailure e1) { - failure.add(e1); - } catch (SWTException e2) { - swtException.add(e2); - } - }); - if (waitForJobsToComplete) { - waitForJobsToComplete(); - } - if (!failure.isEmpty()) { - throw failure.poll(); - } - if (!swtException.isEmpty()) { - throw swtException.poll(); - } - } - - /** - * Waits for all {@link Job} to complete. - * - * @throws InterruptedException - */ - public static void waitForJobsToComplete() { - wait(1, TimeUnit.SECONDS); - while (!Job.getJobManager().isIdle()) { - wait(1, TimeUnit.SECONDS); - } - } - - /** - * @param viewBot - * the {@link SWTBotView} containing the {@link Tree} to traverse - * @param paths - * the node path in the {@link SWTBotTree} associated with the - * given {@link SWTBotView} - * @return the first {@link SWTBotTreeItem} matching the given node names - */ - public static SWTBotTreeItem getTreeItem(final SWTBotView viewBot, final String... paths) { - final SWTBotTree tree = viewBot.bot().tree(); - return getTreeItem(tree.getAllItems(), paths); - } - - /** - * - * @param parentTreeItem - * the parent tree item from which to start - * @param paths - * the relative path to the item to return - * @return the {@link SWTBotTreeItem} that matches the given path from the - * given parent tree item - */ - public static SWTBotTreeItem getTreeItem(final SWTBotTreeItem parentTreeItem, final String... paths) { - if (paths.length == 1) { - return getTreeItem(parentTreeItem, paths[0]); - } - final String[] remainingPaths = new String[paths.length - 1]; - System.arraycopy(paths, 1, remainingPaths, 0, paths.length - 1); - return getTreeItem(getTreeItem(parentTreeItem, paths[0]), remainingPaths); - } - - /** - * Returns the first child node in the given parent tree item whose text - * matches (ie, begins with) the given path argument. - * - * @param parentTree - * the parent tree item - * @param path - * the text of the node that should match - * @return the first matching node or null if none could be - * found - */ - public static SWTBotTreeItem getTreeItem(final SWTBotTree parentTree, final String path) { - for (SWTBotTreeItem child : parentTree.getAllItems()) { - if (child.getText().startsWith(path)) { - return child; - } - } - return null; - } - - /** - * Returns the first child node in the given parent tree item whose text - * matches (ie, begins with) the given path argument. - * - * @param parentTreeItem - * the parent tree item - * @param path - * the text of the node that should match - * @return the first matching node or null if none could be - * found - */ - public static SWTBotTreeItem getTreeItem(final SWTBotTreeItem parentTreeItem, final String path) { - for (SWTBotTreeItem child : parentTreeItem.getItems()) { - if (child.getText().startsWith(path)) { - return child; - } - } - return null; - } - - private static SWTBotTreeItem getTreeItem(final SWTBotTreeItem[] treeItems, final String[] paths) { - final SWTBotTreeItem swtBotTreeItem = Stream.of(treeItems).filter(item -> item.getText().startsWith(paths[0])) - .findFirst().orElseThrow(() -> new RuntimeException("Only available items: " - + Stream.of(treeItems).map(item -> item.getText()).collect(Collectors.joining(", ")))); - if (paths.length > 1) { - syncExec(() -> swtBotTreeItem.expand()); - final String[] remainingPath = new String[paths.length - 1]; - System.arraycopy(paths, 1, remainingPath, 0, remainingPath.length); - return getTreeItem(swtBotTreeItem.getItems(), remainingPath); - } - return swtBotTreeItem; - } - - public static SWTBotTableItem getListItem(final SWTBotTable table, final String name) { - return Stream.iterate(0, i -> i + 1).limit(table.rowCount()).map(rowNumber -> table.getTableItem(rowNumber)) - .filter(rowItem -> { - return Stream.iterate(0, j -> j + 1).limit(table.columnCount()) - .map(colNum -> rowItem.getText(colNum)).anyMatch(colValue -> colValue.contains(name)); - }).findFirst().orElse(null); - } - - /** - * Waits for the given duration - * - * @param duration - * the duration - * @param unit - * the duration unit - */ - public static void wait(final int duration, final TimeUnit unit) { - try { - Thread.sleep(unit.toMillis(duration)); - } catch (InterruptedException e) { - fail("Failed to wait for a " + unit.toMillis(duration) + "ms", e); - } - } - - /** - * Selects all child items in the given - * parentTreeItem whose labels match the given - * items. - * - * @param parentTreeItem - * the parent tree item - * @param matchItems - * the items to select - * @return - */ - public static SWTBotTreeItem select(final SWTBotTreeItem parentTreeItem, final String... matchItems) { - final List fullyQualifiedItems = Stream.of(parentTreeItem.getItems()).filter( - treeItem -> Stream.of(matchItems).anyMatch(matchItem -> treeItem.getText().startsWith(matchItem))) - .map(item -> item.getText()).collect(Collectors.toList()); - return parentTreeItem.select(fullyQualifiedItems.toArray(new String[0])); - } - - /** - * Selects all child items in the given - * parentTreeItem whose labels match the given - * items. - * - * @param parentTree - * the parent tree - * @param matchItems - * the items to select - * @return - */ - public static SWTBotTree select(final SWTBotTree parentTree, final String... matchItems) { - final List fullyQualifiedItems = Stream.of(parentTree.getAllItems()).filter( - treeItem -> Stream.of(matchItems).anyMatch(matchItem -> treeItem.getText().startsWith(matchItem))) - .map(item -> item.getText()).collect(Collectors.toList()); - return parentTree.select(fullyQualifiedItems.toArray(new String[0])); - } - - /** - * Selects the given treeItem whose labels match the given - * items. - * - * @param treeItem - * the parent tree item - * @param matchItems - * the items to select - */ - public static void select(SWTBotTreeItem treeItem) { - treeItem.select(); - } - - /** - * @param tree - * the root {@link SWTBotTree} - * @param path - * the path for the menu - * @return the child {@link SWTBotMenu} named with the first item in the - * given path from the given {@link SWTBotTree} - */ - public static SWTBotMenu getContextMenu(final SWTBotTree tree, String... path) { - final SWTBotMenu contextMenu = tree.contextMenu(path[0]); - if (contextMenu == null) { - Assert.fail("Failed to find context menu '" + path[0] + "'."); - } - if (path.length == 1) { - return contextMenu; - } - final String[] remainingPath = new String[path.length - 1]; - System.arraycopy(path, 1, remainingPath, 0, remainingPath.length); - return getSubMenu(contextMenu, remainingPath); - } - - /** - * Hides the menu for the given tree - * - * @param tree - * the tree whose {@link Menu} should be hidden - */ - public static void hideMenu(final SWTBotTree tree) { - try { - final Menu menu = UIThreadRunnable.syncExec((Result) () -> tree.widget.getMenu()); - UIThreadRunnable.syncExec(new VoidResult() { - - @Override - public void run() { - hide(menu); - } - - private void hide(final Menu menu) { - menu.notifyListeners(SWT.Hide, new Event()); - if (menu.getParentMenu() != null) { - hide(menu.getParentMenu()); - } - } - }); - } catch (WidgetNotFoundException e) { - // ignore if widget is not found, that's probably because there's no - // tree in the - // Docker Explorer view for the test that just ran. - } - } - - /** - * @param menu - * the parent menu - * @param path - * the path for the menu - * @return the child {@link SWTBotMenu} named with the first item in the - * given path from the given {@link SWTBotMenu} - */ - public static SWTBotMenu getSubMenu(final SWTBotMenu menu, String... path) { - final SWTBotMenu subMenu = menu.menu(path[0]); - if (subMenu == null) { - Assert.fail("Failed to find submenu '" + path[0] + "'."); - } - if (path.length == 1) { - return subMenu; - } - final String[] remainingPath = new String[path.length - 1]; - System.arraycopy(path, 1, remainingPath, 0, remainingPath.length); - return getSubMenu(subMenu, remainingPath); - } - - public static SWTBotTreeItem expand(final SWTBotTree tree, final String... paths) { - final SWTBotTreeItem rootItem = getTreeItem(tree, paths[0]); - expandTreeItem(rootItem); - if (paths.length > 1) { - final String[] remainingPath = new String[paths.length - 1]; - System.arraycopy(paths, 1, remainingPath, 0, remainingPath.length); - return expand(rootItem, remainingPath); - } - return rootItem; - } - - public static SWTBotTreeItem expand(final SWTBotTreeItem treeItem, final String... paths) { - final SWTBotTreeItem childItem = getTreeItem(treeItem, paths[0]); - expandTreeItem(childItem); - if (paths.length > 1) { - final String[] remainingPath = new String[paths.length - 1]; - System.arraycopy(paths, 1, remainingPath, 0, remainingPath.length); - return expand(childItem, remainingPath); - } - return getTreeItem(treeItem, paths[0]); - } - - private static SWTBotTreeItem expandTreeItem(final SWTBotTreeItem treeItem) { - final UIJob expandJob = new UIJob("expanding tree") { - - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - treeItem.expand(); - return Status.OK_STATUS; - } - }; - expandJob.addJobChangeListener(new JobChangeAdapter() { - @Override - public void done(IJobChangeEvent event) { - final int maxAttempts = 30; - int currentAttempt = 0; - while (currentAttempt < maxAttempts && treeItem.getItems().length == 1 - && treeItem.getItems()[0].getText().isEmpty()) { - SWTUtils.wait(1, TimeUnit.SECONDS); - currentAttempt++; - } - - } - }); - expandJob.schedule(); - SWTUtils.wait(1, TimeUnit.SECONDS); - return treeItem; - } - - public static SWTBotView getSWTBotView(final SWTWorkbenchBot bot, final String viewId) { - return bot.views().stream().filter(v -> v.getViewReference().getId().equals(viewId)).findFirst().orElse(null); - } - - @SuppressWarnings("unchecked") - public static T getView(final SWTWorkbenchBot bot, final String viewId) { - return (T) getView(bot, viewId, false); - } - - @SuppressWarnings("unchecked") - public static T getView(final SWTWorkbenchBot bot, final String viewId, final boolean restore) { - final SWTBotView viewBot = bot.viewById(viewId); - viewBot.setFocus(); - return (T) viewBot.getReference().getView(restore); - } - - /** - * @return true if the Console view is visible in the active - * page, false otherwise. - * @throws InterruptedException - */ - public static boolean isConsoleViewVisible(final SWTWorkbenchBot bot) { - return bot.views().stream() - .anyMatch(v -> v.getViewReference().getId().equals(IConsoleConstants.ID_CONSOLE_VIEW)); - } - - public static SWTBotToolbarButton getConsoleToolbarButtonWithTooltipText(final SWTWorkbenchBot bot, - final String tooltipText) { - return bot.viewById(IConsoleConstants.ID_CONSOLE_VIEW).getToolbarButtons().stream() - .filter(button -> button.getToolTipText().equals(tooltipText)).findFirst().get(); - } - - public static void closeView(final SWTWorkbenchBot bot, final String viewId) { - bot.views().stream().filter(v -> v.getReference().getId().equals(viewId)).forEach(v -> v.close()); - } - - /** - * Creates a new {@link SWTBotMenu} from the context. This avoids some - * unexpected "Widget is disposed" errors. - * - * @param bot - * the bot - * @param menuName - * the name of the menu to find - * @return the context menu - * @see Eclipse - * forum - */ - public static SWTBotMenu getContextMenu(final AbstractSWTBot bot, final String menuName) { - return new SWTBotMenu(ContextMenuHelper.contextMenu(bot, menuName)); - } - } diff --git a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/TestLoggerRule.java b/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/TestLoggerRule.java deleted file mode 100644 index 663f77a0d7c..00000000000 --- a/build/org.eclipse.cdt.meson.ui.tests/src/org/eclipse/cdt/internal/meson/ui/tests/utils/TestLoggerRule.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Red Hat. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat - Initial Contribution - *******************************************************************************/ - -package org.eclipse.cdt.internal.meson.ui.tests.utils; - -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; - -/** - * - */ -public class TestLoggerRule extends TestWatcher { - - @Override - protected void starting(final Description description) { - System.out.println("Starting " + description.getClassName() + "." + description.getMethodName()); - } -}