diff --git a/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModLSP4JakartaTest.java b/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModLSP4JakartaTest.java new file mode 100644 index 000000000..5422ddd28 --- /dev/null +++ b/src/test/java/io/openliberty/tools/intellij/it/MavenSingleModLSP4JakartaTest.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2023, 2025 IBM Corporation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package io.openliberty.tools.intellij.it; + +import org.junit.jupiter.api.BeforeAll; + +import java.nio.file.Paths; + +public class MavenSingleModLSP4JakartaTest extends SingleModJakartaLSTestCommon { + + /** + * Application Name + */ + public static String PROJECT_NAME = "jakarta-sample"; + + /** + * The path to the folder containing the test projects. + */ + public static String PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "maven").toAbsolutePath().toString(); + + /** + * Application resoruce URL. + */ + public MavenSingleModLSP4JakartaTest() { + super(PROJECT_NAME, PROJECTS_PATH); + } + + /** + * Prepares the environment for test execution. + */ + @BeforeAll + public static void setup() { + prepareEnv(PROJECTS_PATH, PROJECT_NAME); + } +} diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java index 73eadc194..cd28acc7a 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023, 2024 IBM Corporation. + * Copyright (c) 2023, 2025 IBM Corporation. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -59,11 +59,12 @@ public void afterEach(TestInfo info) { */ @AfterAll public static void cleanup() { - ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2)); - - UIBotTestUtils.closeFileEditorTab(remoteRobot, "SystemResource.java", "5"); - UIBotTestUtils.closeFileEditorTab(remoteRobot, "SystemResource2.java", "5"); - + if (remoteRobot.isMac()) { + UIBotTestUtils.closeAllEditorTabs(remoteRobot); + } + else { + UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Close All Tabs", 3); + } UIBotTestUtils.closeProjectView(remoteRobot); UIBotTestUtils.closeProjectFrame(remoteRobot); UIBotTestUtils.validateProjectFrameClosed(remoteRobot); @@ -79,6 +80,7 @@ public void testInsertJakartaCodeSnippetIntoJavaPart() { String snippetChooser = "class"; String insertedCode = "public String methodname() {"; + openSystemResourceFile(projectName); // get focus on file tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, "SystemResource.java"); @@ -111,6 +113,7 @@ public void testJakartaDiagnosticsInJavaPart() { String expectedHoverData = "Only public methods can be exposed as resource methods"; Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", "SystemResource2.java"); + openSystemResourceFile(projectName); // get focus on file tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, "SystemResource2.java"); @@ -144,6 +147,8 @@ public void testJakartaQuickFixInJavaPart() { String privateString = "private Response getProperties() {"; String flaggedString = "getProperties"; + openSystemResourceFile(projectName); + Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", "SystemResource2.java"); String quickfixChooserString = "Make method public"; @@ -174,6 +179,37 @@ public void testJakartaQuickFixInJavaPart() { } } + @Test + @Video + public void testCompleteFilterAnnotationQuickFix() { + String sourceString = "@WebFilter()"; + String flaggedString = "@WebFilter()"; + + ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2)); + JTreeFixture projTree = projectFrame.getProjectViewJTree(projectName); + + + projTree.expand(projectName, "src", "main", "java", "io.openliberty.sample.jakarta", "servlet"); + UIBotTestUtils.openFile(remoteRobot, projectName, "InvalidWebFilter", projectName, "src", "main", "java", "io.openliberty.sample.jakarta", "servlet"); + + Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "sample", "jakarta", "servlet", "InvalidWebFilter.java"); + String quickfixChooserString = "Add the 'servletNames' attribute to @WebFilter"; + + UIBotTestUtils.clickOnFileTab(remoteRobot, "InvalidWebFilter.java"); + UIBotTestUtils.copyWindowContent(remoteRobot); + //UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, "InvalidWebFilter.java", sourceString, replacementString); + + try { + //TestUtils.validateStringNotInFile(pathToSrc.toString(), sourceString); + UIBotTestUtils.hoverForQuickFixInAppFile(remoteRobot, flaggedString, "InvalidWebFilter.java", quickfixChooserString); + UIBotTestUtils.chooseQuickFix(remoteRobot, quickfixChooserString); + TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), sourceString); + } + finally { + UIBotTestUtils.pasteOnActiveWindow(remoteRobot); + } + } + /** * Prepares the environment to run the tests. * @@ -192,6 +228,11 @@ public static void prepareEnv(String projectPath, String projectName) { UIBotTestUtils.openAndValidateLibertyToolWindow(remoteRobot, projectName); UIBotTestUtils.closeLibertyToolWindow(remoteRobot); + // Removes the build tool window if it is opened. This prevents text to be hidden by it. + UIBotTestUtils.removeToolWindow(remoteRobot, "Build:"); + } + + private static void openSystemResourceFile(String projectName) { // pre-open project tree before attempting to open files needed by testcases ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2)); JTreeFixture projTree = projectFrame.getProjectViewJTree(projectName); @@ -202,10 +243,6 @@ public static void prepareEnv(String projectPath, String projectName) { UIBotTestUtils.openFile(remoteRobot, projectName, "SystemResource", projectName, "src", "main", "java", "io.openliberty.mp.sample", "system"); UIBotTestUtils.openFile(remoteRobot, projectName, "SystemResource2", projectName, "src", "main", "java", "io.openliberty.mp.sample", "system"); - - - // Removes the build tool window if it is opened. This prevents text to be hidden by it. - UIBotTestUtils.removeToolWindow(remoteRobot, "Build:"); } } diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModLSP4JakartaTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModLSP4JakartaTestCommon.java new file mode 100644 index 000000000..9bd0d5ece --- /dev/null +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModLSP4JakartaTestCommon.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2023, 2025 IBM Corporation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package io.openliberty.tools.intellij.it; + +import com.intellij.remoterobot.RemoteRobot; +import org.junit.jupiter.api.*; + +import java.time.Duration; + +import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError; + +public abstract class SingleModLSP4JakartaTestCommon { + public static final String REMOTEBOT_URL = "http://localhost:8082"; + public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTEBOT_URL); + + String projectName; + String projectsPath; + + public SingleModLSP4JakartaTestCommon(String projectName, String projectsPath) { + this.projectName = projectName; + this.projectsPath = projectsPath; + } + + /** + * Processes actions before each test. + * + * @param info Test information. + */ + @BeforeEach + public void beforeEach(TestInfo info) { + TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Entry"); + } + + /** + * Processes actions after each test. + * + * @param info Test information. + */ + @AfterEach + public void afterEach(TestInfo info) { + TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Exit"); + TestUtils.detectFatalError(); + } + + /** + * Cleanup. + */ + @AfterAll + public static void cleanup() { + if (remoteRobot.isMac()) { + UIBotTestUtils.closeAllEditorTabs(remoteRobot); + } + else { + UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Close All Tabs", 3); + } + UIBotTestUtils.closeProjectView(remoteRobot); + UIBotTestUtils.closeProjectFrame(remoteRobot); + UIBotTestUtils.validateProjectFrameClosed(remoteRobot); + } + + /** + * Prepares the environment to run the tests. + * + * @param projectPath The path of the project. + * @param projectName The name of the project being used. + */ + + public static void prepareEnv(String projectPath, String projectName) { + waitForIgnoringError(Duration.ofMinutes(4), Duration.ofSeconds(5), "Wait for IDE to start", "IDE did not start", () -> remoteRobot.callJs("true")); + UIBotTestUtils.findWelcomeFrame(remoteRobot); + + UIBotTestUtils.importProject(remoteRobot, projectPath, projectName); + UIBotTestUtils.openProjectView(remoteRobot); + // IntelliJ does not start building and indexing until the Project View is open + UIBotTestUtils.waitForIndexing(remoteRobot); + UIBotTestUtils.openAndValidateLibertyToolWindow(remoteRobot, projectName); + UIBotTestUtils.closeLibertyToolWindow(remoteRobot); + // Removes the build tool window if it is opened. This prevents text to be hidden by it. + UIBotTestUtils.removeToolWindow(remoteRobot, "Build:"); + } +} +