Skip to content

Commit

Permalink
Add test report lookup location
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Wisniewski <[email protected]>
  • Loading branch information
awisniew90 committed Sep 4, 2024
1 parent bda813c commit c2800c9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -563,22 +562,13 @@ public void openMavenIntegrationTestReport(IProject inputProject) {
}

// Get the path to the test report.
Path path = getMavenIntegrationTestReportPath(projectPath);
if (!path.toFile().exists()) {
String msg = "No integration test results were found for project " + projectName + ". Select \""
+ DashboardView.APP_MENU_ACTION_RUN_TESTS + "\" before you select \""
+ DashboardView.APP_MENU_ACTION_VIEW_MVN_IT_REPORT + "\" on the menu.";
if (Trace.isEnabled()) {
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg + " No-op. Path: " + path);
}
ErrorHandler.processErrorMessage(NLS.bind(Messages.mvn_int_test_report_none_found, new String[] { projectName,
DashboardView.APP_MENU_ACTION_RUN_TESTS, DashboardView.APP_MENU_ACTION_VIEW_MVN_IT_REPORT }), true);
return;
}
Path path = getMavenIntegrationTestReportPath(projectPath, projectName);

// Display the report on the browser. Browser display is based on eclipse configuration preferences.
String browserTabTitle = projectName + " " + BROWSER_MVN_IT_REPORT_NAME_SUFFIX;
openTestReport(projectName, path, path.toString(), browserTabTitle, browserTabTitle);
if (path != null) {
// Display the report on the browser. Browser display is based on eclipse configuration preferences.
String browserTabTitle = projectName + " " + BROWSER_MVN_IT_REPORT_NAME_SUFFIX;
openTestReport(projectName, path, path.toString(), browserTabTitle, browserTabTitle);
}
} catch (Exception e) {
String msg = "An error was detected when the view integration test report request was processed on project " + projectName
+ ".";
Expand Down Expand Up @@ -637,22 +627,13 @@ public void openMavenUnitTestReport(IProject inputProject) {
}

// Get the path to the test report.
Path path = getMavenUnitTestReportPath(projectPath);
if (!path.toFile().exists()) {
String msg = "No unit test results were found for project " + projectName + ". Select \""
+ DashboardView.APP_MENU_ACTION_RUN_TESTS + "\" before you select \""
+ DashboardView.APP_MENU_ACTION_VIEW_MVN_UT_REPORT + "\" on the menu.";
if (Trace.isEnabled()) {
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg + " No-op. Path: " + path);
}
ErrorHandler.processErrorMessage(NLS.bind(Messages.mvn_unit_test_report_none_found, new String[] { projectName,
DashboardView.APP_MENU_ACTION_RUN_TESTS, DashboardView.APP_MENU_ACTION_VIEW_MVN_UT_REPORT }), true);
return;
}
Path path = getMavenUnitTestReportPath(projectPath, projectName);

