Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into Issue#1173
Browse files Browse the repository at this point in the history
  • Loading branch information
anusreelakshmi934 committed Jan 7, 2025
2 parents c62a33f + ebc7a3c commit 40478f7
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 31 deletions.
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 Down Expand Up @@ -163,11 +163,12 @@ public void testInsertLibertyConfigElementIntoServerXML() {

/**
* Tests liberty-ls type ahead support in server.env for a
* Liberty Server Configuration Stanza
* Liberty Server Configuration Stanza and
* providing completion suggestions in uppercase letters.
*/
@Test
@Video
public void testInsertLibertyConfigIntoServerEnv() {
public void testInsertLibertyConfigIntoServerEnvForCapitalCase() {
String envCfgSnippet = "WLP_LOGGING_CON";
String envCfgNameChooserSnippet = "FORMAT";
String envCfgValueSnippet = "SIM";
Expand All @@ -189,13 +190,70 @@ public void testInsertLibertyConfigIntoServerEnv() {
}
}

/**
* Tests Liberty-LS support in server.env for
* providing completion suggestions in lowercase letters.
*/
@Test
@Video
public void testInsertLibertyConfigIntoServerEnvForLowerCase() {
String envCfgSnippetLowerCase = "wlp_logging_con";
String envCfgNameChooserSnippet = "FORMAT";
String envCfgValueSnippet = "sim";
String expectedServerEnvString = "WLP_LOGGING_CONSOLE_FORMAT=SIMPLE";

// get focus on server.env tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "server.env");

// Save the current server.env content.
UIBotTestUtils.copyWindowContent(remoteRobot);

try {
UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, "server.env", envCfgSnippetLowerCase, envCfgNameChooserSnippet, envCfgValueSnippet, true);
Path pathToServerEnv = Paths.get(projectsPath, projectName, "src", "main", "liberty", "config", "server.env");
TestUtils.validateStringInFile(pathToServerEnv.toString(), expectedServerEnvString);
} finally {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}
}

/**
* Tests Liberty-LS support in server.env for providing completion
* suggestions in a mix of uppercase and lowercase letters.
*/
@Test
@Video
public void testInsertLibertyConfigIntoServerEnvForMixOfCases() {
String envCfgSnippetMixCase = "wLp_LOgginG_coN";
String envCfgNameChooserSnippet = "FORMAT";
String envCfgValueSnippet = "sIM";
String expectedServerEnvString = "WLP_LOGGING_CONSOLE_FORMAT=SIMPLE";

// get focus on server.env tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "server.env");

// Save the current server.env content.
UIBotTestUtils.copyWindowContent(remoteRobot);

try {
UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, "server.env", envCfgSnippetMixCase, envCfgNameChooserSnippet, envCfgValueSnippet, true);
Path pathToServerEnv = Paths.get(projectsPath, projectName, "src", "main", "liberty", "config", "server.env");
TestUtils.validateStringInFile(pathToServerEnv.toString(), expectedServerEnvString);
} finally {
// Replace server.xml 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
* Liberty Server Configuration bootstrap.properties entry and
* providing completion suggestions in lowercase letters.
*/
@Test
@Video
public void testInsertLibertyConfigIntoBootstrapProps() {
public void testInsertLibertyConfigIntoBootstrapPropsForLowerCase() {
String configNameSnippet = "com.ibm.ws.logging.con";
String configNameChooserSnippet = "format";
String configValueSnippet = "TBA";
Expand All @@ -217,6 +275,62 @@ public void testInsertLibertyConfigIntoBootstrapProps() {
}
}

/**
* Tests Liberty-LS support in bootstrap.properties for
* providing completion suggestions in capital case letters.
*/
@Test
@Video
public void testInsertLibertyConfigIntoBootstrapPropsForCapitalCase() {
String configNameSnippetUpperCase = "COM.IBM.WS.LOGGING.CON";
String configNameChooserSnippet = "format";
String configValueSnippet = "tba";
String expectedBootstrapPropsString = "com.ibm.ws.logging.console.format=TBASIC";

// get focus on bootstrap.properties tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "bootstrap.properties");

// Save the current bootstrap.properties content.
UIBotTestUtils.copyWindowContent(remoteRobot);

try {
UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, "bootstrap.properties", configNameSnippetUpperCase, configNameChooserSnippet, configValueSnippet, true);
Path pathToBootstrapProps = Paths.get(projectsPath, projectName, "src", "main", "liberty", "config", "bootstrap.properties");
TestUtils.validateStringInFile(pathToBootstrapProps.toString(), expectedBootstrapPropsString);
} finally {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}
}

/**
* Tests Liberty-LS support in bootstrap.properties for providing completion
* suggestions in a mix of uppercase and lowercase letters.
*/
@Test
@Video
public void testInsertLibertyConfigIntoBootstrapPropsForMixOfCases() {
String configNameSnippetMixCase = "CoM.Ibm.wS.LoGginG.cON";
String configNameChooserSnippet = "format";
String configValueSnippet = "Tba";
String expectedBootstrapPropsString = "com.ibm.ws.logging.console.format=TBASIC";

// get focus on bootstrap.properties tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, "bootstrap.properties");

// Save the current bootstrap.properties content.
UIBotTestUtils.copyWindowContent(remoteRobot);

try {
UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, "bootstrap.properties", configNameSnippetMixCase, configNameChooserSnippet, configValueSnippet, true);
Path pathToBootstrapProps = Paths.get(projectsPath, projectName, "src", "main", "liberty", "config", "bootstrap.properties");
TestUtils.validateStringInFile(pathToBootstrapProps.toString(), expectedBootstrapPropsString);
} finally {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}
}

/**
* Tests liberty-ls Hover support in server.env for a
* Liberty Server Config setting
Expand Down Expand Up @@ -286,7 +400,6 @@ public void testDiagnosticInServerXML() {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}

}

/**
Expand Down Expand Up @@ -324,8 +437,6 @@ public void testQuickFixInServerXML() {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot, true);
}


}

/**
Expand Down Expand Up @@ -356,7 +467,6 @@ public void testDiagnosticInServerEnv() {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}

}

/**
Expand Down Expand Up @@ -387,7 +497,6 @@ public void testDiagnosticInBootstrapProperties() {
// Replace server.xml content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}

}

/**
Expand Down
94 changes: 73 additions & 21 deletions src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java
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 @@ -13,6 +13,7 @@
import com.intellij.remoterobot.fixtures.*;
import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText;
import com.intellij.remoterobot.search.locators.Locator;
import com.intellij.remoterobot.search.locators.Locators;
import com.intellij.remoterobot.utils.Keyboard;
import com.intellij.remoterobot.utils.RepeatUtilsKt;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
Expand Down Expand Up @@ -1094,19 +1095,31 @@ public static void insertConfigIntoMPConfigPropertiesFile(RemoteRobot remoteRobo
* Inserts a configuration name value pair into a config file via text typing
* and popup menu completion (if required)
*
* @param remoteRobot The RemoteRobot instance.
* @param fileName The string path to the config file
* @param configNameSnippet the portion of the name to type
* @param configNameChooserSnippet the portion of the name to use for selecting from popup menu
* @param configValueSnippet the value to type into keyboard - could be a snippet or a whole word
* @param completeWithPopup use popup to complete value selection or type in an entire provided value string
* @param remoteRobot The RemoteRobot instance.
* @param fileName The string path to the config file
* @param configNameSnippetCaseSpecific the portion of the name to type
* @param configNameChooserSnippet the portion of the name to use for selecting from popup menu
* @param configValueSnippet the value to type into keyboard - could be a snippet or a whole word
* @param completeWithPopup use popup to complete value selection or type in an entire provided value string
*/
public static void insertConfigIntoConfigFile(RemoteRobot remoteRobot, String fileName, String configNameSnippet, String configNameChooserSnippet, String configValueSnippet, boolean completeWithPopup) {
public static void insertConfigIntoConfigFile(RemoteRobot remoteRobot, String fileName, String configNameSnippetCaseSpecific, String configNameChooserSnippet, String configValueSnippet, boolean completeWithPopup) {
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofSeconds(30));
clickOnFileTab(remoteRobot, fileName);
EditorFixture editorNew = remoteRobot.find(EditorFixture.class, EditorFixture.Companion.getLocator());
Exception error = null;

String configNameSnippet = "";
if (fileName.equals("server.env")) {
configNameSnippet = configNameSnippetCaseSpecific.toUpperCase(java.util.Locale.ROOT);
}
else if (fileName.equals("bootstrap.properties")) {
configNameSnippet = configNameSnippetCaseSpecific.toLowerCase(java.util.Locale.ROOT);
}
else {
configNameSnippet = configNameSnippetCaseSpecific;
}
String configValueSnippetUpperCase = configValueSnippet.toUpperCase(java.util.Locale.ROOT);

for (int i = 0; i < 10; i++) {
error = null;
try {
Expand All @@ -1118,19 +1131,20 @@ public static void insertConfigIntoConfigFile(RemoteRobot remoteRobot, String fi
keyboard.hotKey(VK_CONTROL, VK_END);
keyboard.enter();

keyboard.enterText(configNameSnippet);
keyboard.enterText(configNameSnippetCaseSpecific);
// After typing it can take 1 or 2s for IntelliJ to render diagnostics etc. Must wait before continuing.
TestUtils.sleepAndIgnoreException(5);

// Narrow down the config name completion suggestions in the pop-up window that is automatically
// opened as text is typed based on the value of configNameSnippet. Avoid hitting ctrl + space as it has the side effect of selecting
// and entry automatically if the completion suggestion windows has one entry only.
ComponentFixture namePopupWindow = projectFrame.getLookupList();
String finalConfigNameSnippet = configNameSnippet;
RepeatUtilsKt.waitFor(Duration.ofSeconds(5),
Duration.ofSeconds(1),
"Waiting for text " + configNameSnippet + " to appear in the completion suggestion pop-up window",
"Text " + configNameSnippet + " did not appear in the completion suggestion pop-up window",
() -> namePopupWindow.hasText(configNameSnippet));
() -> namePopupWindow.hasText(finalConfigNameSnippet));

// now choose the specific item based on the chooser string
namePopupWindow.findText(contains(configNameChooserSnippet)).doubleClick();
Expand All @@ -1150,11 +1164,11 @@ public static void insertConfigIntoConfigFile(RemoteRobot remoteRobot, String fi
ComponentFixture valuePopupWindow = projectFrame.getLookupList();
RepeatUtilsKt.waitFor(Duration.ofSeconds(5),
Duration.ofSeconds(1),
"Waiting for text " + configValueSnippet + " to appear in the completion suggestion pop-up window",
"Text " + configValueSnippet + " did not appear in the completion suggestion pop-up window",
() -> valuePopupWindow.hasText(configValueSnippet));
"Waiting for text " + configValueSnippetUpperCase + " to appear in the completion suggestion pop-up window",
"Text " + configValueSnippetUpperCase + " did not appear in the completion suggestion pop-up window",
() -> valuePopupWindow.hasText(configValueSnippetUpperCase));

valuePopupWindow.findText(contains(configValueSnippet)).doubleClick();
valuePopupWindow.findText(contains(configValueSnippetUpperCase)).doubleClick();
}
// let the auto-save function of intellij save the file before testing it
if (remoteRobot.isMac()) {
Expand All @@ -1175,7 +1189,7 @@ public static void insertConfigIntoConfigFile(RemoteRobot remoteRobot, String fi

// Report the last error if there is one.
if (error != null) {
throw new RuntimeException("Unable to insert entry in config file : " + fileName + " using text: " + configNameSnippet, error);
throw new RuntimeException("Unable to insert entry in config file : " + fileName + " using text: " + configNameSnippetCaseSpecific, error);
}
}

Expand Down Expand Up @@ -2725,24 +2739,62 @@ public static void rightClickCloseOnFileTab(RemoteRobot remoteRobot, String file
/**
* Maximizes the Intellij ProjectFrame window in Windows.
*
* This method simulates pressing the Windows key + Up arrow to maximize the window,
* but only if the window is not already maximized.
*
* @param remoteRobot The RemoteRobot instance.
*/
public static void maximizeWindow(RemoteRobot remoteRobot) {
Keyboard keyboard = new Keyboard(remoteRobot);
keyboard.hotKey(VK_WINDOWS, VK_UP);
keyboard.enter();
if (!isFullScreen(remoteRobot)) {
Keyboard keyboard = new Keyboard(remoteRobot);
keyboard.hotKey(VK_WINDOWS, VK_UP);
keyboard.enter();
}
}

/**
* Minimizes the Intellij ProjectFrame window in Windows.
*
* This method simulates pressing the Windows key + Down arrow to minimize the window,
* but only if the window is currently maximized.
*
* @param remoteRobot The RemoteRobot instance.
*/
public static void minimizeWindow(RemoteRobot remoteRobot) {
Keyboard keyboard = new Keyboard(remoteRobot);
keyboard.hotKey(VK_WINDOWS, VK_DOWN);
keyboard.enter();
if (isFullScreen(remoteRobot)) {
Keyboard keyboard = new Keyboard(remoteRobot);
keyboard.hotKey(VK_WINDOWS, VK_DOWN);
keyboard.enter();
}
}

/**
* Determines if the IntelliJ window is currently full screen.
*
* This method checks the size of the IntelliJ window against the screen size to
* decide if the window is maximized or not. If the window's width or height is
* greater than or equal to the screen size, it is considered full screen.
*
* @param remoteRobot The RemoteRobot instance.
* @return true if the IntelliJ window is full screen, false otherwise.
*/
public static boolean isFullScreen(RemoteRobot remoteRobot) {
// Locate the IntelliJ IDEA main window
ComponentFixture mainWindow = remoteRobot.find(
ComponentFixture.class,
Locators.byXpath("//div[@class='IdeFrameImpl']")
);

// Get the screen size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

// Get the current dimensions (height and width) of the IntelliJ window.
int intellijWindowHeight = mainWindow.getRemoteComponent().getHeight();
int intellijWindowWidth = mainWindow.getRemoteComponent().getWidth();

return intellijWindowWidth >= screenSize.width || intellijWindowHeight >= screenSize.height;
}

/**
* Handles version-specific menu actions based on the IntelliJ IDEA version.
*
Expand Down

0 comments on commit 40478f7

Please sign in to comment.