64 lines
2.0 KiB
Java
64 lines
2.0 KiB
Java
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.Arrays;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Properties;
|
|
|
|
import org.apache.commons.text.StringSubstitutor;
|
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
|
import org.junit.Test;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@Slf4j
|
|
public class StringReplacerTest {
|
|
|
|
public static String NOTIFICATION_MESSAGE_FILE_PATH = String.format("%s%s", System.getProperty("user.dir"),
|
|
"/src/test/resources/Notifications_Messages.properties");
|
|
|
|
public static final List<String> PLACEHOLDERS = Arrays.asList("TITLE_REVIEW_REQUIRED", "MSG_REVIEW_REQUIRED",
|
|
"TITLE_ITEM_REJECTED", "MSG_ITEM_REJECTED", "TITLE_ITEM_REJECTED_REVIEW_REQUIRED",
|
|
"MSG_ITEM_REJECTED_REVIEW_REQUIRED", "MSG_ITEM_PUBLISHED");
|
|
|
|
public static String USERNAME = "francesco.mangiacrapa";
|
|
public static String PROJECT_NAME = "\"My Great Project\"";
|
|
public static String GIS_LINK = "https://my_gis_link";
|
|
|
|
@Test
|
|
public void checkReplace() {
|
|
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
|
|
if (GCubeTest.isTestInfrastructureEnabled()) {
|
|
|
|
Map<String, String> 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 (InputStream input = new FileInputStream(NOTIFICATION_MESSAGE_FILE_PATH)) {
|
|
Properties prop = new Properties();
|
|
// load a properties file
|
|
prop.load(input);
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|