Skip to content

Commit

Permalink
Merge pull request OpenLiberty#941 from turkeylurkey/issue-939
Browse files Browse the repository at this point in the history
Check for test reports in two locations.
  • Loading branch information
turkeylurkey authored Sep 5, 2024
2 parents f80d006 + 552db04 commit d98c892
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 44 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ For minimum requirements information and detailed instructions on how to use the

The following actions are available when you select a project in the Liberty Tool Window.

| Action | Description |
|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Start | Start dev mode. |
| Action | Description |
|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Start | Start dev mode. |
| Start… | Open the **Run Configurations** dialog to customize and start dev mode. Supported parameters can be found in the documentation for the [dev goal of the Liberty Maven Plugin](https://github.com/OpenLiberty/ci.maven/blob/master/docs/dev.md#additional-parameters) and the [libertyDev task of the Liberty Gradle Plugin](https://github.com/OpenLiberty/ci.gradle/blob/master/docs/libertyDev.md#command-line-parameters). |
| Start in a container | Start dev mode with Liberty running in a container. The `liberty-maven-plugin` must be version `3.3-M1` or higher. The `liberty-gradle-plugin` must be version `3.1-M1` or higher.
| Stop | Stop dev mode. Liberty must be running in dev mode to use this command. |
| Run tests | Run the unit tests and integration tests that are configured for your project. Liberty must be running in dev mode to use this command. |
| View integration test report (Maven) | View the integration test report file if it exists at `/target/site/failsafe-report.html`. |
| View unit test report (Maven) | View the unit test report file if it exists at `/target/site/surefire-report.html`. |
| View test report (Gradle) | Open the test report file, if it exists at the `build/reports/tests/test/index.html` default location. This action command is available only to Gradle projects. Gradle projects have only a single action command for test result reporting. |
| Stop | Stop dev mode. Liberty must be running in dev mode to use this command. |
| Run tests | Run the unit tests and integration tests that are configured for your project. Liberty must be running in dev mode to use this command. |
| View integration test report (Maven) | View the integration test report file if it exists at `target/reports/failsafe.html` or `target/site/failsafe-report.html`. |
| View unit test report (Maven) | View the unit test report file if it exists at `target/reports/surefire.html` or `target/site/surefire-report.html`. |
| View test report (Gradle) | Open the test report file, if it exists at the `build/reports/tests/test/index.html` default location. This action command is available only to Gradle projects. Gradle projects have only a single action command for test result reporting. |

## Technical support
If you experience a problem with this plugin you might be asked to collect language server messages to assist in problem determination. Follow these steps:
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ After you finish running your application tests, you can access the produced tes

To view the integration test report for Maven-built applications, select the **View integration test report** action for your application in the Liberty tool window.

This action looks for the integration test report at the `/target/site/failsafe-report.html` default location.
This action looks for the integration test report at two default locations: `target/reports/failsafe.html` and `target/site/failsafe-report.html`.

To view the unit test report for Maven-built applications, select the **View unit test report** action for your application in the Liberty tool window.

This action looks for the unit test report at the `/target/site/surefire-report.html` default location.
This action looks for the unit test report at two default locations: `target/reports/surefire.html` and `target/site/surefire-report.html`.

### Gradle-built applications

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.openliberty.tools.intellij.LibertyPluginIcons;
import io.openliberty.tools.intellij.util.Constants;
import io.openliberty.tools.intellij.util.LocalizedResourceUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.nio.file.Paths;
Expand Down Expand Up @@ -48,17 +49,23 @@ protected void executeLibertyAction(LibertyModule libertyModule) {

// get path to project folder
final VirtualFile parentFile = buildFile.getParent();
File failsafeReportFile = Paths.get(parentFile.getPath(), "target", "site", "failsafe-report.html").normalize().toAbsolutePath().toFile();
VirtualFile failsafeReportVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(failsafeReportFile);

// Dev mode runs the tests and it may have selected a report generator that uses one location and filename or another depending on the version number
// Maven plugin maven-surefire-report-plugin v3.5 and above use this location and filename
File failsafeReportFile = getReportFile(parentFile, "reports", "failsafe.html");
VirtualFile failsafeReportVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(failsafeReportFile);
if (failsafeReportVirtualFile == null || !failsafeReportVirtualFile.exists()) {
// Maven plugin maven-surefire-report-plugin v3.4 and below use this location and filename
failsafeReportFile = getReportFile(parentFile, "site", "failsafe-report.html");
failsafeReportVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(failsafeReportFile);
}

if (failsafeReportVirtualFile == null || !failsafeReportVirtualFile.exists()) {
Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID,
LocalizedResourceUtil.getMessage("integration.test.report.does.not.exist.notification.title"),
LocalizedResourceUtil.getMessage("test.report.does.not.exist", failsafeReportFile.getAbsolutePath()),
NotificationType.ERROR);
notif.setIcon(LibertyPluginIcons.libertyIcon);

Notifications.Bus.notify(notif, project);
LOGGER.debug("Integration test report does not exist at : " + failsafeReportFile.getAbsolutePath());
return;
Expand All @@ -68,4 +75,9 @@ protected void executeLibertyAction(LibertyModule libertyModule) {
BrowserUtil.browse(failsafeReportVirtualFile.getUrl());
}

@NotNull
private File getReportFile(VirtualFile parentFile, String dir, String filename) {
return Paths.get(parentFile.getPath(), "target", dir, filename).normalize().toAbsolutePath().toFile();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.openliberty.tools.intellij.LibertyPluginIcons;
import io.openliberty.tools.intellij.util.Constants;
import io.openliberty.tools.intellij.util.LocalizedResourceUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.nio.file.Paths;
Expand Down Expand Up @@ -48,8 +49,16 @@ protected void executeLibertyAction(LibertyModule libertyModule) {

// get path to project folder
final VirtualFile parentFile = buildFile.getParent();
File surefireReportFile = Paths.get(parentFile.getPath(), "target", "site", "surefire-report.html").normalize().toAbsolutePath().toFile();

// Dev mode runs the tests and it may have selected a report generator that uses one location or another depending on the version number
// Maven plugin maven-surefire-report-plugin v3.5 and above use this location
File surefireReportFile = getReportFile(parentFile, "reports", "surefire.html");
VirtualFile surefireReportVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(surefireReportFile);
if (surefireReportVirtualFile == null || !surefireReportVirtualFile.exists()) {
// Maven plugin maven-surefire-report-plugin v3.4 and below use this location
surefireReportFile = getReportFile(parentFile,"site", "surefire-report.html");
surefireReportVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(surefireReportFile);
}

if (surefireReportVirtualFile == null || !surefireReportVirtualFile.exists()) {
Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID,
Expand All @@ -67,4 +76,8 @@ protected void executeLibertyAction(LibertyModule libertyModule) {
BrowserUtil.browse(surefireReportVirtualFile.getUrl());
}

@NotNull
private File getReportFile(VirtualFile parentFile, String dir, String filename) {
return Paths.get(parentFile.getPath(), "target", dir, filename).normalize().toAbsolutePath().toFile();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public void deleteTestReports() {
*/
@Override
public void validateTestReportsExist() {
TestUtils.validateTestReportExists(TEST_REPORT_PATH);
//TODO: rewrite validateTestReportExists() to accept one argument or to accept a null as the second argument
TestUtils.validateTestReportExists(TEST_REPORT_PATH, TEST_REPORT_PATH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@ public void deleteTestReports() {
*/
@Override
public void validateTestReportsExist() {
TestUtils.validateTestReportExists(TEST_REPORT_PATH);
TestUtils.validateTestReportExists(TEST_REPORT_PATH, TEST_REPORT_PATH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ public class MavenSingleModMPProjectTest extends SingleModMPProjectTestCommon {
private final String BUILD_FILE_OPEN_CMD = "Liberty: View pom.xml";

/**
* The path to the integration test reports.
* 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 pathToITReport = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "site", "failsafe-report.html");
private final Path pathToITReport34 = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "site", "failsafe-report.html");
private final Path pathToITReport35 = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "reports", "failsafe.html");

/**
* The path to the unit test reports.
* 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 pathToUTReport = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "site", "surefire-report.html");
private final Path pathToUTReport34 = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "site", "surefire-report.html");
private final Path pathToUTReport35 = Paths.get(PROJECTS_PATH, SM_MP_PROJECT_NAME, "target", "reports", "surefire.html");

/**
* Dev mode configuration start parameters.
Expand Down Expand Up @@ -198,19 +200,23 @@ public String getStartParamsDebugPort() {
*/
@Override
public void deleteTestReports() {
boolean itReportDeleted = TestUtils.deleteFile(pathToITReport);
Assertions.assertTrue(itReportDeleted, () -> "Test report file: " + pathToITReport + " was not be deleted.");

boolean utReportDeleted = TestUtils.deleteFile(pathToUTReport);
Assertions.assertTrue(utReportDeleted, () -> "Test report file: " + pathToUTReport + " was not be deleted.");
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(pathToITReport);
TestUtils.validateTestReportExists(pathToUTReport);
TestUtils.validateTestReportExists(pathToITReport34, pathToITReport35);
TestUtils.validateTestReportExists(pathToUTReport34, pathToUTReport35);
}
}
Loading

0 comments on commit d98c892

Please sign in to comment.