Skip to content

Commit

Permalink
Added test to support multiple projects
Browse files Browse the repository at this point in the history
  • Loading branch information
vaisakhkannan committed Jan 16, 2025
1 parent 75d3bf7 commit bc79157
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GradleSingleModMPProjectTest extends SingleModMPProjectTestCommon {
*/
@BeforeAll
public static void setup() {
prepareEnv(PROJECTS_PATH, SM_MP_PROJECT_NAME);
prepareEnv(PROJECTS_PATH, SM_MP_PROJECT_NAME, false);
}

GradleSingleModMPProjectTest() {
Expand All @@ -48,5 +48,6 @@ public static void setup() {
setBuildFileOpenCommand("Liberty: View Gradle config");
setStartParams("--hotTests");
setStartParamsDebugPort("--libertyDebugPort=9876");
setProjectTypeIsMultiple(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void setup() {
Files.move(projectDirPath, projectDirNewPath, StandardCopyOption.REPLACE_EXISTING);

// Prepare the environment with the new project path and name
prepareEnv(PROJECTS_PATH_NEW, SM_MP_PROJECT_NAME_NEW);
prepareEnv(PROJECTS_PATH_NEW, SM_MP_PROJECT_NAME_NEW, false);

} catch (IOException e) {
System.err.println("Setup failed: " + e.getMessage());
Expand Down Expand Up @@ -106,5 +106,6 @@ public static void cleanup() {
setBuildFileOpenCommand("Liberty: View Gradle config");
setStartParams("--hotTests");
setStartParamsDebugPort("--libertyDebugPort=9876");
setProjectTypeIsMultiple(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.tools.intellij.it;

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

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Tests Liberty Tools actions using a single module MicroProfile Gradle project with space in directory and name.
*/
public class MavenMPMultipleProjectTest extends SingleModMPProjectTestCommon {

/**
* Single module Microprofile project name.
*/
private static final String SM_MP_PROJECT_NAME = "singleModMavenMP";

private static final String MAVEN_MULTIPLE_PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "multiple-project", "singleModMavenMP").toAbsolutePath().toString();

private static final String MULTIPLE_PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "multiple-project").toAbsolutePath().toString();
private static final String MULTIPLE_PROJECTS_PATH_PARENT = Paths.get("src", "test", "resources", "projects").toAbsolutePath().toString();

private static final String GRADLE_PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "gradle", "singleModGradleMP").toAbsolutePath().toString();

private static final String MAVEN_PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "maven", "singleModMavenMP").toAbsolutePath().toString();

private static final String GRADLE_MULTIPLE_PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "multiple-project", "singleModGradleMP").toAbsolutePath().toString();

/**
* The paths to the integration test reports. The first is used when maven-surefire-report-plugin 3.4 is used and the second when version 3.5 is used.
*/
private final Path pathToITReport34 = Paths.get(MULTIPLE_PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "site", "failsafe-report.html");
private final Path pathToITReport35 = Paths.get(MULTIPLE_PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "reports", "failsafe.html");

/**
* The paths to the unit test reports. The first is used when maven-surefire-report-plugin 3.4 is used and the second when version 3.5 is used.
*/
private final Path pathToUTReport34 = Paths.get(MULTIPLE_PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "site", "surefire-report.html");
private final Path pathToUTReport35 = Paths.get(MULTIPLE_PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "reports", "surefire.html");



/**
* Prepares the environment for test execution.
*/
@BeforeAll
public static void setup() {
try {
File theDir = new File(MULTIPLE_PROJECTS_PATH);
System.out.println("---------------"+theDir);
if (theDir.exists()){
TestUtils.deleteDirectory(theDir);
System.out.println("---------------Inside If loop--------------");
}
theDir.mkdirs();
System.out.println("---------------"+theDir);

// Copy the directory to allow renaming.
TestUtils.copyDirectory(GRADLE_PROJECTS_PATH, GRADLE_MULTIPLE_PROJECTS_PATH);
TestUtils.copyDirectory(MAVEN_PROJECTS_PATH, MAVEN_MULTIPLE_PROJECTS_PATH);

// Prepare the environment with the new project path and name
prepareEnv(MULTIPLE_PROJECTS_PATH_PARENT, SM_MP_PROJECT_NAME, true);

} catch (IOException e) {
System.err.println("Setup failed: " + e.getMessage());
e.printStackTrace();
Assertions.fail("Test setup failed due to an IOException: " + e.getMessage());
}
}

/**
* Cleanup includes deleting the created project path.
*/
@AfterAll
public static void cleanup() {
try {
closeProjectView();
} finally {
deleteDirectoryIfExists(MULTIPLE_PROJECTS_PATH);
}
}

MavenMPMultipleProjectTest() {
// set the new locations for the test, not the original locations
setProjectsDirPath(MULTIPLE_PROJECTS_PATH);
setTestReportPath(Paths.get(MULTIPLE_PROJECTS_PATH, SM_MP_PROJECT_NAME, "build", "reports", "tests", "test", "index.html"));
setSmMPProjectName(SM_MP_PROJECT_NAME);
setBuildCategory(BuildType.MAVEN_TYPE);
setSmMpProjPort(9080);
setSmMpProjResURI("api/resource");
setSmMPProjOutput("Hello! Welcome to Open Liberty");
setWLPInstallPath(Paths.get("target", "liberty").toString());
setBuildFileName("pom.xml");
setBuildFileOpenCommand("Liberty: View pom.xml");
setStartParams("-DhotTests=true");
setStartParamsDebugPort("-DdebugPort=9876");
setProjectTypeIsMultiple(true);
}

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

boolean utReportDeleted = TestUtils.deleteFile(pathToUTReport34);
Assertions.assertTrue(utReportDeleted, () -> "Test report file: " + pathToUTReport34 + " was not be deleted.");
utReportDeleted = TestUtils.deleteFile(pathToUTReport35);
Assertions.assertTrue(utReportDeleted, () -> "Test report file: " + pathToUTReport35 + " was not be deleted.");
}

/**
* Validates that test reports were generated.
*/
@Override
public void validateTestReportsExist() {
TestUtils.validateTestReportExists(pathToITReport34, pathToITReport35);
TestUtils.validateTestReportExists(pathToUTReport34, pathToUTReport35);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class MavenSingleModMPProjectTest extends SingleModMPProjectTestCommon {
@BeforeAll
public static void setup() {
StepWorker.registerProcessor(new StepLogger());
prepareEnv(PROJECTS_PATH, SM_MP_PROJECT_NAME);
prepareEnv(PROJECTS_PATH, SM_MP_PROJECT_NAME, false);
}

MavenSingleModMPProjectTest() {
Expand All @@ -66,6 +66,7 @@ public static void setup() {
setBuildFileOpenCommand("Liberty: View pom.xml");
setStartParams("-DhotTests=true");
setStartParamsDebugPort("-DdebugPort=9876");
setProjectTypeIsMultiple(false);
}
/**
* Deletes test reports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void setup() {
StepWorker.registerProcessor(new StepLogger());
// Copy the directory from PROJECTS_PATH to PROJECTS_PATH_NEW
TestUtils.copyDirectory(PROJECTS_PATH, PROJECTS_PATH_NEW);
prepareEnv(PROJECTS_PATH_NEW, SM_MP_PROJECT_NAME);
prepareEnv(PROJECTS_PATH_NEW, SM_MP_PROJECT_NAME, false);
} catch (IOException e) {
System.err.println("Setup failed: " + e.getMessage());
e.printStackTrace();
Expand Down Expand Up @@ -94,6 +94,7 @@ public static void cleanup() {
setBuildFileOpenCommand("Liberty: View pom.xml");
setStartParams("-DhotTests=true");
setStartParamsDebugPort("-DdebugPort=9876");
setProjectTypeIsMultiple(false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void cleanup() {
UIBotTestUtils.closeFileEditorTab(remoteRobot, "server.env", "5");
UIBotTestUtils.closeFileEditorTab(remoteRobot, "bootstrap.properties", "5");
if (!remoteRobot.isMac()) {
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3);
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3, false);
}
UIBotTestUtils.closeProjectView(remoteRobot);
UIBotTestUtils.closeProjectFrame(remoteRobot);
Expand Down Expand Up @@ -581,7 +581,7 @@ public static void prepareEnv(String projectPath, String projectName) {
UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
if (!remoteRobot.isMac()) {
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3);
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3, false);
}
// IntelliJ does not start building and indexing until the Project View is open
UIBotTestUtils.waitForIndexing(remoteRobot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void cleanup() {
UIBotTestUtils.closeFileEditorTab(remoteRobot, "ServiceLiveHealthCheck.java", "5");
UIBotTestUtils.closeFileEditorTab(remoteRobot, "microprofile-config.properties", "5");
if (!remoteRobot.isMac()) {
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3);
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3, false);
}
UIBotTestUtils.closeProjectView(remoteRobot);
UIBotTestUtils.closeProjectFrame(remoteRobot);
Expand Down Expand Up @@ -332,7 +332,7 @@ public static void prepareEnv(String projectPath, String projectName) {
UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
if (!remoteRobot.isMac()) {
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3);
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3, false);
}
// IntelliJ does not start building and indexing until the Project View is open
UIBotTestUtils.waitForIndexing(remoteRobot);
Expand Down
Loading

0 comments on commit bc79157

Please sign in to comment.