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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
17 changes: 17 additions & 0 deletions src/main/java/io/openliberty/tools/intellij/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,21 @@ public final class Constants {
public static final String JAKARTA_LANG_SERVER="Eclipse LSP4Jakarta";
public static final String MICROPROFILE_SERVER="Eclipse LSP4MP";

/**
* Constants for Integration testing
*/
public static final String SYSTEM_RESOURCE_JAVA = "SystemResource.java";
public static final String SYSTEM_RESOURCE_2_JAVA = "SystemResource2.java";
public static final String SYSTEM_RESOURCE = "SystemResource";
public static final String SYSTEM_RESOURCE_2 = "SystemResource2";

public static final String SERVER_XML = "server.xml";
public static final String SERVER_ENV = "server.env";
public static final String BOOTSTRAP_PROPERTIES = "bootstrap.properties";
public static final String COMPACT_MODE = "Compact Mode";

public static final String SERVICE_LIVE_HEALTH_CHECK_JAVA = "ServiceLiveHealthCheck.java";
public static final String MPG_PROPERTIES = "microprofile-config.properties";

public static final String CLOSE_ALL_TABS = "Close All Tabs";
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture;
import io.openliberty.tools.intellij.util.Constants;
import org.junit.jupiter.api.*;

import java.nio.file.Path;
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, Constants.SYSTEM_RESOURCE_JAVA, "5");
UIBotTestUtils.closeFileEditorTab(remoteRobot, Constants.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, Constants.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, Constants.SYSTEM_RESOURCE_JAVA, snippetStr, snippetChooser);
Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", Constants.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, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", Constants.SYSTEM_RESOURCE_2_JAVA);

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

// Modify the method signature
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, "SystemResource2.java", publicString, privateString);
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, Constants.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, Constants.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, Constants.SYSTEM_RESOURCE_2_JAVA);

} finally {
// Replace modified content with the original content
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, "SystemResource2.java", privateString, publicString);
UIBotTestUtils.selectAndModifyTextInJavaPart(remoteRobot, Constants.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, "src", "main", "java", "io", "openliberty", "mp", "sample", "system", Constants.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, Constants.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, Constants.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, Constants.SYSTEM_RESOURCE_2_JAVA, quickfixChooserString);

// trigger and use the quickfix popup attached to the diagnostic
UIBotTestUtils.chooseQuickFix(remoteRobot, quickfixChooserString);
Expand Down Expand Up @@ -200,8 +201,8 @@ public static void prepareEnv(String projectPath, String projectName) {
// must be expanded here before trying to open specific files
projTree.expand(projectName, "src", "main", "java", "io.openliberty.mp.sample", "system");

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, Constants.SYSTEM_RESOURCE, projectName, "src", "main", "java", "io.openliberty.mp.sample", "system");
UIBotTestUtils.openFile(remoteRobot, projectName, Constants.SYSTEM_RESOURCE_2, 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.
Expand Down
Loading
Loading