Skip to content

Commit

Permalink
path changed to string array
Browse files Browse the repository at this point in the history
  • Loading branch information
anusreelakshmi934 committed Jan 17, 2025
1 parent 97eac05 commit e64cdbd
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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, 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
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, 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
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, 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);
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, 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);
Expand Down Expand Up @@ -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:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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(), 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);
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/io/openliberty/tools/intellij/it/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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<String> lines = Files.readAllLines(serverEnvPath);
// Check if Debug Port is set to the specified port
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit e64cdbd

Please sign in to comment.