-
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?
Add constants for string literals in UI test classes #1199
Conversation
src/main/java/io/openliberty/tools/intellij/util/Constants.java
Outdated
Show resolved
Hide resolved
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.
Change Copyright year in all files
Changed the Copyright year |
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.
@anusreelakshmi934 I see several new failures that are occurring on the Linux and Windows builds, for example:
GradleSingleModJakartaLSTest > initializationError FAILED
java.lang.RuntimeException: Unable to open file SystemResource
at io.openliberty.tools.intellij.it.UIBotTestUtils.openFile(UIBotTestUtils.java:700)
at io.openliberty.tools.intellij.it.SingleModJakartaLSTestCommon.prepareEnv(SingleModJakartaLSTestCommon.java:204)
at io.openliberty.tools.intellij.it.GradleSingleModJakartaLSTest.setup(GradleSingleModJakartaLSTest.java:40)
Caused by:
java.util.NoSuchElementException: List is empty.
at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:221)
at com.intellij.remoterobot.fixtures.Fixture.findText(Fixture.kt:46)
at io.openliberty.tools.intellij.it.UIBotTestUtils.openFile(UIBotTestUtils.java:687)
... 2 more
I suspect these might be related to recent changes in computing paths in this PR. Please verify.
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.
Looks good to me. Thanks!
Hi @mrglavas . I have made the changes and now the test succeeds. |
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.
It looks like a few spots to use the new constants may have been missed. I only marked the spots visible in the GitHub diffs. Please make sure to search through the test code to see if there are any other spots that were missed where the new constants can be used or where new constants should be created.
src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java
Outdated
Show resolved
Hide resolved
src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java
Outdated
Show resolved
Hide resolved
src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java
Outdated
Show resolved
Hide resolved
Hi @TrevCraw . Initially, I replaced all occurrences where the new constants could be used. However, this caused a GitHub Actions (GHA) failure where the file could not be opened. Upon investigation, I discovered that the I also tried passing the value as a But if we pass the constant we will get - If we pass the value as String array we will get - So the file will not be opened. Hence I kept the strings in openFile as it was. |
Hi @anusreelakshmi934 , looking at the image above, it looks like you used If you take a step back and look at the original code, you will noticed the pattern for both |
Thanks, @TrevCraw, for the clarification. Initially, when I passed the string array to the |
@anusreelakshmi934 I know you're currently working on updates to this PR so will wait for that before reviewing again. For the current state of the PR, I had similar feedback to what @TrevCraw already expressed. It should be possible to construct arrays from a combination of constants and variable values that are equivalent to the vararg syntax (for |
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.
See my recent comments. Awaiting changes before reviewing again.
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.
There are lots of places where String.join()
is used. Would it be possible to pass String arrays as was done before? You can build the String arrays from your existing constants dynamically if needed. Or, in most cases, you can create new constants that combine your existing constants.
For example, you have:
CONFIG_DIR_PATH = { "src", "main", "liberty", "config" };
SERVER_XML = "server.xml";
You can create a new constant that combines the two called SERVER_XML_PATH
and then use that to pass as a parameter to the necessary methods.
src/test/java/io/openliberty/tools/intellij/it/Utils/ItConstants.java
Outdated
Show resolved
Hide resolved
Hi @TrevCraw, Additionally, I’ve removed the WLP_MSGLOG_PATH from the TestUtils file and moved it to the ItConstants file as a slash-separated path. I felt that, instead of calling |
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.
Hi @anusreelakshmi934 , please address the review comments below. And be sure to check the build results after making your changes.
It probably was not necessary to move MESSAGES_LOG_PATH
to the ItConstants
file since it is only used in one file. However, the change should be OK. Please take a look at one of the comments related to this change below.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the SYSTEM_DIR_PATH
to a String[]
. Additionally, I introduced new variables: SERVER_XML_PATH
, SERVER_ENV_PATH
, and BOOTSTRAP_PROPERTIES_PATH
.
|
||
// Save the current server.xml content. | ||
UIBotTestUtils.copyWindowContent(remoteRobot); | ||
|
||
// Insert a new element in server.xml. | ||
try { | ||
UIBotTestUtils.insertStanzaInAppServerXML(remoteRobot, stanzaSnippet, 18, 40, UIBotTestUtils.InsertionType.FEATURE, true); | ||
Path pathToServerXML = Paths.get(projectsPath, projectName, "src", "main", "liberty", "config", "server.xml"); | ||
Path pathToServerXML = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); |
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.
Same comment here as for SYSTEM_DIR_PATH above. Would be better to keep as a String[].
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 have updated the SYSTEM_DIR_PATH to a String[]
UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, "ServiceLiveHealthCheck.java", snippetStr, snippetChooser); | ||
Path pathToSrc = Paths.get(projectsPath, projectName, "src", "main", "java", "io", "openliberty", "mp", "sample", "health","ServiceLiveHealthCheck.java"); | ||
UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA, snippetStr, snippetChooser); | ||
Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.HEALTH_DIR_PATH, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); |
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.
Same comment here as for SYSTEM_DIR_PATH and CONFIG_DIR_PATH above. Would be better to keep as a String[].
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 have updated the SYSTEM_DIR_PATH to a String[]
UIBotTestUtils.insertConfigIntoMPConfigPropertiesFile(remoteRobot, "microprofile-config.properties", cfgSnippet, cfgNameChooserSnippet, cfgValueSnippet, true); | ||
Path pathToMpCfgProperties = Paths.get(projectsPath, projectName, "src", "main", "resources", "META-INF", "microprofile-config.properties"); | ||
UIBotTestUtils.insertConfigIntoMPConfigPropertiesFile(remoteRobot, ItConstants.MPG_PROPERTIES, cfgSnippet, cfgNameChooserSnippet, cfgValueSnippet, true); | ||
Path pathToMpCfgProperties = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.META_INF_DIR_PATH), ItConstants.MPG_PROPERTIES); |
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.
Why do a String.join() here? The original code is passing a String[].
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 have removed the String.join() and combined the projectName and MPCFG path using combinePath method.
@@ -294,19 +296,19 @@ public void testQuickFixInMicroProfileConfigProperties() { | |||
String correctedValue = "mp.health.disable-default-procedures=true"; | |||
String expectedHoverData = "Type mismatch: boolean expected. By default, this value will be interpreted as 'false'"; | |||
|
|||
Path pathToMpCfgProperties = Paths.get(projectsPath, projectName,"src", "main", "resources", "META-INF", "microprofile-config.properties"); | |||
Path pathToMpCfgProperties = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.META_INF_DIR_PATH), ItConstants.MPG_PROPERTIES); |
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.
Same as above comment on String.join().
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 have removed the String.join() and combined the projectName and MPCFG path using combinePath method
@@ -541,7 +540,7 @@ public static boolean isServerStopNeeded(String wlpInstallPath) { | |||
*/ | |||
public static void checkDebugPort(String absoluteWLPPath, int debugPort) throws IOException { | |||
// Retrieve the WLP server.env file path | |||
Path serverEnvPath = Paths.get(absoluteWLPPath, "wlp", "usr", "servers", "defaultServer", "server.env"); | |||
Path serverEnvPath = Paths.get(absoluteWLPPath, ItConstants.DEFAULT_SERVER_PATH, ItConstants.SERVER_ENV); |
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.
Same comment here as for SYSTEM_DIR_PATH, CONFIG_DIR_PATH and HEALTH_DIR_PATH above. Would be better to keep as a String[].
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 have updated it to String[].
Fixes #1153