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 26 commits into
base: main
Choose a base branch
from

Conversation

anusreelakshmi934
Copy link
Contributor

Fixes #1153

Copy link
Contributor

@dessina-devasia dessina-devasia left a 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

@anusreelakshmi934
Copy link
Contributor Author

Change Copyright year in all files

Changed the Copyright year

Copy link
Contributor

@mrglavas mrglavas left a 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.

@anusreelakshmi934 anusreelakshmi934 marked this pull request as ready for review January 13, 2025 14:29
Copy link
Contributor

@dessina-devasia dessina-devasia left a 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!

@anusreelakshmi934
Copy link
Contributor Author

@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.

Hi @mrglavas . I have made the changes and now the test succeeds.

Copy link
Contributor

@TrevCraw TrevCraw left a 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.

@anusreelakshmi934
Copy link
Contributor Author

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.

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 openFile method expects the filePath parameter in the format String... filePath. Replacing it with the constant resulted in an error because the input was not provided in the required String... format.

I also tried passing the value as a String array, but this led to a compilation issue. The problem arises because the method expects multiple strings as individual arguments and does not accept an array in place of these arguments.

Expected Output is -
image

But if we pass the constant we will get -
image

If we pass the value as String array we will get -
image

So the file will not be opened. Hence I kept the strings in openFile as it was.

@TrevCraw
Copy link
Contributor

If we pass the value as String array we will get - image

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 Arrays.toString() for your String array parameter. That will not work, as Arrays.toString() returns a String, not an array of Strings. You should be able to pass an array of Strings to the String... varargs parameter.

If you take a step back and look at the original code, you will noticed the pattern for both getPath() and openFile() was always set up to work with String.... We should leave that format alone and adjust the newly created constants to match the existing code patterns. It would probably be best to modify your String constants that are paths with slashes to be String arrays instead.

@anusreelakshmi934
Copy link
Contributor Author

If we pass the value as String array we will get - image
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 Arrays.toString() for your String array parameter. That will not work, as Arrays.toString() returns a String, not an array of Strings. You should be able to pass an array of Strings to the String... varargs parameter.

If you take a step back and look at the original code, you will noticed the pattern for both getPath() and openFile() was always set up to work with String.... We should leave that format alone and adjust the newly created constants to match the existing code patterns. It would probably be best to modify your String constants that are paths with slashes to be String arrays instead.

Thanks, @TrevCraw, for the clarification. Initially, when I passed the string array to the openFile method, it was being interpreted as the fifth parameter, with the project name as the fourth. This caused issues with passing the string array. To resolve this, I modified the approach by combining the projectName and the path. With this change, two of the classes are now passing, but others are still failing despite using the same approach. I am currently investigating the issue and will update the PR accordingly.

@mrglavas
Copy link
Contributor

Thanks, @TrevCraw, for the clarification. Initially, when I passed the string array to the openFile method, it was being interpreted as the fifth parameter, with the project name as the fourth. This caused issues with passing the string array. To resolve this, I modified the approach by combining the projectName and the path. With this change, two of the classes are now passing, but others are still failing despite using the same approach. I am currently investigating the issue and will update the PR accordingly.

@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 String...) that was in the original code.

Copy link
Contributor

@mrglavas mrglavas left a 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.

Copy link
Contributor

@TrevCraw TrevCraw left a 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.

@anusreelakshmi934
Copy link
Contributor Author

Hi @TrevCraw,
I’ve addressed your comments and made the necessary changes. Please review them when you get a chance and let me know if this aligns with your expectations or if further modifications are needed. Thanks!

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 Paths.get(), it might be more efficient to directly specify the path there. Could you confirm if this approach is appropriate?

Copy link
Contributor

@TrevCraw TrevCraw left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

@anusreelakshmi934 anusreelakshmi934 Jan 23, 2025

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);
Copy link
Contributor

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[].

Copy link
Contributor Author

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);
Copy link
Contributor

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[].

Copy link
Contributor Author

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);
Copy link
Contributor

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[].

Copy link
Contributor Author

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);
Copy link
Contributor

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().

Copy link
Contributor Author

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);
Copy link
Contributor

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[].

Copy link
Contributor Author

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[].

- MPG_PROPERTIES changed to MPCFG_PROPERTIES
- concatenate the Strings for wlpMsgLogPath
@@ -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;
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add constants for string literals throughout the UI tests.
6 participants