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

UI test to check for relevant completion options in bootstrap.properties and server.env #1205

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand All @@ -12,12 +12,17 @@
import com.automation.remarks.junit5.Video;
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
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;

Expand Down Expand Up @@ -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<String, Integer> 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<String, Integer> 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
Expand Down
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
Expand All @@ -12,6 +12,7 @@
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, Integer> 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<RemoteText> allData = completionPopupWindow.getData().getAll();
Map<String, Integer> 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).
*
Expand Down
Loading