Skip to content

Commit

Permalink
Dynamically combine paths and project name
Browse files Browse the repository at this point in the history
  • Loading branch information
anusreelakshmi934 committed Jan 31, 2025
1 parent 682853c commit 25a376e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;
import static io.openliberty.tools.intellij.it.Utils.ItConstants.*;
import static io.openliberty.tools.intellij.it.TestUtils.*;

public abstract class SingleModJakartaLSTestCommon {
public static final String REMOTEBOT_URL = "http://localhost:8082";
Expand Down Expand Up @@ -92,7 +93,7 @@ public void testInsertJakartaCodeSnippetIntoJavaPart() {
// Insert a code snippet into java part
try {
UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, SYSTEM_RESOURCE_JAVA, snippetStr, snippetChooser);
Path pathToSrc = Paths.get(projectsPath, TestUtils.combinePath(projectName, SYSTEM_RESOURCE_PATH));
Path pathToSrc = Paths.get(projectsPath, combinePath(projectName, buildPathArray(SYSTEM_DIR_PATH, SYSTEM_RESOURCE_JAVA)));
TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode);
}
finally {
Expand All @@ -110,7 +111,7 @@ public void testJakartaDiagnosticsInJavaPart() {
String privateString = "private Response getProperties() {";
String flaggedString = "getProperties";
String expectedHoverData = "Only public methods can be exposed as resource methods";
Path pathToSrc = Paths.get(projectsPath, TestUtils.combinePath(projectName, SYSTEM_RESOURCE_2_PATH));
Path pathToSrc = Paths.get(projectsPath, combinePath(projectName, buildPathArray(SYSTEM_DIR_PATH, SYSTEM_RESOURCE_2_JAVA)));

// get focus on file tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, SYSTEM_RESOURCE_2_JAVA);
Expand Down Expand Up @@ -145,7 +146,7 @@ public void testJakartaQuickFixInJavaPart() {
String privateString = "private Response getProperties() {";
String flaggedString = "getProperties";

Path pathToSrc = Paths.get(projectsPath, TestUtils.combinePath(projectName, SYSTEM_RESOURCE_2_PATH));
Path pathToSrc = Paths.get(projectsPath, combinePath(projectName, buildPathArray(SYSTEM_DIR_PATH, SYSTEM_RESOURCE_2_JAVA)));
String quickfixChooserString = "Make method public";

// get focus on file tab prior to copy
Expand Down Expand Up @@ -199,9 +200,9 @@ public static void prepareEnv(String projectPath, String projectName) {

// expand project directories that are specific to this test app being used by these testcases
// must be expanded here before trying to open specific files
projTree.expand(TestUtils.combinePath(projectName, SYSTEM_DIR_PATH));
projTree.expand(combinePath(projectName, SYSTEM_DIR_PATH_FOR_EXPAND));

String[] systemDirPath = TestUtils.combinePath(projectName, SYSTEM_DIR_PATH);
String[] systemDirPath = combinePath(projectName, SYSTEM_DIR_PATH_FOR_EXPAND);
UIBotTestUtils.openFile(remoteRobot, projectName, SYSTEM_RESOURCE, systemDirPath);
UIBotTestUtils.openFile(remoteRobot, projectName, SYSTEM_RESOURCE_2, systemDirPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;
import static io.openliberty.tools.intellij.it.Utils.ItConstants.*;
import static io.openliberty.tools.intellij.it.TestUtils.*;

public abstract class SingleModLibertyLSTestCommon {
public static final String REMOTEBOT_URL = "http://localhost:8082";
Expand Down Expand Up @@ -131,7 +132,7 @@ public void testInsertFeatureIntoServerXML() {
// Insert a new element in server.xml.
try {
UIBotTestUtils.insertStanzaInAppServerXML(remoteRobot, stanzaSnippet, 18, 40, UIBotTestUtils.InsertionType.FEATURE, true);
Path pathToServerXML = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVER_XML_PATH));
Path pathToServerXML = Paths.get(projectsPath, combinePath(projectName, buildPathArray(CONFIG_DIR_PATH, SERVER_XML)));
TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedFeature);
} finally {
// Replace server.xml content with the original content
Expand Down Expand Up @@ -159,7 +160,7 @@ public void testInsertLibertyConfigElementIntoServerXML() {
try {
UIBotTestUtils.insertStanzaInAppServerXML(remoteRobot, stanzaSnippet, 20, 0, UIBotTestUtils.InsertionType.ELEMENT, true);
TestUtils.sleepAndIgnoreException(2); // wait for editor to update
Path pathToServerXML = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVER_XML_PATH));
Path pathToServerXML = Paths.get(projectsPath, combinePath(projectName, buildPathArray(CONFIG_DIR_PATH, SERVER_XML)));
TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedConfig);
} finally {
// Replace server.xml content with the original content
Expand Down Expand Up @@ -188,7 +189,7 @@ public void testInsertLibertyConfigIntoServerEnvForCapitalCase() {

try {
UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, SERVER_ENV, envCfgSnippet, envCfgNameChooserSnippet, envCfgValueSnippet, true);
Path pathToServerEnv = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVER_ENV_PATH));
Path pathToServerEnv = Paths.get(projectsPath, combinePath(projectName, buildPathArray(CONFIG_DIR_PATH, SERVER_ENV)));
TestUtils.validateStringInFile(pathToServerEnv.toString(), expectedServerEnvString);
} finally {
// Replace server.xml content with the original content
Expand Down Expand Up @@ -273,7 +274,7 @@ public void testInsertLibertyConfigIntoBootstrapPropsForLowerCase() {

try {
UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, BOOTSTRAP_PROPERTIES, configNameSnippet, configNameChooserSnippet, configValueSnippet, true);
Path pathToBootstrapProps = Paths.get(projectsPath, TestUtils.combinePath(projectName, BOOTSTRAP_PROPERTIES_PATH));
Path pathToBootstrapProps = Paths.get(projectsPath, combinePath(projectName, buildPathArray(CONFIG_DIR_PATH, BOOTSTRAP_PROPERTIES)));
TestUtils.validateStringInFile(pathToBootstrapProps.toString(), expectedBootstrapPropsString);
} finally {
// Replace server.xml content with the original content
Expand Down Expand Up @@ -406,7 +407,7 @@ public void testDiagnosticInServerXML() {
String expectedHoverData = "cvc-datatype-valid.1.2.3: 'wrong' is not a valid value of union type 'booleanType'.";

Path pathToServerXML = null;
pathToServerXML = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVER_XML_PATH));
pathToServerXML = Paths.get(projectsPath, combinePath(projectName, buildPathArray(CONFIG_DIR_PATH, SERVER_XML)));

// get focus on server.xml tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, SERVER_XML);
Expand Down Expand Up @@ -442,7 +443,7 @@ public void testQuickFixInServerXML() {
String expectedHoverData = "cvc-datatype-valid.1.2.3: 'wrong' is not a valid value of union type 'booleanType'.";

Path pathToServerXML = null;
pathToServerXML = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVER_XML_PATH));
pathToServerXML = Paths.get(projectsPath, combinePath(projectName, buildPathArray(CONFIG_DIR_PATH, SERVER_XML)));

// get focus on server.xml tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, SERVER_XML);
Expand Down Expand Up @@ -592,9 +593,9 @@ public static void prepareEnv(String projectPath, String projectName) {
// get a JTreeFixture reference to the file project viewer entry
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2));
JTreeFixture projTree = projectFrame.getProjectViewJTree(projectName);
projTree.expand(TestUtils.combinePath(projectName, CONFIG_DIR_PATH));
projTree.expand(combinePath(projectName, CONFIG_DIR_PATH));

String[] configDirPath = TestUtils.combinePath(projectName, CONFIG_DIR_PATH);
String[] configDirPath = combinePath(projectName, CONFIG_DIR_PATH);

// open server.xml file
UIBotTestUtils.openFile(remoteRobot, projectName, SERVER_XML, configDirPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;
import static io.openliberty.tools.intellij.it.Utils.ItConstants.*;
import static io.openliberty.tools.intellij.it.TestUtils.*;

public abstract class SingleModMPLSTestCommon {
public static final String REMOTEBOT_URL = "http://localhost:8082";
Expand Down Expand Up @@ -97,7 +98,7 @@ public void testInsertCodeSnippetIntoJavaPart() {
// Insert a code snippet into java part
try {
UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, SERVICE_LIVE_HEALTH_CHECK_JAVA, snippetStr, snippetChooser);
Path pathToSrc = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVICE_LIVE_HEALTHCHECK_PATH));
Path pathToSrc = Paths.get(projectsPath, combinePath(projectName, buildPathArray(HEALTH_DIR_PATH, SERVICE_LIVE_HEALTH_CHECK_JAVA)));
TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode);
} finally {
// Replace modified content with the original content
Expand All @@ -124,7 +125,7 @@ public void testMPDiagnosticsInJavaPart() {

// Delete the liveness annotation
UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot, SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString);
Path pathToSrc = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVICE_LIVE_HEALTHCHECK_PATH));
Path pathToSrc = Paths.get(projectsPath, combinePath(projectName, buildPathArray(HEALTH_DIR_PATH, SERVICE_LIVE_HEALTH_CHECK_JAVA)));

