From 122fd7c8821de082c4bd591f6ed141068bbbfe05 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 21 Mar 2024 15:54:09 +0100 Subject: [PATCH] string replace test --- .../src/test/java/StringReplacerTest.java | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/notifications-plugins/src/test/java/StringReplacerTest.java b/notifications-plugins/src/test/java/StringReplacerTest.java index 1fe9401..377d7d1 100644 --- a/notifications-plugins/src/test/java/StringReplacerTest.java +++ b/notifications-plugins/src/test/java/StringReplacerTest.java @@ -1,6 +1,9 @@ +import java.io.BufferedInputStream; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -8,6 +11,7 @@ import java.util.Map; import java.util.Properties; import org.apache.commons.text.StringSubstitutor; +import org.gcube.application.cms.notifications.substitutor.SubstitutorMessagesMap; import org.gcube.application.geoportal.common.utils.tests.GCubeTest; import org.junit.Test; @@ -24,39 +28,41 @@ public class StringReplacerTest { "MSG_ITEM_REJECTED_REVIEW_REQUIRED", "MSG_ITEM_PUBLISHED"); public static String USERNAME = "francesco.mangiacrapa"; + public static String PROJECT_ID = "12345"; public static String PROJECT_NAME = "\"My Great Project\""; public static String GIS_LINK = "https://my_gis_link"; + public static String FILE_URL = "https://code-repo.d4science.org/gCubeSystem/gcube-cms-suite/raw/branch/event_manager/D4S_UCDs/DEV/devVRE/notifications/Notifications_Messages.properties"; + @Test public void checkReplace() { org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled()); - if (GCubeTest.isTestInfrastructureEnabled()) { + Map valuesMap = new HashMap<>(); + valuesMap.put(SubstitutorMessagesMap.USER, USERNAME); + valuesMap.put(SubstitutorMessagesMap.PROJECT_NAME, PROJECT_NAME); + valuesMap.put(SubstitutorMessagesMap.GIS_LINK, GIS_LINK); + valuesMap.put(SubstitutorMessagesMap.PROJECT_ID, PROJECT_ID); + // Build StringSubstitutor + StringSubstitutor sub = new StringSubstitutor(valuesMap); - Map valuesMap = new HashMap<>(); - valuesMap.put("user", USERNAME); - valuesMap.put("project_name", PROJECT_NAME); - valuesMap.put("gis_link", GIS_LINK); - // Build StringSubstitutor - StringSubstitutor sub = new StringSubstitutor(valuesMap); + try (BufferedInputStream in = new BufferedInputStream(new URL(FILE_URL).openStream())) { - try (InputStream input = new FileInputStream(NOTIFICATION_MESSAGE_FILE_PATH)) { - Properties prop = new Properties(); - // load a properties file - prop.load(input); + Properties prop = new Properties(); + // load a properties file + prop.load(in); - for (String placeholder : PLACEHOLDERS) { - log.info("placeholder: {}", placeholder); - String templateString = prop.getProperty(placeholder); - log.info("templateString: {}", templateString); - // Replace - String resolvedString = sub.replace(templateString); - log.info("resolvedString: {}", resolvedString); - } - - } catch (IOException ex) { - ex.printStackTrace(); + for (String placeholder : PLACEHOLDERS) { + log.info("placeholder: {}", placeholder); + String templateString = prop.getProperty(placeholder); + log.info("templateString: {}", templateString); + // Replace + String resolvedString = sub.replace(templateString); + log.info("resolvedString: {}", resolvedString); } + + } catch (IOException e) { + e.printStackTrace(); } }