-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: main
Are you sure you want to change the base?
Changes from 19 commits
5268e33
1e62f89
02c2113
da9f216
daa7096
769d3d3
fcac98e
02a2265
ce62614
42261b6
4fc023b
92e9776
2bf831c
0618396
0588eba
b34d02a
4761fe1
698703d
6f5f2f5
97eac05
e64cdbd
64b7a81
f1d400d
31ca81d
3f1b7b3
229e73e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -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.*; | ||
|
||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is SYSTEM_DIR_PATH a String and not a String[]? It would be better to keep the format the same as the original code. You can always build a new String[] constant from String[] SYSTEM_DIR_PATH and String SYSTEM_RESOURCE_JAVA. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated the |
||
TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode); | ||
} | ||
finally { | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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, "src", "main", "java", "io.openliberty.mp.sample", "system"); | ||
UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE_2, projectName, "src", "main", "java", "io.openliberty.mp.sample", "system"); | ||
anusreelakshmi934 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
// Removes the build tool window if it is opened. This prevents text to be hidden by it. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to suggest using
import static io.openliberty.tools.intellij.it.Utils.ItConstants.*
so that you do not have to specify the class name every time you use a constant in all these test files. It gets repetitive.