try {
// validate @Liveness no longer found in java part
Expand Down Expand Up @@ -169,8 +170,8 @@ public void testMPQuickFixInJavaFile() {
UIBotTestUtils.copyWindowContent(remoteRobot);

// Delete the liveness annotation
UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot,SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString);
Path pathToSrc = Paths.get(projectsPath, TestUtils.combinePath(projectName, SERVICE_LIVE_HEALTHCHECK_PATH));
UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot, SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString);
Path pathToSrc = Paths.get(projectsPath, combinePath(projectName, buildPathArray(HEALTH_DIR_PATH, SERVICE_LIVE_HEALTH_CHECK_JAVA)));

try {
// validate @Liveness no longer found in java part
Expand Down Expand Up @@ -209,7 +210,7 @@ public void testInsertMicroProfileProperty() {

try {
UIBotTestUtils.insertConfigIntoMPConfigPropertiesFile(remoteRobot, MPCFG_PROPERTIES, cfgSnippet, cfgNameChooserSnippet, cfgValueSnippet, true);
Path pathToMpCfgProperties = Paths.get(projectsPath, TestUtils.combinePath(projectName, MPCFG_PATH));
Path pathToMpCfgProperties = Paths.get(projectsPath, combinePath(projectName, buildPathArray(META_INF_DIR_PATH, MPCFG_PROPERTIES)));
TestUtils.validateStringInFile(pathToMpCfgProperties.toString(), expectedMpCfgPropertiesString);
} finally {
// Replace modified microprofile-config.properties with the original content
Expand Down Expand Up @@ -295,7 +296,7 @@ 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, TestUtils.combinePath(projectName, MPCFG_PATH));
Path pathToMpCfgProperties = Paths.get(projectsPath, combinePath(projectName, buildPathArray(META_INF_DIR_PATH, MPCFG_PROPERTIES)));

// get focus on file tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, MPCFG_PROPERTIES);
Expand Down Expand Up @@ -344,8 +345,8 @@ public static void prepareEnv(String projectPath, String projectName) {
ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofMinutes(2));
JTreeFixture projTree = projectFrame.getProjectViewJTree(projectName);

UIBotTestUtils.openFile(remoteRobot, projectName, SERVICE_LIVEHEALTH_CHECK, TestUtils.combinePath(projectName, HEALTH_DIR_PATH));
UIBotTestUtils.openFile(remoteRobot, projectName, MPCFG_PROPERTIES, TestUtils.combinePath(projectName, META_INF_DIR_PATH));
UIBotTestUtils.openFile(remoteRobot, projectName, SERVICE_LIVEHEALTH_CHECK, combinePath(projectName, HEALTH_DIR_PATH_FOR_EXPAND));
UIBotTestUtils.openFile(remoteRobot, projectName, MPCFG_PROPERTIES, combinePath(projectName, META_INF_DIR_PATH));

// Removes the build tool window if it is opened. This prevents text to be hidden by it.
UIBotTestUtils.removeToolWindow(remoteRobot, "Build:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;
import static org.junit.jupiter.api.Assertions.fail;
import static io.openliberty.tools.intellij.it.Utils.ItConstants.*;
import static io.openliberty.tools.intellij.it.TestUtils.*;

/**
* Holds common tests that use a single module non Liberty Tools compliant REST project.
Expand Down Expand Up @@ -196,7 +197,7 @@ public void testsRefreshProjectWithServerXmlOnly() {

// Copy a valid server.xml file to this project's src/main/liberty/config directory.
Path validServerXml = Paths.get(getHelperFilesDirPath(), SERVER_XML);
Path destination = Paths.get(getProjectsDirPath(), TestUtils.combinePath(getSmNLTRestProjectName(), SERVER_XML_PATH));
Path destination = Paths.get(getProjectsDirPath(), combinePath(getSmNLTRestProjectName(), buildPathArray(CONFIG_DIR_PATH, SERVER_XML)));

try {
Files.copy(validServerXml, destination, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
Expand Down
24 changes: 18 additions & 6 deletions src/test/java/io/openliberty/tools/intellij/it/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void validateLibertyServerStopped(String testName, String wlpInsta
public static void validateLibertyServerStopped(String testName, String wlpInstallPath, int maxAttempts, boolean failOnNoStop) {
printTrace(TraceSevLevel.INFO, testName + ":validateLibertyServerStopped: Entry.");

String wlpMsgLogPath = Paths.get(wlpInstallPath, MESSAGES_LOG_PATH).toString();
String wlpMsgLogPath = Paths.get(wlpInstallPath, buildPathArray(MESSAGES_LOG_PATH, MESSAGES_LOG)).toString();
int retryIntervalSecs = 5;
boolean foundStoppedMsg = false;
Exception error = null;
Expand Down Expand Up @@ -168,7 +168,7 @@ public static void validateProjectStarted(String testName, String resourceURI, i
// If we are here, the expected outcome was not found. Print the Liberty server's messages.log and fail.
String msg = testName + ":validateProjectStarted: Timed out while waiting for project with resource URI " + resourceURI + "and port " + port + " to become available.";
printTrace(TraceSevLevel.ERROR, msg);
String wlpMsgLogPath = Paths.get(wlpInstallPath, MESSAGES_LOG_PATH).toString();
String wlpMsgLogPath = Paths.get(wlpInstallPath, buildPathArray(MESSAGES_LOG_PATH, MESSAGES_LOG)).toString();
String msgHeader = "Message log for failed test: " + testName + ":validateProjectStarted";
printLibertyMessagesLogFile(msgHeader, wlpMsgLogPath);
Assertions.fail(msg);
Expand Down Expand Up @@ -274,7 +274,7 @@ public static void validateProjectStopped(String testName, String projUrl, Strin
// If we are here, the expected outcome was not found. Print the Liberty server's messages.log and fail.
String msg = testName + ":validateProjectStopped: Timed out while waiting for project under URL: " + projUrl + " to stop.";
printTrace(TraceSevLevel.ERROR, msg);
String wlpMsgLogPath = Paths.get(wlpInstallPath, MESSAGES_LOG_PATH).toString();
String wlpMsgLogPath = Paths.get(wlpInstallPath, buildPathArray(MESSAGES_LOG_PATH, MESSAGES_LOG)).toString();
String msgHeader = "Message log for failed test: " + testName + ":validateProjectStopped";
printLibertyMessagesLogFile(msgHeader, wlpMsgLogPath);
Assertions.fail(msg);
Expand Down Expand Up @@ -516,7 +516,7 @@ public static void sleepAndIgnoreException(int seconds) {
*/
public static boolean isServerStopNeeded(String wlpInstallPath) {
boolean stopServer = false;
Path msgLogPath = Paths.get(wlpInstallPath, MESSAGES_LOG_PATH);
Path msgLogPath = Paths.get(wlpInstallPath, buildPathArray(MESSAGES_LOG_PATH, MESSAGES_LOG));
if (fileExists(msgLogPath)) {
try {
// The file maybe an old log. For now, check for the message indicating
Expand All @@ -541,7 +541,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, DEFAULT_SERVER_ENV_PATH);
Path serverEnvPath = Paths.get(absoluteWLPPath, buildPathArray(DEFAULT_SERVER_PATH, SERVER_ENV));
// Read all lines from server.env
List<String> lines = Files.readAllLines(serverEnvPath);
// Check if Debug Port is set to the specified port
Expand Down Expand Up @@ -604,11 +604,23 @@ public static void detectFatalError() {
* Combines the project name with a given array of paths.
*
* @param projectName the name of the project to prepend
* @param pathArray an array of paths to append to the project name
* @param pathArray an array of paths to append to the project name
* @return a new array with the project name as the first element followed by the original paths
*/
public static String[] combinePath(String projectName, String[] pathArray) {
return Stream.concat(Stream.of(projectName), Arrays.stream(pathArray))
.toArray(String[]::new);
}

/**
* Builds a new array by appending a file name to an existing path array.
*
* @param path An array of path segments.
* @param fileName The file name to append.
* @return A new array containing all elements of `path` followed by `fileName`.
*/
public static String[] buildPathArray(String[] path, String fileName) {
return Stream.concat(Stream.of(path), Stream.of(fileName))
.toArray(String[]::new);
}
}
Loading

0 comments on commit 25a376e

Please sign in to comment.