From 16a86fb769e04ac95930ae8749457ec0520b8d11 Mon Sep 17 00:00:00 2001 From: Mohanachandran S Date: Wed, 25 Sep 2024 17:04:10 +0530 Subject: [PATCH] MOSIP-36012 - Reports will be stored in mount path if push reports to s3 is No Signed-off-by: Mohanachandran S --- .../mosip/testrig/apirig/report/EmailableReport.java | 12 ++++++++++++ .../io/mosip/testrig/apirig/utils/ConfigManager.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java index 4ae90c3a07..83dc85b310 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java @@ -8,6 +8,9 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.text.NumberFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -55,6 +58,7 @@ public class EmailableReport implements IReporter { private final StringBuilder buffer = new StringBuilder(); private String fileName = "emailable-report.html"; + private String mountPathForReport = ConfigManager.getMountPathForReport(); private static final String JVM_ARG = GlobalConstants.EMAILABLEREPORT2NAME; @@ -152,6 +156,14 @@ public void generateReport(List xmlSuites, List suites, String } else { LOG.info("Failed while pushing file to S3"); } + } else { + try { + Path mountFilePath = Path.of(mountPathForReport, newString); + Files.copy(newReportFile.toPath(), mountFilePath, StandardCopyOption.REPLACE_EXISTING); + LOG.info("Successfully copied report file to mount path: " + mountFilePath.toString()); + } catch (Exception e) { + LOG.error("Error occurred while copying file to mount path: " + e.getLocalizedMessage()); + } } } else { LOG.error("Renamed report file doesn't exist"); diff --git a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/ConfigManager.java b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/ConfigManager.java index b12b363c4a..3aeca841ff 100644 --- a/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/ConfigManager.java +++ b/apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/ConfigManager.java @@ -125,6 +125,7 @@ public class ConfigManager { private static String AUTHCERTS_PATH = "authCertsPath"; private static String MOUNT_PATH_FOR_SCENARIO = "mountPathForScenario"; private static String MOCK_NOTIFICATION_CHANNEL = "mockNotificationChannel"; + private static String MOUNT_PATH_FOR_REPORT = "mountPathForReport"; private static String SERVER_ERRORS_TO_MONITOR = "serverErrorsToMonitor"; @@ -251,6 +252,7 @@ public class ConfigManager { private static String serverErrorsToMonitor; private static String mountPath; + private static String mountPathForReport; private static String authCertsPath; private static String mockNotificationChannel; private static String mountPathForScenario; @@ -366,6 +368,12 @@ public static void init() { mountPath = System.getenv(MOUNT_PATH) == null ? propsKernel.getProperty(MOUNT_PATH) : System.getenv(MOUNT_PATH); propsKernel.setProperty(MOUNT_PATH, mountPath); + + mountPathForReport = System.getenv(MOUNT_PATH_FOR_REPORT) == null + ? propsKernel.getProperty(MOUNT_PATH_FOR_REPORT) + : System.getenv(MOUNT_PATH_FOR_REPORT); + propsKernel.setProperty(MOUNT_PATH_FOR_REPORT, mountPathForReport); + mockNotificationChannel = System.getenv(MOCK_NOTIFICATION_CHANNEL) == null ? propsKernel.getProperty(MOCK_NOTIFICATION_CHANNEL) @@ -640,6 +648,10 @@ public static String getmountPath() { return mountPath; } + public static String getMountPathForReport() { + return mountPathForReport; + } + public static String getmountPathForScenario() { return mountPathForScenario; }