Skip to content

Commit

Permalink
Merge pull request #1083 from turkeylurkey/refactor-IT
Browse files Browse the repository at this point in the history
Refactor the automated UI tests for easier maintenance
  • Loading branch information
turkeylurkey authored Nov 13, 2024
2 parents 14e0597 + ad42003 commit fb1762e
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 876 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
*******************************************************************************/
package io.openliberty.tools.intellij.it;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Tests Liberty Tools actions using a single module MicroProfile Gradle project.
*/
public class GradleSingleModMPProjectTest extends SingleModMPProjectTestCommon {

/**
* Single module Microprofile project name.
*/
Expand All @@ -30,56 +27,6 @@ public class GradleSingleModMPProjectTest extends SingleModMPProjectTestCommon {
*/
private static final String PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "gradle").toAbsolutePath().toString();

/**
* Project port.
*/
private final int SM_MP_PROJECT_PORT = 9080;

/**
* Project resource URI.
*/
private final String SM_MP_PROJECT_RES_URI = "api/resource";

/**
* Project response.
*/
private final String SM_MP_PROJECT_OUTPUT = "Hello! Welcome to Open Liberty";

/**
* Relative location of the WLP installation.
*/
private final String WLP_INSTALL_PATH = "build";

/**
* The path to the test report.
*/
private final Path TEST_REPORT_PATH = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "build", "reports", "tests", "test", "index.html");

/**
* Build file name.
*/
private final String BUILD_FILE_NAME = "build.gradle";

/**
* Build Category.
*/
private final BuildType BUILD_CATEGORY = BuildType.GRADLE_TYPE;

/**
* Action command to open the build file.
*/
private final String BUILD_FILE_OPEN_CMD = "Liberty: View Gradle config";

/**
* Dev mode configuration start parameters.
*/
private final String DEV_MODE_START_PARAMS = "--hotTests";

/**
* Dev mode configuration custom start parameters for debugging.
*/
private final String DEV_MODE_START_PARAMS_DEBUG = "--libertyDebugPort=9876";

/**
* Prepares the environment for test execution.
*/
Expand All @@ -88,131 +35,18 @@ public static void setup() {
prepareEnv(PROJECTS_PATH, SM_MP_PROJECT_NAME);
}

/**
* Returns the path where the Liberty server was installed.
*
* @return The path where the Liberty server was installed.
*/
@Override
public String getWLPInstallPath() {
return WLP_INSTALL_PATH;
}

/**
* Returns the projects directory path.
*
* @return The projects directory path.
*/
@Override
public String getProjectsDirPath() {
return PROJECTS_PATH;
}

/**
* Returns the name of the single module MicroProfile project.
*
* @return The name of the single module MicroProfile project.
*/
@Override
public String getSmMPProjectName() {
return SM_MP_PROJECT_NAME;
}

/**
* Returns the expected HTTP response payload associated with the single module
* MicroProfile project.
*
* @return The expected HTTP response payload associated with the single module
* MicroProfile project.
*/
@Override
public String getSmMPProjOutput() {
return SM_MP_PROJECT_OUTPUT;
}

/**
* Returns the port number associated with the single module MicroProfile project.
*
* @return The port number associated with the single module MicroProfile project.
*/
@Override
public int getSmMpProjPort() {
return SM_MP_PROJECT_PORT;
}

/**
* Return the Resource URI associated with the single module MicroProfile project.
*
* @return The Resource URI associated with the single module MicroProfile project.
*/
@Override
public String getSmMpProjResURI() {
return SM_MP_PROJECT_RES_URI;
}

/**
* Returns the name of the build file used by the project.
*
* @return The name of the build file used by the project.
*/
@Override
public String getBuildFileName() {
return BUILD_FILE_NAME;
}

/**
* Returns the name of the custom action command used to open the build file.
*
* @return The name of the custom action command used to open the build file.
*/
@Override
public String getBuildFileOpenCommand() {
return BUILD_FILE_OPEN_CMD;
}

/**
* Returns the custom start parameters to be used to start dev mode.
*
* @return The custom start parameters to be used to start dev mode.
*/
@Override
public String getStartParams() {
return DEV_MODE_START_PARAMS;
}

/**
* Returns the custom start parameters for debugging to start dev mode.
*
* @return The custom start parameters for debugging to start dev mode.
*/
@Override
public String getStartParamsDebugPort() {
return DEV_MODE_START_PARAMS_DEBUG;
}

/**
* Deletes test reports.
*/
@Override
public void deleteTestReports() {
boolean testReportDeleted = TestUtils.deleteFile(TEST_REPORT_PATH);
Assertions.assertTrue(testReportDeleted, () -> "Test report file: " + TEST_REPORT_PATH + " was not be deleted.");
}

/**
* Validates that test reports were generated.
*/
@Override
public void validateTestReportsExist() {
//TODO: rewrite validateTestReportExists() to accept one argument or to accept a null as the second argument
TestUtils.validateTestReportExists(TEST_REPORT_PATH, TEST_REPORT_PATH);
}

/**
* Returns the build type category (either MAVEN_TYPE or GRADLE_TYPE)
*/
@Override
public BuildType getBuildCategory() {
return BUILD_CATEGORY;
GradleSingleModMPProjectTest() {
setProjectsDirPath(PROJECTS_PATH);
setSmMPProjectName(SM_MP_PROJECT_NAME);
setBuildCategory(BuildType.GRADLE_TYPE);
setSmMpProjPort(9080);
setSmMpProjResURI("api/resource");
setSmMPProjOutput("Hello! Welcome to Open Liberty");
setWLPInstallPath("build");
setTestReportPath(Paths.get(getProjectsDirPath(), getSmMPProjectName(), "build", "reports", "tests", "test", "index.html"));
setBuildFileName("build.gradle");
setBuildFileOpenCommand("Liberty: View Gradle config");
setStartParams("--hotTests");
setStartParamsDebugPort("--libertyDebugPort=9876");
}
}
Loading

0 comments on commit fb1762e

Please sign in to comment.