// Display the report on the browser. Browser display is based on eclipse configuration preferences.
String browserTabTitle = projectName + " " + BROWSER_MVN_UT_REPORT_NAME_SUFFIX;
openTestReport(projectName, path, path.toString(), browserTabTitle, browserTabTitle);
if (path != null) {
// Display the report on the browser. Browser display is based on eclipse configuration preferences.
String browserTabTitle = projectName + " " + BROWSER_MVN_UT_REPORT_NAME_SUFFIX;
openTestReport(projectName, path, path.toString(), browserTabTitle, browserTabTitle);
}
} catch (Exception e) {
String msg = "An error was detected when the view unit test report request was processed on project " + projectName + ".";
if (Trace.isEnabled()) {
Expand Down Expand Up @@ -983,10 +964,23 @@ public void run() {
*
* @return The path of the HTML file containing the integration test report.
*/
public static Path getMavenIntegrationTestReportPath(String projectPath) {
Path path = Paths.get(projectPath, "target", "site", "failsafe-report.html");
public static Path getMavenIntegrationTestReportPath(String projectPath, String projectName) {
Path path1 = Paths.get(projectPath, "target", "failsafe-report.html");
Path path2 = Paths.get(projectPath, "target", "site", "failsafe-report.html");

if (!path1.toFile().exists() && !path2.toFile().exists()) {
String msg = "No integration test results were found for project " + projectName + ". Select \""
+ DashboardView.APP_MENU_ACTION_RUN_TESTS + "\" before you select \""
+ DashboardView.APP_MENU_ACTION_VIEW_MVN_IT_REPORT + "\" on the menu.";
if (Trace.isEnabled()) {
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg + " No-op. Paths checked: " + path1 + ", " + path2);
}
ErrorHandler.processErrorMessage(NLS.bind(Messages.mvn_int_test_report_none_found, new String[] { projectName,
DashboardView.APP_MENU_ACTION_RUN_TESTS, DashboardView.APP_MENU_ACTION_VIEW_MVN_IT_REPORT }), true);
return null;
}

return path;
return path1.toFile().exists() ? path1 : path2;
}

/**
Expand All @@ -996,10 +990,23 @@ public static Path getMavenIntegrationTestReportPath(String projectPath) {
*
* @return The path of the HTML file containing the unit test report.
*/
public static Path getMavenUnitTestReportPath(String projectPath) {
Path path = Paths.get(projectPath, "target", "site", "surefire-report.html");
public static Path getMavenUnitTestReportPath(String projectPath, String projectName) {
Path path1 = Paths.get(projectPath, "target", "surefire-report.html");
Path path2 = Paths.get(projectPath, "target", "site", "surefire-report.html");

if (!path1.toFile().exists() && !path2.toFile().exists()) {
String msg = "No unit test results were found for project " + projectName + ". Select \""
+ DashboardView.APP_MENU_ACTION_RUN_TESTS + "\" before you select \""
+ DashboardView.APP_MENU_ACTION_VIEW_MVN_UT_REPORT + "\" on the menu.";
if (Trace.isEnabled()) {
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg + " No-op. Paths checked: " + path1 + ", " + path2);
}
ErrorHandler.processErrorMessage(NLS.bind(Messages.mvn_unit_test_report_none_found, new String[] { projectName,
DashboardView.APP_MENU_ACTION_RUN_TESTS, DashboardView.APP_MENU_ACTION_VIEW_MVN_UT_REPORT }), true);
return null;
}

return path;
return path1.toFile().exists() ? path1 : path2;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void testDashboardStartWithCustomConfigAction() {
deleteLibertyToolsRunConfigEntriesFromAppRunAs(MVN_APP_NAME);

// Delete the test report files before we start this test.
Path pathToITReport = Paths.get(projectPath.toString(), "target", "site", "failsafe-report.html");
Path pathToITReport = Paths.get(projectPath.toString(), "target", "failsafe-report.html");
boolean testReportDeleted = LibertyPluginTestUtils.deleteFile(pathToITReport.toFile());
Assertions.assertTrue(testReportDeleted, () -> "File: " + pathToITReport + " was not be deleted.");

Expand Down Expand Up @@ -508,7 +508,7 @@ public void testDashboardDebugWithCustomConfigAction() {
deleteLibertyToolsRunConfigEntriesFromAppRunAs(MVN_APP_NAME);

// Delete the test report files before we start this test.
Path pathToITReport = Paths.get(projectPath.toString(), "target", "site", "failsafe-report.html");
Path pathToITReport = Paths.get(projectPath.toString(), "target", "failsafe-report.html");
boolean testReportDeleted = LibertyPluginTestUtils.deleteFile(pathToITReport.toFile());
Assertions.assertTrue(testReportDeleted, () -> "File: " + pathToITReport + " was not be deleted.");

Expand Down Expand Up @@ -544,7 +544,7 @@ public void testDashboardDebugWithCustomConfigAction() {
public void testDashboardActions() {

// Delete the test report files before we start this test.
Path pathToITReport = Paths.get(projectPath.toString(), "target", "site", "failsafe-report.html");
Path pathToITReport = Paths.get(projectPath.toString(), "target", "failsafe-report.html");
boolean itReportDeleted = LibertyPluginTestUtils.deleteFile(pathToITReport.toFile());
Assertions.assertTrue(itReportDeleted, () -> "Test report file: " + pathToITReport + " was not be deleted.");

Expand Down Expand Up @@ -622,7 +622,7 @@ public void testStartWithCustomRunAsConfig() {
deleteLibertyToolsRunConfigEntriesFromAppRunAs(MVN_APP_NAME);

// Delete the test report files before we start this test.
Path pathToITReport = Paths.get(projectPath.toString(), "target", "site", "failsafe-report.html");
Path pathToITReport = Paths.get(projectPath.toString(), "target", "failsafe-report.html");
boolean testReportDeleted = LibertyPluginTestUtils.deleteFile(pathToITReport.toFile());
Assertions.assertTrue(testReportDeleted, () -> "File: " + pathToITReport + " was not be deleted.");

Expand Down Expand Up @@ -655,7 +655,7 @@ public void testRunAsShortcutActions() {
deleteLibertyToolsRunConfigEntriesFromAppRunAs(MVN_APP_NAME);

// Delete the test report files before we start this test.
Path pathToITReport = Paths.get(projectPath.toString(), "target", "site", "failsafe-report.html");
Path pathToITReport = Paths.get(projectPath.toString(), "target", "failsafe-report.html");
boolean itReportDeleted = LibertyPluginTestUtils.deleteFile(pathToITReport.toFile());
Assertions.assertTrue(itReportDeleted, () -> "Test report file: " + pathToITReport + " was not be deleted.");

Expand Down Expand Up @@ -706,7 +706,7 @@ public void testStartWithCustomDebugAsConfig() {
deleteLibertyToolsRunConfigEntriesFromAppRunAs(MVN_APP_NAME);

// Delete the test report files before we start this test.
Path pathToITReport = Paths.get(projectPath.toString(), "target", "site", "failsafe-report.html");
Path pathToITReport = Paths.get(projectPath.toString(), "target", "failsafe-report.html");
boolean testReportDeleted = LibertyPluginTestUtils.deleteFile(pathToITReport.toFile());
Assertions.assertTrue(testReportDeleted, () -> "File: " + pathToITReport + " was not be deleted.");

Expand Down

0 comments on commit c2800c9

Please sign in to comment.