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

Add constants for string literals in UI test classes #1199

Draft
wants to merge 14 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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2024 IBM Corporation.
* Copyright (c) 2020, 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
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 All @@ -12,6 +12,7 @@
import com.automation.remarks.junit5.Video;
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import io.openliberty.tools.intellij.it.Utils.ItConstants;
import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture;
import org.junit.jupiter.api.*;

Expand Down Expand Up @@ -61,8 +62,8 @@ public void afterEach(TestInfo info) {
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");
UIBotTestUtils.closeFileEditorTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_JAVA, "5");
UIBotTestUtils.closeFileEditorTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA, "5");

UIBotTestUtils.closeProjectView(remoteRobot);
UIBotTestUtils.closeProjectFrame(remoteRobot);
Expand All @@ -80,7 +81,7 @@ public void testInsertJakartaCodeSnippetIntoJavaPart() {
String insertedCode = "public String methodname() {";

// get focus on file tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "SystemResource.java");
UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_JAVA);

// Save the current content.
UIBotTestUtils.copyWindowContent(remoteRobot);
Expand All @@ -90,8 +91,8 @@ public void testInsertJakartaCodeSnippetIntoJavaPart() {

// Insert a code snippet into java part
try {
UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, "SystemResource.java", snippetStr, snippetChooser);
Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", "SystemResource.java");
UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, ItConstants.SYSTEM_RESOURCE_JAVA, snippetStr, snippetChooser);
Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_JAVA);
TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode);
}
finally {
Expand All @@ -109,28 +110,28 @@ public void testJakartaDiagnosticsInJavaPart() {
String privateString = "private Response getProperties() {";
String flaggedString = "getProperties";
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");
Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_2_JAVA);

// get focus on file tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "SystemResource2.java");
UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA);

// Modify the method signature
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, "SystemResource2.java", publicString, privateString);
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA, publicString, privateString);

try {
// validate the method signature is no longer set to public
TestUtils.validateStringNotInFile(pathToSrc.toString(), publicString);

//there should be a diagnostic for "private" on method signature - move cursor to hover point
UIBotTestUtils.hoverInAppServerCfgFile(remoteRobot, flaggedString, "SystemResource2.java", UIBotTestUtils.PopupType.DIAGNOSTIC);
UIBotTestUtils.hoverInAppServerCfgFile(remoteRobot, flaggedString, ItConstants.SYSTEM_RESOURCE_2_JAVA, UIBotTestUtils.PopupType.DIAGNOSTIC);

String foundHoverData = UIBotTestUtils.getHoverStringData(remoteRobot, UIBotTestUtils.PopupType.DIAGNOSTIC);
TestUtils.validateHoverData(expectedHoverData, foundHoverData);
UIBotTestUtils.clickOnFileTab(remoteRobot, "SystemResource2.java");
UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA);

} finally {
// Replace modified content with the original content
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, "SystemResource2.java", privateString, publicString);
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA, privateString, publicString);
}
}

Expand All @@ -144,24 +145,24 @@ public void testJakartaQuickFixInJavaPart() {
String privateString = "private Response getProperties() {";
String flaggedString = "getProperties";

Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", "SystemResource2.java");
Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_2_JAVA);
String quickfixChooserString = "Make method public";

// get focus on file tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "SystemResource2.java");
UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA);

// Save the current content.
UIBotTestUtils.copyWindowContent(remoteRobot);

// Modify the method signature
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, "SystemResource2.java", publicString, privateString);
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA, publicString, privateString);

try {
// validate public signature no longer found in java part
TestUtils.validateStringNotInFile(pathToSrc.toString(), publicString);

//there should be a diagnostic - move cursor to hover point
UIBotTestUtils.hoverForQuickFixInAppFile(remoteRobot, flaggedString, "SystemResource2.java", quickfixChooserString);
UIBotTestUtils.hoverForQuickFixInAppFile(remoteRobot, flaggedString, ItConstants.SYSTEM_RESOURCE_2_JAVA, quickfixChooserString);

// trigger and use the quickfix popup attached to the diagnostic
UIBotTestUtils.chooseQuickFix(remoteRobot, quickfixChooserString);
Expand Down Expand Up @@ -198,10 +199,10 @@ public static void prepareEnv(String projectPath, String projectName) {

// expand project directories that are specific to this test app being used by these testcases
// must be expanded here before trying to open specific files
projTree.expand(projectName, "src", "main", "java", "io.openliberty.mp.sample", "system");
projTree.expand(projectName, ItConstants.SYSTEM_DIR_PATH);

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");
UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE, projectName, ItConstants.SYSTEM_DIR_PATH);
UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE_2, projectName, ItConstants.SYSTEM_DIR_PATH);


// Removes the build tool window if it is opened. This prevents text to be hidden by it.
Expand Down
Loading
Loading