Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anusreelakshmi934 committed Jan 22, 2025
1 parent f1d400d commit 31ca81d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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

0 comments on commit 31ca81d

Please sign in to comment.