Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification to add automated ui test for CompleteFilterAnnotationQuickfix #1230

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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";

Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
Expand All @@ -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:");
}
}

Original file line number Diff line number Diff line change
@@ -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:");
}
}

Loading