From e64cdbd8baba49b5dfcedf018871255bd71a5220 Mon Sep 17 00:00:00 2001 From: Anusree Lakshmi Date: Fri, 17 Jan 2025 15:52:27 +0530 Subject: [PATCH] path changed to string array --- .../it/SingleModJakartaLSTestCommon.java | 20 +++++++++++------- .../it/SingleModLibertyLSTestCommon.java | 21 ++++++++++--------- .../intellij/it/SingleModMPLSTestCommon.java | 21 ++++++++++++------- .../it/SingleModNLTRestProjectTestCommon.java | 3 ++- .../tools/intellij/it/TestUtils.java | 11 ++++++++-- .../tools/intellij/it/Utils/ItConstants.java | 15 +++++++------ 6 files changed, 58 insertions(+), 33 deletions(-) diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java index f92666e89..a683914b2 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java @@ -16,9 +16,13 @@ import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture; import org.junit.jupiter.api.*; +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError; @@ -92,7 +96,8 @@ public void testInsertJakartaCodeSnippetIntoJavaPart() { // Insert a code snippet into java part try { UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, ItConstants.SYSTEM_RESOURCE_JAVA, snippetStr, snippetChooser); - Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_JAVA); + String systemDirPath = Arrays.stream(ItConstants.SYSTEM_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToSrc = Paths.get(projectsPath, projectName, systemDirPath, ItConstants.SYSTEM_RESOURCE_JAVA); TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode); } finally { @@ -110,7 +115,8 @@ 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, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_2_JAVA); + String systemDirPath = Arrays.stream(ItConstants.SYSTEM_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToSrc = Paths.get(projectsPath, projectName, systemDirPath, ItConstants.SYSTEM_RESOURCE_2_JAVA); // get focus on file tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA); @@ -145,7 +151,8 @@ public void testJakartaQuickFixInJavaPart() { String privateString = "private Response getProperties() {"; String flaggedString = "getProperties"; - Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_2_JAVA); + String systemDirPath = Arrays.stream(ItConstants.SYSTEM_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToSrc = Paths.get(projectsPath, projectName, systemDirPath, ItConstants.SYSTEM_RESOURCE_2_JAVA); String quickfixChooserString = "Make method public"; // get focus on file tab prior to copy @@ -199,11 +206,10 @@ 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(projectName, ItConstants.SYSTEM_DIR_PATH); - - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE, projectName, "src", "main", "java", "io.openliberty.mp.sample", "system"); - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE_2, projectName, "src", "main", "java", "io.openliberty.mp.sample", "system"); + projTree.expand(projectName, String.join(File.separator, ItConstants.SYSTEM_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE, TestUtils.combinePath(projectName, ItConstants.SYSTEM_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE_2, TestUtils.combinePath(projectName, ItConstants.SYSTEM_DIR_PATH)); // Removes the build tool window if it is opened. This prevents text to be hidden by it. UIBotTestUtils.removeToolWindow(remoteRobot, "Build:"); 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 cb3f54547..23f468c18 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java @@ -17,6 +17,7 @@ import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture; import org.junit.jupiter.api.*; +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; @@ -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, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); + Path pathToServerXML = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedFeature); } finally { // Replace server.xml content with the original content @@ -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, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); + Path pathToServerXML = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedConfig); } finally { // Replace server.xml content with the original content @@ -188,7 +189,7 @@ public void testInsertLibertyConfigIntoServerEnvForCapitalCase() { try { UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, ItConstants.SERVER_ENV, envCfgSnippet, envCfgNameChooserSnippet, envCfgValueSnippet, true); - Path pathToServerEnv = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_ENV); + Path pathToServerEnv = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_ENV); TestUtils.validateStringInFile(pathToServerEnv.toString(), expectedServerEnvString); } finally { // Replace server.xml content with the original content @@ -273,7 +274,7 @@ public void testInsertLibertyConfigIntoBootstrapPropsForLowerCase() { try { UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, ItConstants.BOOTSTRAP_PROPERTIES, configNameSnippet, configNameChooserSnippet, configValueSnippet, true); - Path pathToBootstrapProps = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.BOOTSTRAP_PROPERTIES); + Path pathToBootstrapProps = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.BOOTSTRAP_PROPERTIES); TestUtils.validateStringInFile(pathToBootstrapProps.toString(), expectedBootstrapPropsString); } finally { // Replace server.xml content with the original content @@ -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, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); + pathToServerXML = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); // get focus on server.xml tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SERVER_XML); @@ -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, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); + pathToServerXML = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); // get focus on server.xml tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SERVER_XML); @@ -592,16 +593,16 @@ 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(projectName, ItConstants.CONFIG_DIR_PATH); + projTree.expand(projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH)); // open server.xml file - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_XML, projectName, "src", "main", "liberty", "config"); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_XML, TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH)); // open server.env file - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_ENV, projectName, "src", "main", "liberty", "config"); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_ENV, TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH)); // open bootstrap.properties file - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.BOOTSTRAP_PROPERTIES, projectName, "src", "main", "liberty", "config"); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.BOOTSTRAP_PROPERTIES, TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH)); // Removes the build tool window if it is opened. This prevents text to be hidden by it. UIBotTestUtils.removeToolWindow(remoteRobot, "Build:"); diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java index af91eed66..8ea1475b2 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java @@ -19,6 +19,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.Arrays; +import java.util.stream.Collectors; import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError; @@ -97,7 +99,8 @@ public void testInsertCodeSnippetIntoJavaPart() { // Insert a code snippet into java part try { 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); + String healthDirPath = Arrays.stream(ItConstants.HEALTH_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToSrc = Paths.get(projectsPath, projectName, healthDirPath, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode); } finally { // Replace modified content with the original content @@ -124,7 +127,8 @@ public void testMPDiagnosticsInJavaPart() { // Delete the liveness annotation UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString); - Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.HEALTH_DIR_PATH, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); + String healthDirPath = Arrays.stream(ItConstants.HEALTH_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToSrc = Paths.get(projectsPath, projectName, healthDirPath, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); try { // validate @Liveness no longer found in java part @@ -170,7 +174,8 @@ public void testMPQuickFixInJavaFile() { // Delete the liveness annotation UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot,ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString); - Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.HEALTH_DIR_PATH, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); + String healthDirPath = Arrays.stream(ItConstants.HEALTH_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToSrc = Paths.get(projectsPath, projectName, healthDirPath, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); try { // validate @Liveness no longer found in java part @@ -209,7 +214,8 @@ public void testInsertMicroProfileProperty() { try { UIBotTestUtils.insertConfigIntoMPConfigPropertiesFile(remoteRobot, ItConstants.MPG_PROPERTIES, cfgSnippet, cfgNameChooserSnippet, cfgValueSnippet, true); - Path pathToMpCfgProperties = Paths.get(projectsPath, projectName, ItConstants.META_INF_DIR_PATH, ItConstants.MPG_PROPERTIES); + String metaInfDirPath = Arrays.stream(ItConstants.META_INF_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToMpCfgProperties = Paths.get(projectsPath, projectName, metaInfDirPath, ItConstants.MPG_PROPERTIES); TestUtils.validateStringInFile(pathToMpCfgProperties.toString(), expectedMpCfgPropertiesString); } finally { // Replace modified microprofile-config.properties with the original content @@ -295,7 +301,8 @@ 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,ItConstants.META_INF_DIR_PATH, ItConstants.MPG_PROPERTIES); + String metaInfDirPath = Arrays.stream(ItConstants.META_INF_DIR_PATH).map(s -> s.replace(".", "/")).collect(Collectors.joining("/")); + Path pathToMpCfgProperties = Paths.get(projectsPath, projectName, metaInfDirPath, ItConstants.MPG_PROPERTIES); // get focus on file tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.MPG_PROPERTIES); @@ -344,8 +351,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, "ServiceLiveHealthCheck", projectName, "src", "main", "java", "io.openliberty.mp.sample", "health"); - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.MPG_PROPERTIES, projectName, "src", "main", "resources", "META-INF"); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVICE_LIVEHEALTH_CHECK, TestUtils.combinePath(projectName, ItConstants.HEALTH_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.MPG_PROPERTIES, TestUtils.combinePath(projectName, ItConstants.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:"); diff --git a/src/test/java/io/openliberty/tools/intellij/it/SingleModNLTRestProjectTestCommon.java b/src/test/java/io/openliberty/tools/intellij/it/SingleModNLTRestProjectTestCommon.java index 970423362..da2daea63 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModNLTRestProjectTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModNLTRestProjectTestCommon.java @@ -14,6 +14,7 @@ import io.openliberty.tools.intellij.it.Utils.ItConstants; import org.junit.jupiter.api.*; +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -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(), ItConstants.SERVER_XML); - Path destination = Paths.get(getProjectsDirPath(), getSmNLTRestProjectName(), ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); + Path destination = Paths.get(getProjectsDirPath(), getSmNLTRestProjectName(), String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); try { Files.copy(validServerXml, destination, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); diff --git a/src/test/java/io/openliberty/tools/intellij/it/TestUtils.java b/src/test/java/io/openliberty/tools/intellij/it/TestUtils.java index 23aaed82f..3653561b9 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/TestUtils.java +++ b/src/test/java/io/openliberty/tools/intellij/it/TestUtils.java @@ -18,7 +18,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; /** * Test utilities. @@ -28,7 +30,7 @@ public class TestUtils { /** * WLP messages.log path. */ - public static final Path WLP_MSGLOG_PATH = Paths.get(ItConstants.MESSAGES_LOG_PATH, "messages.log"); + public static final Path WLP_MSGLOG_PATH = Paths.get(String.join(File.separator, ItConstants.MESSAGES_LOG_PATH), "messages.log"); /** * Liberty server stopped message: @@ -542,7 +544,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, ItConstants.DEFAULT_SERVER_PATH, ItConstants.SERVER_ENV); + Path serverEnvPath = Paths.get(absoluteWLPPath, String.join(File.separator, ItConstants.DEFAULT_SERVER_PATH), ItConstants.SERVER_ENV); // Read all lines from server.env List lines = Files.readAllLines(serverEnvPath); // Check if Debug Port is set to the specified port @@ -599,4 +601,9 @@ public static void detectFatalError() { throw new RuntimeException(e); } } + + public static String[] combinePath(String projectName, String[] pathArray) { + return Stream.concat(Stream.of(projectName), Arrays.stream(pathArray)) + .toArray(String[]::new); + } } diff --git a/src/test/java/io/openliberty/tools/intellij/it/Utils/ItConstants.java b/src/test/java/io/openliberty/tools/intellij/it/Utils/ItConstants.java index 5662ca5fc..8f41d76c2 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/Utils/ItConstants.java +++ b/src/test/java/io/openliberty/tools/intellij/it/Utils/ItConstants.java @@ -18,13 +18,16 @@ public class ItConstants { public static final String SYSTEM_RESOURCE_2_JAVA = "SystemResource2.java"; public static final String SYSTEM_RESOURCE = "SystemResource"; public static final String SYSTEM_RESOURCE_2 = "SystemResource2"; + public static final String SERVICE_LIVEHEALTH_CHECK = "ServiceLiveHealthCheck"; + + public static final String[] CONFIG_DIR_PATH = { "src", "main", "liberty", "config" }; + public static final String[] SYSTEM_DIR_PATH = { "src", "main", "java", "io.openliberty.mp.sample", "system"}; + public static final String[] HEALTH_DIR_PATH = { "src", "main", "java", "io.openliberty.mp.sample", "health" }; + public static final String[] META_INF_DIR_PATH = { "src", "main", "resources", "META-INF" }; + public static final String[] DEFAULT_SERVER_PATH = { "wlp", "usr", "servers", "defaultServer" }; + public static final String[] MESSAGES_LOG_PATH = { "wlp", "usr", "servers", "defaultServer", "logs" }; + - public static final String CONFIG_DIR_PATH = "src/main/liberty/config"; - public static final String SYSTEM_DIR_PATH = "src/main/java/io/openliberty/mp/sample/system"; - public static final String HEALTH_DIR_PATH = "src/main/java/io/openliberty/mp/sample/health"; - public static final String META_INF_DIR_PATH = "src/main/resources/META-INF"; - public static final String DEFAULT_SERVER_PATH = "wlp/usr/servers/defaultServer"; - public static final String MESSAGES_LOG_PATH = "wlp/usr/servers/defaultServer/logs"; public static final String SERVER_XML = "server.xml"; public static final String SERVER_ENV = "server.env"; public static final String BOOTSTRAP_PROPERTIES = "bootstrap.properties";