diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java index 48e9b2d59..08c26213e 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java @@ -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,12 +12,17 @@ import com.automation.remarks.junit5.Video; import com.intellij.remoterobot.RemoteRobot; import com.intellij.remoterobot.fixtures.JTreeFixture; +import com.intellij.remoterobot.utils.Keyboard; import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture; import org.junit.jupiter.api.*; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.Map; + +import static java.awt.event.KeyEvent.VK_CONTROL; +import static java.awt.event.KeyEvent.VK_SPACE; import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError; @@ -189,6 +194,98 @@ public void testInsertLibertyConfigIntoServerEnv() { } } + /** + Test to Ensure that relevant completion values (e.g., SIMPLE, ADVANCED) + * are displayed and prioritized at the top of the list in server.env. + */ + @Test + @Video + public void testCompletionValuesInServerEnv() { + String envCfgKeySnippet = "WLP_LOGGING_CONSOLE_FORMAT="; // Property key + String[] expectedCompletionValues = {"DEV", "JSON", "SIMPLE", "TBASIC"}; // Expected completion values + + Keyboard keyboard = new Keyboard(remoteRobot); + + // Get focus on server.env tab prior to copy + UIBotTestUtils.clickOnFileTab(remoteRobot, "server.env"); + + // Save the current server.env content. + UIBotTestUtils.copyWindowContent(remoteRobot); + + // Delete the current server.env content. + UIBotTestUtils.clearWindowContent(remoteRobot); + + // Type the property key + keyboard.enterText(envCfgKeySnippet); + + // Trigger code completion + keyboard.hotKey(VK_CONTROL, VK_SPACE); + + try { + // Check if the expected value appears in the top of the completion pop-up + Map textPositions = ProjectFrameFixture.findAllTextPositions(remoteRobot); + + // Verify each expected value's position + for (String expectedValue : expectedCompletionValues) { + Integer position = textPositions.get(expectedValue); + // Verify that the expected value is within the top 4 positions + Assertions.assertNotNull(position, + "Text '" + expectedValue + "' did not appear in the completion suggestion pop-up window."); + Assertions.assertTrue(position >= 0 && position <= 3, + "Text '" + expectedValue + "' is at position " + position + " and is not in the top 4."); + } + } finally { + // Replace server.env content with the original content + UIBotTestUtils.pasteOnActiveWindow(remoteRobot); + } + } + + /** + Test to Ensure that relevant completion values (e.g., AUDIT, ERROR) + * are displayed and prioritized at the top of the list in bootstrap.properties. + */ + @Test + @Video + public void testCompletionValuesInBootstrapProperties() { + String envCfgKeySnippet = "com.ibm.ws.logging.console.log.level="; // Property key + String[] expectedCompletionValues = {"AUDIT", "ERROR", "INFO", "OFF", "WARNING"}; // Expected completion values + + Keyboard keyboard = new Keyboard(remoteRobot); + + // get focus on bootstrap.properties tab prior to copy + UIBotTestUtils.clickOnFileTab(remoteRobot, "bootstrap.properties"); + + // Save the current bootstrap.properties content. + UIBotTestUtils.copyWindowContent(remoteRobot); + + // Delete the current bootstrap.properties content. + UIBotTestUtils.clearWindowContent(remoteRobot); + + // Type the property key + keyboard.enterText(envCfgKeySnippet); + + // Trigger code completion + keyboard.hotKey(VK_CONTROL, VK_SPACE); + + try { + // Check if the expected value appears in the top of the completion pop-up + Map textPositions = ProjectFrameFixture.findAllTextPositions(remoteRobot); + + // Verify each expected value's position + for (String expectedValue : expectedCompletionValues) { + Integer position = textPositions.get(expectedValue); + // Verify that the expected value is within the top 5 positions + Assertions.assertNotNull(position, + "Text '" + expectedValue + "' did not appear in the completion suggestion pop-up window."); + Assertions.assertTrue(position >= 0 && position <= 4, + "Text '" + expectedValue + "' is at position " + position + " and is not in the top 5."); + } + } finally { + // Replace bootstrap.properties content with the original content + UIBotTestUtils.pasteOnActiveWindow(remoteRobot); + } + } + /** * Tests liberty-ls type ahead support in bootstrap.properties for a * Liberty Server Configuration booststrap.properties entry diff --git a/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java b/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java index 7e3e8e442..45f40f29d 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java +++ b/src/test/java/io/openliberty/tools/intellij/it/fixtures/ProjectFrameFixture.java @@ -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.intellij.remoterobot.RemoteRobot; import com.intellij.remoterobot.data.RemoteComponent; import com.intellij.remoterobot.fixtures.*; +import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText; import com.intellij.remoterobot.search.locators.Locator; import com.intellij.remoterobot.utils.RepeatUtilsKt; import com.intellij.remoterobot.utils.WaitForConditionTimeoutException; @@ -20,7 +21,9 @@ import org.jetbrains.annotations.NotNull; import java.time.Duration; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static com.intellij.remoterobot.search.locators.Locators.byXpath; @@ -329,6 +332,26 @@ public ContainerFixture getLookupList() { return find(ContainerFixture.class, byXpath("//div[@class='HeavyWeightWindow']//div[@class='LookupList']"), Duration.ofSeconds(10)); } + /** + * Retrieves a map of text and their positions from the completion suggestion pop-up in IntelliJ IDEA. + * + * @return a map where keys are suggestion texts and values are their positions. + */ + + public static Map findAllTextPositions(RemoteRobot remoteRobot) { + + ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofSeconds(10)); + // Wait for the completion suggestion pop-up window to display the expected values + ComponentFixture completionPopupWindow = projectFrame.getLookupList(); + List allData = completionPopupWindow.getData().getAll(); + Map textPositionMap = new HashMap<>(); + // Populate the map with text and their respective positions + for (int i = 0; i < allData.size(); i++) { + textPositionMap.put(allData.get(i).getText(), i); + } + return textPositionMap; // Return the map with all text positions + } + /** * Returns the ContainerFixture object associated with the MyList class in a HeavyWeightWindow (List window). *