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 a683914b2..75bc27ade 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModJakartaLSTestCommon.java @@ -16,13 +16,9 @@ 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; @@ -96,8 +92,7 @@ public void testInsertJakartaCodeSnippetIntoJavaPart() { // Insert a code snippet into java part try { UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, ItConstants.SYSTEM_RESOURCE_JAVA, snippetStr, snippetChooser); - 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); + Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_JAVA); TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode); } finally { @@ -115,8 +110,7 @@ public void testJakartaDiagnosticsInJavaPart() { String privateString = "private Response getProperties() {"; String flaggedString = "getProperties"; String expectedHoverData = "Only public methods can be exposed as resource methods"; - 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); + Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_2_JAVA); // get focus on file tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SYSTEM_RESOURCE_2_JAVA); @@ -151,8 +145,7 @@ public void testJakartaQuickFixInJavaPart() { String privateString = "private Response getProperties() {"; String flaggedString = "getProperties"; - 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); + Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.SYSTEM_DIR_PATH, ItConstants.SYSTEM_RESOURCE_2_JAVA); String quickfixChooserString = "Make method public"; // get focus on file tab prior to copy @@ -206,10 +199,11 @@ 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, String.join(File.separator, ItConstants.SYSTEM_DIR_PATH)); + projTree.expand(projectName, 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)); + String[] systemDirPath = TestUtils.combinePath(projectName, ItConstants.SYSTEM_DIR_PATH_ARR); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE, systemDirPath); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SYSTEM_RESOURCE_2, systemDirPath); // 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 23f468c18..ccbd15e41 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModLibertyLSTestCommon.java @@ -17,7 +17,6 @@ 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; @@ -132,7 +131,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, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); + Path pathToServerXML = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedFeature); } finally { // Replace server.xml content with the original content @@ -160,7 +159,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, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); + Path pathToServerXML = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); TestUtils.validateStanzaInConfigFile(pathToServerXML.toString(), insertedConfig); } finally { // Replace server.xml content with the original content @@ -189,7 +188,7 @@ public void testInsertLibertyConfigIntoServerEnvForCapitalCase() { try { UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, ItConstants.SERVER_ENV, envCfgSnippet, envCfgNameChooserSnippet, envCfgValueSnippet, true); - Path pathToServerEnv = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_ENV); + Path pathToServerEnv = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_ENV); TestUtils.validateStringInFile(pathToServerEnv.toString(), expectedServerEnvString); } finally { // Replace server.xml content with the original content @@ -274,7 +273,7 @@ public void testInsertLibertyConfigIntoBootstrapPropsForLowerCase() { try { UIBotTestUtils.insertConfigIntoConfigFile(remoteRobot, ItConstants.BOOTSTRAP_PROPERTIES, configNameSnippet, configNameChooserSnippet, configValueSnippet, true); - Path pathToBootstrapProps = Paths.get(projectsPath, projectName, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.BOOTSTRAP_PROPERTIES); + Path pathToBootstrapProps = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.BOOTSTRAP_PROPERTIES); TestUtils.validateStringInFile(pathToBootstrapProps.toString(), expectedBootstrapPropsString); } finally { // Replace server.xml content with the original content @@ -407,7 +406,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, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); + pathToServerXML = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); // get focus on server.xml tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SERVER_XML); @@ -443,7 +442,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, String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); + pathToServerXML = Paths.get(projectsPath, projectName, ItConstants.CONFIG_DIR_PATH, ItConstants.SERVER_XML); // get focus on server.xml tab prior to copy UIBotTestUtils.clickOnFileTab(remoteRobot, ItConstants.SERVER_XML); @@ -593,16 +592,18 @@ 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, String.join(File.separator, ItConstants.CONFIG_DIR_PATH)); + projTree.expand(projectName, ItConstants.CONFIG_DIR_PATH); + + String[] configDirPath = TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH_ARR); // open server.xml file - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_XML, TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_XML, configDirPath); // open server.env file - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_ENV, TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVER_ENV, configDirPath); // open bootstrap.properties file - UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.BOOTSTRAP_PROPERTIES, TestUtils.combinePath(projectName, ItConstants.CONFIG_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.BOOTSTRAP_PROPERTIES, configDirPath); // 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 1d0598281..aa94a2e2b 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModMPLSTestCommon.java @@ -20,8 +20,6 @@ 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; @@ -100,8 +98,7 @@ public void testInsertCodeSnippetIntoJavaPart() { // Insert a code snippet into java part try { UIBotTestUtils.insertCodeSnippetIntoSourceFile(remoteRobot, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA, snippetStr, snippetChooser); - 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); + Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.HEALTH_DIR_PATH, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); TestUtils.validateCodeInJavaSrc(pathToSrc.toString(), insertedCode); } finally { // Replace modified content with the original content @@ -128,8 +125,7 @@ public void testMPDiagnosticsInJavaPart() { // Delete the liveness annotation UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString); - 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); + Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.HEALTH_DIR_PATH, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); try { // validate @Liveness no longer found in java part @@ -175,8 +171,7 @@ public void testMPQuickFixInJavaFile() { // Delete the liveness annotation UIBotTestUtils.selectAndDeleteTextInJavaPart(remoteRobot,ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA, livenessString); - 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); + Path pathToSrc = Paths.get(projectsPath, projectName, ItConstants.HEALTH_DIR_PATH, ItConstants.SERVICE_LIVE_HEALTH_CHECK_JAVA); try { // validate @Liveness no longer found in java part @@ -350,7 +345,7 @@ 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, ItConstants.SERVICE_LIVEHEALTH_CHECK, TestUtils.combinePath(projectName, ItConstants.HEALTH_DIR_PATH)); + UIBotTestUtils.openFile(remoteRobot, projectName, ItConstants.SERVICE_LIVEHEALTH_CHECK, TestUtils.combinePath(projectName, ItConstants.HEALTH_DIR_PATH_ARR)); 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. 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 da2daea63..970423362 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/SingleModNLTRestProjectTestCommon.java +++ b/src/test/java/io/openliberty/tools/intellij/it/SingleModNLTRestProjectTestCommon.java @@ -14,7 +14,6 @@ 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; @@ -197,7 +196,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(), String.join(File.separator, ItConstants.CONFIG_DIR_PATH), ItConstants.SERVER_XML); + Path destination = Paths.get(getProjectsDirPath(), getSmNLTRestProjectName(), 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 3653561b9..cad40dd27 100644 --- a/src/test/java/io/openliberty/tools/intellij/it/TestUtils.java +++ b/src/test/java/io/openliberty/tools/intellij/it/TestUtils.java @@ -27,10 +27,6 @@ */ public class TestUtils { - /** - * WLP messages.log path. - */ - public static final Path WLP_MSGLOG_PATH = Paths.get(String.join(File.separator, ItConstants.MESSAGES_LOG_PATH), "messages.log"); /** * Liberty server stopped message: @@ -63,7 +59,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, WLP_MSGLOG_PATH.toString()).toString(); + String wlpMsgLogPath = Paths.get(wlpInstallPath, ItConstants.MESSAGES_LOG_PATH).toString(); int retryIntervalSecs = 5; boolean foundStoppedMsg = false; Exception error = null; @@ -171,7 +167,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, WLP_MSGLOG_PATH.toString()).toString(); + String wlpMsgLogPath = Paths.get(wlpInstallPath, ItConstants.MESSAGES_LOG_PATH).toString(); String msgHeader = "Message log for failed test: " + testName + ":validateProjectStarted"; printLibertyMessagesLogFile(msgHeader, wlpMsgLogPath); Assertions.fail(msg); @@ -277,7 +273,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, WLP_MSGLOG_PATH.toString()).toString(); + String wlpMsgLogPath = Paths.get(wlpInstallPath, ItConstants.MESSAGES_LOG_PATH).toString(); String msgHeader = "Message log for failed test: " + testName + ":validateProjectStopped"; printLibertyMessagesLogFile(msgHeader, wlpMsgLogPath); Assertions.fail(msg); @@ -519,7 +515,7 @@ public static void sleepAndIgnoreException(int seconds) { */ public static boolean isServerStopNeeded(String wlpInstallPath) { boolean stopServer = false; - Path msgLogPath = Paths.get(wlpInstallPath, WLP_MSGLOG_PATH.toString()); + Path msgLogPath = Paths.get(wlpInstallPath, ItConstants.MESSAGES_LOG_PATH); if (fileExists(msgLogPath)) { try { // The file maybe an old log. For now, check for the message indicating @@ -544,7 +540,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, String.join(File.separator, ItConstants.DEFAULT_SERVER_PATH), ItConstants.SERVER_ENV); + Path serverEnvPath = Paths.get(absoluteWLPPath, 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 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 8f41d76c2..e3eac5f78 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 @@ -20,12 +20,15 @@ public class ItConstants { 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 CONFIG_DIR_PATH = "src/main/liberty/config"; + public static final String[] CONFIG_DIR_PATH_ARR = { "src", "main", "liberty", "config" }; + public static final String SYSTEM_DIR_PATH = "src/main/java/io/openliberty/mp/sample/system"; + public static final String[] SYSTEM_DIR_PATH_ARR = { "src", "main", "java", "io.openliberty.mp.sample", "system"}; + public static final String HEALTH_DIR_PATH = "src/main/java/io/openliberty/mp/sample/system"; + public static final String[] HEALTH_DIR_PATH_ARR = { "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 DEFAULT_SERVER_PATH = "wlp/usr/servers/defaultServer"; + public static final String MESSAGES_LOG_PATH = "wlp/usr/servers/defaultServer/logs/messages.log"; public static final String SERVER_XML = "server.xml";